72 lines
2.6 KiB
PHP
72 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Entry;
|
|
use App\Models\Event;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
// TODO: Printing testing
|
|
/** @codeCoverageIgnore */
|
|
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());
|
|
// if (request()->audition == null) {
|
|
// return redirect()->back()->with('error', 'You must specify at least one audition');
|
|
// }
|
|
if (request()->audition) {
|
|
$selectedAuditionIds = array_keys(request()->audition);
|
|
} else {
|
|
$selectedAuditionIds = [];
|
|
}
|
|
$cardQuery = Entry::whereIn('audition_id', $selectedAuditionIds);
|
|
|
|
// Process Filters
|
|
if (request()->filter == 'today') {
|
|
$now = Carbon::now('America/Chicago')->format('Y-m-d');
|
|
$cardQuery->where('created_at', '>=', $now);
|
|
}
|
|
if (request()->filter == 'idAfter') {
|
|
$firstId = request()->idAfter;
|
|
$cardQuery->where('id', '>=', $firstId);
|
|
}
|
|
$cards = $cardQuery->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'));
|
|
}
|
|
}
|