diff --git a/app/Http/Controllers/Admin/RoomController.php b/app/Http/Controllers/Admin/RoomController.php index 6bc804a..81e432b 100644 --- a/app/Http/Controllers/Admin/RoomController.php +++ b/app/Http/Controllers/Admin/RoomController.php @@ -2,7 +2,6 @@ namespace App\Http\Controllers\Admin; -use App\Events\AuditionChange; use App\Events\RoomJudgeChange; use App\Http\Controllers\Controller; use App\Models\Audition; @@ -10,49 +9,101 @@ use App\Models\Room; use App\Models\User; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; + use function redirect; class RoomController extends Controller { public function index() { - if(! Auth::user()->is_admin) abort(403); - #$unassignedAuditions = Audition::with('entries')->where('room_id','=','0')->orderBy('score_order')->get(); + if (! Auth::user()->is_admin) { + abort(403); + } + //$unassignedAuditions = Audition::with('entries')->where('room_id','=','0')->orderBy('score_order')->get(); $rooms = Room::with('auditions.entries')->orderBy('name')->get(); + return view('admin.rooms.index', ['rooms' => $rooms]); } public function judgingAssignment() // Show form for assigning judges { + if (! Auth::user()->is_admin) { + abort(403); + } $usersWithoutRooms = User::doesntHave('rooms')->orderBy('last_name')->orderBy('first_name')->get(); $usersWithRooms = User::has('rooms')->orderBy('last_name')->orderBy('first_name')->get(); - $rooms = Room::with(['judges.school','auditions'])->get(); + $rooms = Room::with(['judges.school', 'auditions'])->get(); - return view('admin.rooms.judge_assignments', compact('usersWithoutRooms','usersWithRooms','rooms')); + return view('admin.rooms.judge_assignments', compact('usersWithoutRooms', 'usersWithRooms', 'rooms')); } public function updateJudgeAssignment(Request $request, Room $room) { + if (! Auth::user()->is_admin) { + abort(403); + } $validData = $request->validate([ - 'judge' => 'exists:users,id' + 'judge' => 'exists:users,id', ]); $judge = User::find($validData['judge']); - if($request->isMethod('post')) { + if ($request->isMethod('post')) { // attach judge on post $room->addJudge($judge->id); - $message = "Assigned " . $judge->full_name() . " to " . $room->name; + $message = 'Assigned '.$judge->full_name().' to '.$room->name; } elseif ($request->isMethod('delete')) { // detach judge on delete $room->removeJudge($judge->id); - $message = "Removed " . $judge->full_name() . " from " . $room->name; + $message = 'Removed '.$judge->full_name().' from '.$room->name; } else { return redirect('/admin/rooms/judging_assignments')->with('error', 'Invalid request method.'); } - return redirect('/admin/rooms/judging_assignments')->with('success',$message); + + return redirect('/admin/rooms/judging_assignments')->with('success', $message); } + public function create() + { + if (! Auth::user()->is_admin) { + abort(403); + } -// TODO need to be able to add new rooms. Dispatch RoomJudgeChange when we do. + return view('admin.rooms.create'); + } + + public function store(Request $request) + { + if (! Auth::user()->is_admin) { + abort(403); + } + $validData = $request->validate([ + 'name' => 'required', + 'description' => 'nullable', + ]); + + $room = new Room(); + $room->name = $validData['name']; + $room->description = $validData['description']; + $room->save(); + + return redirect()->route('admin.rooms.index')->with('success', 'Room created.'); + } + + public function destroy(Request $request, Room $room) + { + if (! Auth::user()->is_admin) { + abort(403); + } + + if ($room->auditions()->count() > 0) { + return redirect()->route('admin.rooms.index')->with('error', 'Cannot delete room with auditions. First move the auditions to unassigned or another room'); + } + + $room->delete(); + + return redirect()->route('admin.rooms.index')->with('success', 'Room deleted.'); + } + + // TODO need to be able to add new rooms. Dispatch RoomJudgeChange when we do. } diff --git a/resources/views/admin/rooms/create.blade.php b/resources/views/admin/rooms/create.blade.php new file mode 100644 index 0000000..1906ff3 --- /dev/null +++ b/resources/views/admin/rooms/create.blade.php @@ -0,0 +1,13 @@ + + Create Room + + Create Room + + + + + Save Room + + + + diff --git a/resources/views/admin/rooms/index.blade.php b/resources/views/admin/rooms/index.blade.php index 9da605e..ada35cb 100644 --- a/resources/views/admin/rooms/index.blade.php +++ b/resources/views/admin/rooms/index.blade.php @@ -7,8 +7,8 @@
@foreach($rooms as $room) + {{-- Room 0 should be at the end for unassigned auditions--}} @if($room->id == '0') - @push('noRoom') @endif @@ -16,7 +16,18 @@ {{ $room->name }} {{ $room->description }} - {{ $room->entries->count() }} + @if($room->entries->count() === 0 and $room->id != '0') +
+ + + +
+ @else + {{ $room->entries->count() }} + @endif
@@ -28,7 +39,6 @@ @endforeach -