52 lines
1.9 KiB
PHP
52 lines
1.9 KiB
PHP
<?php
|
|
|
|
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
|
|
{
|
|
$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(\App\Actions\Print\PrintCards $printer)
|
|
{
|
|
//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);
|
|
$printer->print($cards);
|
|
//return view('admin.print_cards.print', compact('cards'));
|
|
}
|
|
}
|