Hello,
I'm sorry to make some issue for question :(
I created new Controllers "TeamsController" and i write new methods (register, edit/update and delete).
The visitors is able to register, edit/update and delete their team.
My problem is:
I create my method with help of ThreadsController (module forum) but when i upload file for the team my file is not save :sob:
TeamsController.php
/**
* Get form register a team
*/
public function getRegister()
{
$gamecat = Game::lists('title', 'id')->all();
return $this->pageView('teams::user_register_team', compact('model', 'modelClass', 'gamecat'));
}
/**
* Post form register a team
*/
public function postRegister()
{
$team = new Team(Input::all());
$team->slug = str_slug(Input::get('title'), '-');
$team->gamecat_id = Input::get('gamecat_id');
$team->teamcat_id = 3;
$team->password = $this->generateRandomPassword(8);
$team->published = 1;
$team->creator_id = user()->id;
$team->updater_id = null;
if (! $team->isValid()) {
return Redirect::to('teams/register')
->withInput()->withErrors($team->getErrors());
}
$team->forceSave();
$this->alertFlash(trans('app.created', ['Team']));
return Redirect::to('teams');
}
/**
* Generate random password during post to register team
*/
private function generateRandomPassword($length) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$generateRandomPassword = '';
for ($i = 0; $i < $length; $i++) {
$generateRandomPassword .= $characters[rand(0, $charactersLength - 1)];
}
return $generateRandomPassword;
}
user_register_team.blade.php
{!! Form::errors($errors) !!}
{!! Form::open(['url' => 'teams/register', 'files' => true]) !!}
{!! Form::label('title', 'Title:') !!}
{!! Form::text('title', null) !!}
{!! Form::label('text', 'Description:') !!}
{!! Form::textarea('text', null) !!}
{!! Form::select('gamecat_id', $gamecat) !!}
{!! Form::smartImageFile('image', trans('app.image')) !!}
{!! Form::actions(['submit'], false) !!}
{!! Form::close() !!}
I try with this (and is it ok but i prefer to use your same function like user image/avatar or team with admin backend):
if(Input::hasFile('image')) {
$image = Input::file('image');
$imageExtension = Input::file('image')->getClientOriginalExtension();
$imageName = $id.'_image.'.$imageExtension;
$image->move('uploads/teams', $imageName);
$team->image = $imageName
}
Thank you,
Alexis
and is it ok but i prefer to use your same function like user image/avatar or team with admin backend
The function of the admin backend does not work in the frontend.
The code for the user picture / avatar upload is in this file: contentify/Models/User.php (method uploadImage() line 296)
It's very similar to what you do. Except it uses getimagesize()to check if the file really is an image and it also creates thumbnails.
Your code for the image upload looks good. I assume $id is the team ID, right? And you assign the team ID to it prior in the code?
$team->image = $imageName
Missing semicolon. :wink:
And you do something like $team->save(); right?
Hey :)
It's right, i found the method line 369 for me ^^ but no problem i understand, so i copied it to model Team.php with modifications and i add some code in my TeamsController.php and it's OK :+1: :+1:
/**
* Tries to upload an image
*
* @param string $fieldName Name of the form field
* @return Redirect|null
*/
public function uploadImage($fieldName)
{
$file = Input::file($fieldName);
$extension = $file->getClientOriginalExtension();
try {
$imgData = getimagesize($file->getRealPath()); // Try to gather infos about the image
} catch (Exception $e) {
}
if (! isset($imgData[2]) or ! $imgData[2]) {
return Redirect::back()->withInput()->withErrors([trans('app.invalid_image')]);
}
$filePath = public_path().'/uploads/teams/';
if (File::exists($filePath.$this->getOriginal($fieldName))) {
File::delete($filePath.$this->getOriginal($fieldName));
}
$fileName = $this->id.'_'.$fieldName.'.'.$extension;
$uploadedFile = $file->move($filePath, $fileName);
$this->$fieldName = $fileName;
$this->save();
if ($fieldName == 'image') {
InterImage::make($filePath.'/'.$fileName)->resize(80, 80, function ($constraint) {
$constraint->aspectRatio();
})->save($filePath.$fileName);
}
}
/**
* Deletes a user image.
*
* @param string $fieldName Name of the form field
* @return void
*/
public function deleteImage($fieldName)
{
$filePath = public_path().'/uploads/teams/';
if (File::exists($filePath.$this->getOriginal($fieldName))) {
File::delete($filePath.$this->getOriginal($fieldName));
}
$this->$fieldName = '';
$this->save();
}
TeamsController.php
$team->fill(Input::all());
if (Input::hasFile('image')) {
$result = $team->uploadImage('image');
if ($result) return $result;
} elseif (Input::get('image') == '.') {
$team->deleteImage('image');
}
Yes sure ;)
Thank you for your help, i have other questions but i think you will be bored if i open more issues ^^
I would make some modification because i would organize some tournaments.
So now my visitors is able to make teams, next step i will make module for create tournaments (backend), next step make brackets (backend and view on frontend), next step able admin to add some user as arbiter on tournaments, next step visitors able to register his team in tournament and next step i will see it later ^^
If i finish my project i think i will send you the code, because i would help you on your cms, i think it's very good CMS. Before your cms i use Webspell but it's not on Laravel or Symfony2 and it's very difficult to edit ...
Thanks again for your help, have nice day.
Thank you for your help, i have other questions but i think you will be bored if i open more issues
No, it's fine. :+1: You can ask me for help i you have more troubles. Sharing your module in return seems to be fair enough.
If i finish my project i think i will send you the code
That would be great. I know a lot of people would love to get a tournament module!
because i would help you on your cms
Thanks!
Before your cms i use Webspell but it's not on Laravel or Symfony2
Yeah and it never will be. I know they try to improve it but their focus is not on the core. They add bootstrap and other stuff which is fine, but they do not seem to have enough manpower to touch the core of the CMS. And the core is old - very old, like 10 years or even older. Contentify is written in modern PHP with a modern framework and so on. It's not 100% state of the art, especially the frontend is not. No bower, for example.
No, it's fine. :+1: You can ask me for help i you have more troubles. Sharing your module in return seems to be fair enough.
Ok thank you very much, i will ask you for other problem, when i finish my module i will push to your repo, no problem for this ;)
Yeah and it never will be. I know they try to improve it but their focus is not on the core. They add bootstrap and other stuff which is fine, but they do not seem to have enough manpower to touch the core of the CMS. And the core is old - very old, like 10 years or even older. Contentify is written in modern PHP with a modern framework and so on. It's not 100% state of the art, especially the frontend is not. No bower, for example.
Yeah sure ! and cms for esport is not easy to find ..., but your cms i found it there are 2/3 weeks and i am very happy because i can modify it with more facility ;)
@About bundle Tournaments at now i make this:
Visitors can create teams (with password), edit team, delete team.
Admin can create tournament, edit tournament, add arbiters on tournament,
Creator of teams can join tournament, validate presence and leave tournament.
Soon:
Visitors can join team with password.
Admin start tournament for create brackets.
Admin can remove or check teams in backend.
And more ..
Sounds good, so far. Have you ever done something similar before?
Maybe I can help you with some of the more difficult parts (if you want help). I've created a small tournament module for the predecessor of Contentify (Callista CMS). Plus I work for MATCHARENA.eu which is a tournament platform. So yeah I have some experience.
Sounds good, so far. Have you ever done something similar before?
No i haven't done something like tournaments, but i like learn so it's good project ^^
I'm self-taught and it hasn't been simple because i think my code isn't 'clean' i think..
But i would learn for work in this domain.
If your are ok, i accept your help with pleasure ;)
I dont know how to github works, because i use private repository with bitbucket, so how do you want to proceed?
Thank you again.
@New function now finish:
Visitors can join team with password and leave team
Check if team have enough members for signup in tournaments
Tournaments with counter strike games have rules (5 players and valid steam id)
I dont know how to github works, because i use private repository with bitbucket, so how do you want to proceed?
Do you want to invite me to your BitBucket repository? I think in BitBucket you can send an invitation directly to my username siconize.
Yeah, it's done ;)
Ok cool, got it!