xoco70 /
kendozone
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace App\Http\Controllers; |
||||
| 4 | |||||
| 5 | use App\Category; |
||||
| 6 | use App\Country; |
||||
| 7 | use App\Exceptions\InvitationNeededException; |
||||
| 8 | use App\FightersGroup; |
||||
| 9 | use App\Grade; |
||||
| 10 | use App\Http\Requests\TournamentRequest; |
||||
| 11 | use App\Http\Requests\VenueRequest; |
||||
| 12 | use App\Tournament; |
||||
| 13 | use App\TournamentLevel; |
||||
| 14 | use App\Venue; |
||||
| 15 | use Illuminate\Http\Request; |
||||
| 16 | use Illuminate\Support\Facades\App; |
||||
| 17 | use Illuminate\Support\Facades\Auth; |
||||
| 18 | use Illuminate\Support\Facades\Lang; |
||||
| 19 | use Illuminate\Support\Facades\Response; |
||||
| 20 | use Illuminate\Support\Facades\Session; |
||||
| 21 | use Illuminate\Support\Facades\URL; |
||||
| 22 | |||||
| 23 | |||||
| 24 | class TournamentController extends Controller |
||||
| 25 | { |
||||
| 26 | 13 | public function __construct() |
|||
| 27 | { |
||||
| 28 | 13 | $this->middleware('ownTournament')->except('index', 'show', 'register'); |
|||
| 29 | 13 | $this->middleware('auth')->except('show', 'register'); |
|||
| 30 | 13 | } |
|||
| 31 | |||||
| 32 | /** |
||||
| 33 | * Display a listing of the resource. |
||||
| 34 | * |
||||
| 35 | * @return \Illuminate\Http\Response |
||||
| 36 | */ |
||||
| 37 | 2 | public function index() |
|||
| 38 | { |
||||
| 39 | |||||
| 40 | 2 | if (Auth::user()->isSuperAdmin()) { |
|||
| 41 | 2 | $tournaments = Tournament::with('owner') |
|||
| 42 | 2 | ->withCount('competitors') |
|||
| 43 | 2 | ->orderBy('updated_at', 'desc') |
|||
| 44 | 2 | ->paginate(config('constants.PAGINATION')); // ,'uniqueTrees' |
|||
| 45 | } else { |
||||
| 46 | $tournaments = Auth::user()->tournaments() |
||||
| 47 | ->with('owner')->orderBy('updated_at', 'desc') |
||||
| 48 | ->paginate(config('constants.PAGINATION')); |
||||
| 49 | } |
||||
| 50 | 2 | $title = trans('core.tournaments_created'); |
|||
| 51 | 2 | return view('tournaments.index', compact('tournaments', 'title')); |
|||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||||
| 52 | } |
||||
| 53 | |||||
| 54 | /** |
||||
| 55 | * Show the form for creating a new resource. |
||||
| 56 | * |
||||
| 57 | * @return \Illuminate\Http\Response |
||||
| 58 | */ |
||||
| 59 | 3 | public function create() |
|||
| 60 | { |
||||
| 61 | 3 | $levels = TournamentLevel::getAllPlucked(); |
|||
| 62 | 3 | $categories = Category::take(10)->orderBy('id', 'asc')->pluck('name', 'id'); |
|||
| 63 | 3 | $tournament = new Tournament(); |
|||
| 64 | 3 | $rules = config('options.rules'); |
|||
| 65 | 3 | $rulesCategories = (new Category)->getCategorieslabelByRule(); |
|||
| 66 | 3 | return view('tournaments.create', compact('levels', 'categories', 'tournament', 'rules', 'rulesCategories')); |
|||
|
0 ignored issues
–
show
|
|||||
| 67 | } |
||||
| 68 | |||||
| 69 | /** |
||||
| 70 | * Store a new Tournament |
||||
| 71 | * |
||||
| 72 | * @param TournamentRequest $form |
||||
| 73 | * @return \Illuminate\Http\Response |
||||
| 74 | */ |
||||
| 75 | 2 | public function store(TournamentRequest $form) |
|||
| 76 | { |
||||
| 77 | 2 | $tournament = $form->persist(); |
|||
| 78 | 2 | $msg = trans('msg.tournament_create_successful', ['name' => $tournament->name]); |
|||
| 79 | 2 | flash()->success($msg); |
|||
|
0 ignored issues
–
show
Are you sure the usage of
flash() is correct as it seems to always return null.
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. Loading history...
|
|||||
| 80 | 2 | return redirect(URL::action('TournamentController@edit', $tournament->slug)); |
|||
|
0 ignored issues
–
show
|
|||||
| 81 | } |
||||
| 82 | |||||
| 83 | /** |
||||
| 84 | * Display the Tournament. |
||||
| 85 | * |
||||
| 86 | * @param Request $request |
||||
| 87 | * @param $tournamentSlug |
||||
| 88 | * @return \Illuminate\Http\Response |
||||
| 89 | */ |
||||
| 90 | 1 | public function show(Request $request, $tournamentSlug) |
|||
|
0 ignored issues
–
show
The parameter
$tournamentSlug is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
|
|||||
| 91 | { |
||||
| 92 | 1 | $teams = ""; |
|||
| 93 | 1 | $grades = Grade::getAllPlucked(); |
|||
| 94 | 1 | $tournament = FightersGroup::getTournament($request); |
|||
| 95 | 1 | $venue = $tournament->venue ?? new Venue; |
|||
|
0 ignored issues
–
show
|
|||||
| 96 | 1 | $countries = Country::getAll(); |
|||
| 97 | |||||
| 98 | 1 | return view('tournaments.show', compact('tournament', 'tournamentWithTrees', 'grades', 'teams', 'venue', 'countries')); |
|||
|
0 ignored issues
–
show
|
|||||
| 99 | } |
||||
| 100 | |||||
| 101 | /** |
||||
| 102 | * Show the form for editing the Tournament. |
||||
| 103 | * |
||||
| 104 | * @param Tournament $tournament |
||||
| 105 | * @return \Illuminate\Http\Response |
||||
| 106 | */ |
||||
| 107 | 5 | public function edit(Tournament $tournament) |
|||
| 108 | { |
||||
| 109 | |||||
| 110 | 5 | $tournament = Tournament::with('competitors', 'championshipSettings', 'championships.settings', 'championships.category') |
|||
| 111 | 5 | ->withCount('competitors', 'teams') |
|||
| 112 | 5 | ->find($tournament->id); |
|||
| 113 | 5 | $selectedCategories = $tournament->categories->pluck('name','id'); // 3,4 ,240 |
|||
| 114 | 5 | $defaultCategories = Category::take(7)->get()->sortBy('id')->pluck('name','id'); // 1 2 3 4 5 6 7 |
|||
| 115 | |||||
| 116 | 5 | $categories = $selectedCategories->union($defaultCategories)->toArray(); |
|||
| 117 | |||||
| 118 | |||||
| 119 | |||||
| 120 | // Statistics for Right Panel |
||||
| 121 | 5 | $countries = Country::getAllPlucked(); |
|||
| 122 | 5 | $settingSize = $tournament->championshipSettings->count(); |
|||
| 123 | 5 | $categorySize = $tournament->championships->count(); |
|||
| 124 | 5 | $hanteiLimit = config('options.hanteiLimit'); |
|||
| 125 | |||||
| 126 | 5 | $grades = Grade::getAllPlucked(); |
|||
| 127 | 5 | $venue = $tournament->venue ?? new Venue; |
|||
| 128 | 5 | $levels = TournamentLevel::getAllPlucked(); |
|||
| 129 | |||||
| 130 | 5 | return view('tournaments.edit', compact('tournament', 'levels', 'categories', 'settingSize', 'categorySize', 'grades', 'numCompetitors', 'rules', 'hanteiLimit', 'numTeams', 'countries', 'venue')); |
|||
|
0 ignored issues
–
show
|
|||||
| 131 | } |
||||
| 132 | |||||
| 133 | /** |
||||
| 134 | * Update the Tournament in storage. |
||||
| 135 | * |
||||
| 136 | * @param TournamentRequest $request |
||||
| 137 | * @param VenueRequest $venueRequest |
||||
| 138 | * @param Tournament $tournament |
||||
| 139 | * @return \Illuminate\Http\JsonResponse |
||||
| 140 | */ |
||||
| 141 | 4 | public function update(TournamentRequest $request, VenueRequest $venueRequest, Tournament $tournament) |
|||
| 142 | { |
||||
| 143 | //TODO Shouldn't I have a Policy??? |
||||
| 144 | 4 | $venue = $tournament->venue; |
|||
| 145 | 4 | if ($venue == null) |
|||
| 146 | 4 | $venue = new Venue; |
|||
| 147 | |||||
| 148 | 4 | if ($venueRequest->has('venue_name')) { |
|||
| 149 | 1 | $venue->fill($venueRequest->all()); |
|||
| 150 | 1 | $venue->save(); |
|||
| 151 | } else { |
||||
| 152 | 3 | $venue = new Venue(); |
|||
| 153 | } |
||||
| 154 | 4 | $res = $request->update($tournament, $venue); |
|||
| 155 | |||||
| 156 | 4 | if ($request->ajax()) { |
|||
| 157 | $res == 0 |
||||
|
0 ignored issues
–
show
|
|||||
| 158 | ? $result = Response::json(['msg' => trans('msg.tournament_update_error', ['name' => $tournament->name]), 'status' => 'error']) |
||||
| 159 | : $result = Response::json(['msg' => trans('msg.tournament_update_successful', ['name' => $tournament->name]), 'status' => 'success']); |
||||
| 160 | return $result; |
||||
| 161 | } else { |
||||
| 162 | 4 | $res == 0 |
|||
|
0 ignored issues
–
show
|
|||||
| 163 | ? flash()->success(trans('msg.tournament_update_error', ['name' => $tournament->name])) |
||||
| 164 | 4 | : flash()->success(trans('msg.tournament_update_successful', ['name' => $tournament->name])); |
|||
|
0 ignored issues
–
show
Are you sure the usage of
flash() is correct as it seems to always return null.
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. Loading history...
|
|||||
| 165 | 4 | return redirect(URL::action('TournamentController@edit', $tournament->slug))->with('activeTab', $request->activeTab); |
|||
|
0 ignored issues
–
show
|
|||||
| 166 | } |
||||
| 167 | } |
||||
| 168 | |||||
| 169 | /** |
||||
| 170 | * Remove the Tournament from storage. |
||||
| 171 | * |
||||
| 172 | * @param Tournament $tournament |
||||
| 173 | * @return \Illuminate\Http\JsonResponse |
||||
| 174 | * @throws \Exception |
||||
| 175 | */ |
||||
| 176 | 1 | public function destroy(Tournament $tournament) |
|||
| 177 | { |
||||
| 178 | 1 | if ($tournament->delete()) { |
|||
| 179 | 1 | return Response::json(['msg' => Lang::get('msg.tournament_delete_successful', ['name' => $tournament->name]), 'status' => 'success']); |
|||
| 180 | } |
||||
| 181 | return Response::json(['msg' => Lang::get('msg.tournament_delete_error', ['name' => $tournament->name]), 'status' => 'error']); |
||||
| 182 | } |
||||
| 183 | |||||
| 184 | /** |
||||
| 185 | * @param $tournamentSlug |
||||
| 186 | * @return \Illuminate\Http\JsonResponse |
||||
| 187 | */ |
||||
| 188 | 1 | public function restore($tournamentSlug) |
|||
| 189 | { |
||||
| 190 | 1 | $tournament = Tournament::withTrashed()->whereSlug($tournamentSlug)->first(); |
|||
| 191 | 1 | if ($tournament->restore()) { |
|||
| 192 | 1 | return Response::json(['msg' => Lang::get('msg.tournament_restored_successful', ['name' => $tournament->name]), 'status' => 'success']); |
|||
| 193 | } |
||||
| 194 | |||||
| 195 | return Response::json(['msg' => Lang::get('msg.tournament_restored_error', ['name' => $tournament->name]), 'status' => 'error']); |
||||
| 196 | |||||
| 197 | } |
||||
| 198 | |||||
| 199 | /** |
||||
| 200 | * Called when a user want to register an open tournament |
||||
| 201 | * @param Request $request |
||||
| 202 | * @param Tournament $tournament |
||||
| 203 | * @return mixed |
||||
| 204 | * @throws InvitationNeededException |
||||
| 205 | */ |
||||
| 206 | 1 | public function register(Request $request, Tournament $tournament) |
|||
|
0 ignored issues
–
show
The parameter
$request is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
|
|||||
| 207 | { |
||||
| 208 | |||||
| 209 | 1 | if (!Auth::check()) { |
|||
| 210 | 1 | Session::flash('message', trans('msg.please_create_account_before_playing', ['tournament' => $tournament->name])); |
|||
| 211 | 1 | return redirect(URL::action('Auth\LoginController@login')); |
|||
| 212 | } |
||||
| 213 | 1 | if ($tournament->isOpen() && Auth::check()) { |
|||
| 214 | 1 | App::setLocale(Auth::user()->locale); |
|||
| 215 | |||||
| 216 | 1 | $grades = Grade::getAllPlucked(); |
|||
| 217 | 1 | $tournament = Tournament::with('championships.category', 'championships.users')->find($tournament->id); |
|||
| 218 | 1 | return view("categories.register", compact('tournament', 'invite', 'currentModelName', 'grades')); |
|||
| 219 | } |
||||
| 220 | |||||
| 221 | throw new InvitationNeededException(); |
||||
| 222 | } |
||||
| 223 | |||||
| 224 | /** |
||||
| 225 | * Get Deleted Tournaments |
||||
| 226 | * |
||||
| 227 | * @return mixed |
||||
| 228 | */ |
||||
| 229 | public function getDeleted() |
||||
| 230 | { |
||||
| 231 | $tournaments = Auth::user()->tournaments()->with('owner') |
||||
| 232 | ->onlyTrashed() |
||||
| 233 | ->latest() |
||||
| 234 | ->paginate(config('constants.PAGINATION')); |
||||
| 235 | |||||
| 236 | if (Auth::user()->isSuperAdmin()) { |
||||
| 237 | $tournaments = Tournament::onlyTrashed()->with('owner') |
||||
| 238 | ->has('owner') |
||||
| 239 | ->latest() |
||||
| 240 | ->paginate(config('constants.PAGINATION')); |
||||
| 241 | } |
||||
| 242 | |||||
| 243 | $title = trans('core.tournaments_deleted'); |
||||
| 244 | return view('tournaments.deleted', compact('tournaments', 'title')); |
||||
| 245 | } |
||||
| 246 | |||||
| 247 | |||||
| 248 | } |
||||
| 249 |