130 lines
4.1 KiB
PHP
130 lines
4.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Actions\Tabulation\CheckPrelimResult;
|
|
use App\Models\Entry;
|
|
use App\Models\PrelimDefinition;
|
|
|
|
use function compact;
|
|
|
|
class MonitorController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
if (! auth()->user()->hasFlag('monitor')) {
|
|
abort(403);
|
|
}
|
|
$method = 'POST';
|
|
$formRoute = 'monitor.enterFlag';
|
|
$title = 'Flag Entry';
|
|
|
|
//return view('tabulation.choose_entry', compact('method', 'formRoute', 'title'));
|
|
$prelims = PrelimDefinition::with('audition')->get();
|
|
$prelimDefinition = null;
|
|
|
|
return view('monitor.index', compact('prelims', 'prelimDefinition'));
|
|
}
|
|
|
|
public function prelimStatus(PrelimDefinition $prelimDefinition)
|
|
{
|
|
if (! auth()->user()->hasFlag('monitor')) {
|
|
abort(403);
|
|
}
|
|
$prelims = PrelimDefinition::with('audition')->get();
|
|
$entries = $prelimDefinition->audition->entries()->with('student.school')->with('PrelimScoreSheets')->get();
|
|
|
|
// foreach ($entries as $entry) {
|
|
// app(CheckPrelimResult::class)->__invoke($entry);
|
|
// }
|
|
return view('monitor.index', compact('prelims', 'prelimDefinition', 'entries'));
|
|
}
|
|
|
|
public function toggleNoShow(Entry $entry)
|
|
{
|
|
if ($entry->hasFlag('no_show')) {
|
|
$entry->removeFlag('no_show');
|
|
|
|
return;
|
|
}
|
|
$entry->addFlag('no_show');
|
|
|
|
return redirect()->back()->with('success', 'No Show Entered');
|
|
}
|
|
|
|
public function flagForm()
|
|
{
|
|
if (! auth()->user()->hasFlag('monitor')) {
|
|
abort(403);
|
|
}
|
|
|
|
$validData = request()->validate([
|
|
'entry_id' => ['required', 'integer', 'exists:entries,id'],
|
|
]);
|
|
|
|
$entry = Entry::find($validData['entry_id']);
|
|
|
|
// If the entries audition is published, bounce out
|
|
if ($entry->audition->hasFlag('seats_published') || $entry->audition->hasFlag('advancement_published')) {
|
|
return redirect()->route('monitor.index')->with('error', 'Cannot set flags while results are published');
|
|
}
|
|
|
|
// If entry has scores, bounce on out
|
|
if ($entry->scoreSheets()->count() > 0) {
|
|
return redirect()->route('monitor.index')->with('error', 'That entry has existing scores');
|
|
}
|
|
|
|
return view('monitor_entry_flag_form', compact('entry'));
|
|
}
|
|
|
|
public function storeFlag(Entry $entry)
|
|
{
|
|
if (! auth()->user()->hasFlag('monitor')) {
|
|
abort(403);
|
|
}
|
|
|
|
// If the entries audition is published, bounce out
|
|
if ($entry->audition->hasFlag('seats_published') || $entry->audition->hasFlag('advancement_published')) {
|
|
return redirect()->route('monitor.index')->with('error', 'Cannot set flags while results are published');
|
|
}
|
|
|
|
// If entry has scores, bounce on out
|
|
if ($entry->scoreSheets()->count() > 0) {
|
|
return redirect()->route('monitor.index')->with('error', 'That entry has existing scores');
|
|
}
|
|
|
|
$action = request()->input('action');
|
|
$result = match ($action) {
|
|
'failed-prelim' => $this->setFlag($entry, 'failed_prelim'),
|
|
'no-show' => $this->setFlag($entry, 'no_show'),
|
|
'clear' => $this->setFlag($entry, 'clear'),
|
|
default => redirect()->route('monitor.index')->with('error', 'Invalid action requested'),
|
|
};
|
|
|
|
return redirect()->route('monitor.index')->with('success', 'Flag set for entry #'.$entry->id);
|
|
}
|
|
|
|
private function setFlag(Entry $entry, string $flag)
|
|
{
|
|
if ($flag === 'no_show') {
|
|
$entry->removeFlag('failed_prelim');
|
|
$entry->addFlag('no_show');
|
|
|
|
return true;
|
|
}
|
|
if ($flag === 'failed_prelim') {
|
|
$entry->addFlag('failed_prelim');
|
|
$entry->addFlag('no_show');
|
|
|
|
return true;
|
|
}
|
|
if ($flag === 'clear') {
|
|
$entry->removeFlag('failed_prelim');
|
|
$entry->removeFlag('no_show');
|
|
|
|
return true;
|
|
}
|
|
|
|
}
|
|
}
|