Create action for entering no_show and failed_prelim flags

This commit is contained in:
Matt Young 2025-06-25 15:25:10 -05:00
parent e1719c64fa
commit fba625c316
1 changed files with 55 additions and 0 deletions

View File

@ -0,0 +1,55 @@
<?php
namespace App\Actions\Tabulation;
use App\Exceptions\AuditionAdminException;
use App\Models\BonusScore;
use App\Models\Entry;
use App\Models\EntryTotalScore;
use App\Models\ScoreSheet;
class EnterNoShow
{
/**
* Handles the no-show or failed-prelim flagging for a given entry.
*
* This method ensures the specified flag type is valid and validates
* that the action can be performed based on the associated audition's state.
* Deletes related score records and applies the specified flag ('no_show'
* or 'failed_prelim') to the entry, returning a success message.
*
* @param Entry $entry The entry being flagged.
* @param string $flagType The type of flag to apply ('no-show' or 'failed-prelim').
* @return string A confirmation message about the flagging operation.
*
* @throws AuditionAdminException If an invalid flag type is provided,
* or the action violates business rules.
*/
public function __invoke(Entry $entry, string $flagType = 'no-show'): string
{
if ($flagType !== 'no-show' && $flagType !== 'failed-prelim') {
throw new AuditionAdminException('Invalid flag type');
}
if ($entry->audition->hasFlag('seats_published')) {
throw new AuditionAdminException('Cannot enter a no-show for an entry in an audition where seats are published');
}
if ($entry->audition->hasFlag('advancement_published')) {
throw new AuditionAdminException('Cannot enter a no-show for an entry in an audition where advancement is published');
}
DB::table('score_sheets')->where('entry_id', $entry->id)->delete();
ScoreSheet::where('entry_id', $entry->id)->delete();
BonusScore::where('entry_id', $entry->id)->delete();
EntryTotalScore::where('entry_id', $entry->id)->delete();
if ($flagType == 'failed-prelim') {
$msg = 'Failed prelim has been entered for '.$entry->audition->name.' #'.$entry->draw_number.' (ID: '.$entry->id.').';
$entry->addFlag('failed_prelim');
} else {
$entry->addFlag('no_show');
$msg = 'No Show has been entered for '.$entry->audition->name.' #'.$entry->draw_number.' (ID: '.$entry->id.').';
}
return $msg;
}
}