diff --git a/app/Http/Controllers/Admin/PrintCards.php b/app/Http/Controllers/Admin/PrintCards.php index a50eb3f..428c3fc 100644 --- a/app/Http/Controllers/Admin/PrintCards.php +++ b/app/Http/Controllers/Admin/PrintCards.php @@ -3,11 +3,49 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; +use App\Models\Entry; +use App\Models\Event; class PrintCards extends Controller { public function index() // Display a form to select which cards to print { - return view('admin.printcards.index'); + $events = Event::with('auditions.flags')->get(); + $sortOptions = [ + 'name' => 'Student Name', + 'school' => 'School Name', + 'audition' => 'Audition', + 'room' => 'Room', + 'drawNumber' => 'Draw Number', + ]; + + return view('admin.print_cards.index', compact('events', 'sortOptions')); + } + + public function print() + { + //dump(request()->all()); + + $selectedAuditionIds = array_keys(request()->audition); + $cards = Entry::whereIn('audition_id', $selectedAuditionIds)->get(); + $sorts = []; + // Process submitted sort criteria + foreach (request()->sort as $sortField) { + // continue if nothing to sort by + if ($sortField === null) { + continue; + } + // set appropriate sort parameters for later processing + $sorts[] = match ($sortField) { + 'name' => fn (Entry $a, Entry $b) => $a->student->full_name(true) <=> $b->student->full_name(true), + 'school' => fn (Entry $a, Entry $b) => $a->student->school->name <=> $b->student->school->name, + 'audition' => fn (Entry $a, Entry $b) => $a->audition->score_order <=> $b->audition->score_order, + 'room' => fn (Entry $a, Entry $b) => $a->audition->room->name <=> $b->audition->room->name, + 'drawNumber' => fn (Entry $a, Entry $b) => $a->draw_number <=> $b->draw_number, + }; + } + $cards = $cards->sortBy($sorts); + + return view('admin.print_cards.print', compact('cards')); } } diff --git a/resources/views/admin/print_cards/index.blade.php b/resources/views/admin/print_cards/index.blade.php new file mode 100644 index 0000000..7be40bd --- /dev/null +++ b/resources/views/admin/print_cards/index.blade.php @@ -0,0 +1,58 @@ + + Select Cards to Print + + {{--Audition Select--}} + @foreach($events as $event) + @continue($event->auditions->isEmpty()) + + + {{ $event->name }} + + + + + +
+ @foreach($event->auditions as $audition) +
+ + {{$audition->name}} {{ $audition->hasFlag('drawn') ? '':'(*)' }} +
+ @endforeach +
+
+ (*): Draw has not been run for this audition +
+
+ + {{--Sort Options--}} + + Card Sorting +
+ + Primary Sort: + + @foreach($sortOptions as $value => $label) + + @endforeach + + + Secondary Slot: + + @foreach($sortOptions as $value => $label) + + @endforeach + + + Tertiary Slot: + + @foreach($sortOptions as $value => $label) + + @endforeach + +
+
+ Print Cards + @endforeach +
+
diff --git a/resources/views/admin/print_cards/print.blade.php b/resources/views/admin/print_cards/print.blade.php new file mode 100644 index 0000000..1a88522 --- /dev/null +++ b/resources/views/admin/print_cards/print.blade.php @@ -0,0 +1,28 @@ +@php + dump($cards); +@endphp + + + + + + Room + Audition + Draw Number + Student + School + + + + @foreach($cards as $card) + + {{$card->audition->room->name}} + {{ $card->audition->name }} + {{ $card->draw_number }} + {{ $card->student->full_name(true) }} + {{ $card->student->school->name }} + + @endforeach + + + diff --git a/resources/views/admin/printcards/index.blade.php b/resources/views/admin/printcards/index.blade.php deleted file mode 100644 index 7e414a4..0000000 --- a/resources/views/admin/printcards/index.blade.php +++ /dev/null @@ -1,3 +0,0 @@ - - Select Cards to Print - diff --git a/routes/admin.php b/routes/admin.php index 13bc4c3..53de58b 100644 --- a/routes/admin.php +++ b/routes/admin.php @@ -168,5 +168,6 @@ Route::middleware(['auth', 'verified', CheckIfAdmin::class])->prefix('admin/')-> // Admin Card Routes Route::prefix('cards')->controller(PrintCards::class)->group(function () { Route::get('/', 'index')->name('admin.cards.index'); + Route::post('/print', 'print')->name('admin.cards.print'); }); });