diff --git a/app/Actions/Tabulation/CalculateAuditionScores.php b/app/Actions/Tabulation/CalculateAuditionScores.php new file mode 100644 index 0000000..72d774c --- /dev/null +++ b/app/Actions/Tabulation/CalculateAuditionScores.php @@ -0,0 +1,30 @@ +judges->count(); + $pending_entries = Entry::where('audition_id', $audition->id) + ->has('scoreSheets', '=', $scores_required) + ->whereDoesntHave('totalScore') + ->with('audition.scoringGuide.subscores') + ->get(); + foreach ($pending_entries as $entry) { + Debugbar::debug('Calculating scores for entry: '.$entry->id); + $totaler->__invoke($entry); + } + } +} diff --git a/app/Actions/Tabulation/TotalEntryScores.php b/app/Actions/Tabulation/TotalEntryScores.php index be6e305..241a9af 100644 --- a/app/Actions/Tabulation/TotalEntryScores.php +++ b/app/Actions/Tabulation/TotalEntryScores.php @@ -6,6 +6,10 @@ use App\Models\Entry; use App\Models\EntryTotalScore; use App\Models\ScoreSheet; +/** + * Handles the calculation of a total score for an entry, including seating and advancement scores, + * based on scoring sheets and subscores defined in the audition's scoring guide. + */ class TotalEntryScores { public function __construct() @@ -67,6 +71,5 @@ class TotalEntryScores } $newTotaledScore->advancement_subscore_totals = $total_advancement_subscores; $newTotaledScore->save(); - dd($newTotaledScore); } } diff --git a/app/Models/ScoreSheet.php b/app/Models/ScoreSheet.php index a5b7dd8..e025272 100644 --- a/app/Models/ScoreSheet.php +++ b/app/Models/ScoreSheet.php @@ -5,7 +5,6 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasOneThrough; -use Illuminate\Support\Facades\Cache; class ScoreSheet extends Model { @@ -19,22 +18,6 @@ class ScoreSheet extends Model protected $casts = ['subscores' => 'json']; - protected static function boot() - { - parent::boot(); - static::created(function ($scoreSheet) { - $scoreSheet->deleteRelatedCalculatedScores(); - }); - - static::updated(function ($scoreSheet) { - $scoreSheet->deleteRelatedCalculatedScores(); - }); - - static::deleted(function ($scoreSheet) { - $scoreSheet->deleteRelatedCalculatedScores(); - }); - } - public function entry(): BelongsTo { return $this->belongsTo(Entry::class); @@ -62,16 +45,4 @@ class ScoreSheet extends Model return $this->subscores[$id]['score'] ?? false; // this function is used at resources/views/tabulation/entry_score_sheet.blade.php } - - public function deleteRelatedCalculatedScores(): void - { - $entry = $this->entry; - if ($entry) { - $entry->calculatedScores()->delete(); - Cache::forget('entryScore-'.$entry->id.'-seating'); - Cache::forget('entryScore-'.$entry->id.'-advancement'); - Cache::forget('audition'.$entry->audition_id.'seating'); - Cache::forget('audition'.$entry->audition_id.'advancement'); - } - } } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 5211a7e..1ff4c7b 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -5,11 +5,10 @@ namespace App\Providers; use App\Actions\Entries\CreateEntry; use App\Actions\Entries\UpdateEntry; use App\Actions\Schools\SetHeadDirector; -use App\Actions\Tabulation\AllowForOlympicScoring; -use App\Actions\Tabulation\CalculateEntryScore; +use App\Actions\Tabulation\CalculateAuditionScores; use App\Actions\Tabulation\CalculateScoreSheetTotal; use App\Actions\Tabulation\CalculateScoreSheetTotalDivideByTotalWeights; -use App\Actions\Tabulation\CalculateScoreSheetTotalDivideByWeightedPossible; +use App\Actions\Tabulation\TotalEntryScores; use App\Http\Controllers\NominationEnsembles\NominationAdminController; use App\Http\Controllers\NominationEnsembles\NominationEnsembleController; use App\Http\Controllers\NominationEnsembles\NominationEnsembleEntryController; @@ -58,8 +57,6 @@ class AppServiceProvider extends ServiceProvider { //$this->app->singleton(CalculateScoreSheetTotal::class, CalculateScoreSheetTotal::class); //$this->app->singleton(CalculateScoreSheetTotal::class, CalculateScoreSheetTotalDivideByTotalWeights::class); - $this->app->singleton(CalculateScoreSheetTotal::class, CalculateScoreSheetTotalDivideByWeightedPossible::class); - $this->app->singleton(CalculateEntryScore::class, AllowForOlympicScoring::class); $this->app->singleton(DrawService::class, DrawService::class); $this->app->singleton(AuditionService::class, AuditionService::class); $this->app->singleton(EntryService::class, EntryService::class); @@ -69,6 +66,8 @@ class AppServiceProvider extends ServiceProvider $this->app->singleton(CreateEntry::class, CreateEntry::class); $this->app->singleton(UpdateEntry::class, UpdateEntry::class); $this->app->singleton(SetHeadDirector::class, SetHeadDirector::class); + $this->app->singleton(TotalEntryScores::class, TotalEntryScores::class); + $this->app->singleton(CalculateAuditionScores::class, CalculateAuditionScores::class); // Nomination Ensemble // $this->app->bind(NominationEnsembleController::class, ScobdaNominationEnsembleController::class);