Calculate all total scores for an audition.
This commit is contained in:
parent
8647a66df8
commit
fd198a9972
|
|
@ -0,0 +1,30 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\Tabulation;
|
||||||
|
|
||||||
|
use App\Models\Audition;
|
||||||
|
use App\Models\Entry;
|
||||||
|
use Debugbar;
|
||||||
|
|
||||||
|
class CalculateAuditionScores
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __invoke(Audition $audition): void
|
||||||
|
{
|
||||||
|
$totaler = app(TotalEntryScores::class);
|
||||||
|
$scores_required = $audition->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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -6,6 +6,10 @@ use App\Models\Entry;
|
||||||
use App\Models\EntryTotalScore;
|
use App\Models\EntryTotalScore;
|
||||||
use App\Models\ScoreSheet;
|
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
|
class TotalEntryScores
|
||||||
{
|
{
|
||||||
public function __construct()
|
public function __construct()
|
||||||
|
|
@ -67,6 +71,5 @@ class TotalEntryScores
|
||||||
}
|
}
|
||||||
$newTotaledScore->advancement_subscore_totals = $total_advancement_subscores;
|
$newTotaledScore->advancement_subscore_totals = $total_advancement_subscores;
|
||||||
$newTotaledScore->save();
|
$newTotaledScore->save();
|
||||||
dd($newTotaledScore);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ namespace App\Models;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
|
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
|
||||||
use Illuminate\Support\Facades\Cache;
|
|
||||||
|
|
||||||
class ScoreSheet extends Model
|
class ScoreSheet extends Model
|
||||||
{
|
{
|
||||||
|
|
@ -19,22 +18,6 @@ class ScoreSheet extends Model
|
||||||
|
|
||||||
protected $casts = ['subscores' => 'json'];
|
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
|
public function entry(): BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Entry::class);
|
return $this->belongsTo(Entry::class);
|
||||||
|
|
@ -62,16 +45,4 @@ class ScoreSheet extends Model
|
||||||
return $this->subscores[$id]['score'] ?? false;
|
return $this->subscores[$id]['score'] ?? false;
|
||||||
// this function is used at resources/views/tabulation/entry_score_sheet.blade.php
|
// 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');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,10 @@ namespace App\Providers;
|
||||||
use App\Actions\Entries\CreateEntry;
|
use App\Actions\Entries\CreateEntry;
|
||||||
use App\Actions\Entries\UpdateEntry;
|
use App\Actions\Entries\UpdateEntry;
|
||||||
use App\Actions\Schools\SetHeadDirector;
|
use App\Actions\Schools\SetHeadDirector;
|
||||||
use App\Actions\Tabulation\AllowForOlympicScoring;
|
use App\Actions\Tabulation\CalculateAuditionScores;
|
||||||
use App\Actions\Tabulation\CalculateEntryScore;
|
|
||||||
use App\Actions\Tabulation\CalculateScoreSheetTotal;
|
use App\Actions\Tabulation\CalculateScoreSheetTotal;
|
||||||
use App\Actions\Tabulation\CalculateScoreSheetTotalDivideByTotalWeights;
|
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\NominationAdminController;
|
||||||
use App\Http\Controllers\NominationEnsembles\NominationEnsembleController;
|
use App\Http\Controllers\NominationEnsembles\NominationEnsembleController;
|
||||||
use App\Http\Controllers\NominationEnsembles\NominationEnsembleEntryController;
|
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, CalculateScoreSheetTotal::class);
|
||||||
//$this->app->singleton(CalculateScoreSheetTotal::class, CalculateScoreSheetTotalDivideByTotalWeights::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(DrawService::class, DrawService::class);
|
||||||
$this->app->singleton(AuditionService::class, AuditionService::class);
|
$this->app->singleton(AuditionService::class, AuditionService::class);
|
||||||
$this->app->singleton(EntryService::class, EntryService::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(CreateEntry::class, CreateEntry::class);
|
||||||
$this->app->singleton(UpdateEntry::class, UpdateEntry::class);
|
$this->app->singleton(UpdateEntry::class, UpdateEntry::class);
|
||||||
$this->app->singleton(SetHeadDirector::class, SetHeadDirector::class);
|
$this->app->singleton(SetHeadDirector::class, SetHeadDirector::class);
|
||||||
|
$this->app->singleton(TotalEntryScores::class, TotalEntryScores::class);
|
||||||
|
$this->app->singleton(CalculateAuditionScores::class, CalculateAuditionScores::class);
|
||||||
|
|
||||||
// Nomination Ensemble
|
// Nomination Ensemble
|
||||||
// $this->app->bind(NominationEnsembleController::class, ScobdaNominationEnsembleController::class);
|
// $this->app->bind(NominationEnsembleController::class, ScobdaNominationEnsembleController::class);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue