42 lines
1.3 KiB
PHP
42 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Actions\Tabulation\EnterScore;
|
|
use App\Models\ScoreSheet;
|
|
use Illuminate\Console\Command;
|
|
|
|
class RecalculateJudgeTotalsCommand extends Command
|
|
{
|
|
protected $signature = 'audition:recalculate-judge-totals';
|
|
|
|
protected $description = 'Recalculates total scores for all score sheets for unpubished auditions';
|
|
|
|
public function handle(): void
|
|
{
|
|
$this->info('Starting score recalculation...');
|
|
$scoreSheets = ScoreSheet::all();
|
|
foreach ($scoreSheets as $scoreSheet) {
|
|
if ($scoreSheet->entry->audition->hasFlag('seats_published')) {
|
|
continue;
|
|
}
|
|
$this->recalculate($scoreSheet);
|
|
}
|
|
|
|
$this->info('Score recalculation completed successfully.');
|
|
}
|
|
|
|
private function recalculate(ScoreSheet|int $scoreSheet): void
|
|
{
|
|
if (is_int($scoreSheet)) {
|
|
$scoreSheet = ScoreSheet::findOrFail($scoreSheet);
|
|
}
|
|
$scribe = app()->make(EnterScore::class);
|
|
$scoreSubmission = [];
|
|
foreach ($scoreSheet->subscores as $subscore) {
|
|
$scoreSubmission[$subscore['subscore_id']] = $subscore['score'];
|
|
}
|
|
$scribe($scoreSheet->judge, $scoreSheet->entry, $scoreSubmission, $scoreSheet);
|
|
}
|
|
}
|