Auditionadmin 20 - Bonus scores are fully functional #25

Merged
okorpheus merged 16 commits from auditionadmin-20 into master 2024-07-16 08:04:08 +00:00
1 changed files with 36 additions and 4 deletions
Showing only changes of commit c04dd02405 - Show all commits

View File

@ -5,20 +5,27 @@
namespace App\Actions\Tabulation;
use App\Exceptions\TabulationException;
use App\Models\BonusScore;
use App\Models\Entry;
use App\Services\AuditionService;
use App\Services\EntryService;
use Illuminate\Support\Facades\Cache;
use function auditionSetting;
class AllowForOlympicScoring implements CalculateEntryScore
{
protected CalculateScoreSheetTotal $calculator;
protected AuditionService $auditionService;
protected EntryService $entryService;
public function __construct(CalculateScoreSheetTotal $calculator, AuditionService $auditionService, EntryService $entryService)
{
public function __construct(
CalculateScoreSheetTotal $calculator,
AuditionService $auditionService,
EntryService $entryService
) {
$this->calculator = $calculator;
$this->auditionService = $auditionService;
$this->entryService = $entryService;
@ -28,6 +35,7 @@ class AllowForOlympicScoring implements CalculateEntryScore
{
$cacheKey = 'entryScore-'.$entry->id.'-'.$mode;
return Cache::remember($cacheKey, 10, function () use ($mode, $entry) {
$this->basicValidation($mode, $entry);
$this->areAllJudgesIn($entry);
@ -38,7 +46,7 @@ class AllowForOlympicScoring implements CalculateEntryScore
}
protected function getJudgeTotals($mode, Entry $entry)
protected function getJudgeTotals($mode, Entry $entry): array
{
$scores = [];
@ -55,7 +63,7 @@ class AllowForOlympicScoring implements CalculateEntryScore
// remove the highest and lowest scores
array_pop($scores);
array_shift($scores);
}
}
$sums = [];
// Sum each subscore from the judges
foreach ($scores as $score) {
@ -66,9 +74,33 @@ class AllowForOlympicScoring implements CalculateEntryScore
$index++;
}
}
// add the bonus points for a seating mode
if ($mode === 'seating') {
$sums[0] += $this->getBonusPoints($entry);
}
return $sums;
}
protected function getBonusPoints(Entry $entry)
{
$bonusScoreDefinition = $entry->audition->bonusScore()->first();
if (! $bonusScoreDefinition) {
return 0;
}
$bonusJudges = $bonusScoreDefinition->judges;
$bonusScoreSheets = BonusScore::where('entry_id', $entry->id)->get();
foreach ($bonusScoreSheets as $sheet) {
if (! $bonusJudges->contains($sheet->user_id)) {
throw new TabulationException('Entry has a bonus score from unassigned judge');
}
}
// sum the score property of the $bonusScoreSheets
return $bonusScoreSheets->sum('score');
}
protected function basicValidation($mode, $entry): void
{
if ($mode !== 'seating' && $mode !== 'advancement') {