Rewrite EnterScore action to deal with both seating and advancement totals.
This commit is contained in:
parent
86f715f086
commit
783ec991b3
|
|
@ -71,8 +71,10 @@ class EnterScore
|
|||
// Check the validity of submitted subscores, format array for storage, and sum score
|
||||
$subscoresRequired = $entry->audition->scoringGuide->subscores;
|
||||
$subscoresStorageArray = [];
|
||||
$scoreSheetTotal = 0;
|
||||
$maxPossible = 0;
|
||||
$seatingTotal = 0;
|
||||
$seatingMaxPossible = 0;
|
||||
$advancementTotal = 0;
|
||||
$advancementMaxPossible = 0;
|
||||
if ($scores->count() !== $subscoresRequired->count()) {
|
||||
throw new ScoreEntryException('Invalid number of scores');
|
||||
}
|
||||
|
|
@ -93,12 +95,20 @@ class EnterScore
|
|||
'subscore_name' => $subscore->name,
|
||||
];
|
||||
|
||||
// Multiply subscore by weight and add to the total
|
||||
$scoreSheetTotal += ($subscore->weight * $scores[$subscore->id]);
|
||||
// If included in seating, multiply by weight and add to the total and max possible
|
||||
if ($subscore->for_seating) {
|
||||
$seatingTotal += ($subscore->weight * $scores[$subscore->id]);
|
||||
$seatingMaxPossible += ($subscore->weight * $subscore->max_score);
|
||||
}
|
||||
|
||||
// Add weight to total weights
|
||||
$maxPossible += ($subscore->weight * $subscore->max_score);
|
||||
// If included in advancement, multiply by weight and add to the total and max possible
|
||||
if ($subscore->for_advance) {
|
||||
$advancementTotal += ($subscore->weight * $scores[$subscore->id]);
|
||||
$advancementMaxPossible += ($subscore->weight * $subscore->max_score);
|
||||
}
|
||||
}
|
||||
$finalSeatingTotal = ($seatingMaxPossible === 0) ? 0 : (($seatingTotal / $seatingMaxPossible) * 100);
|
||||
$finalAdvancementTotal = ($advancementMaxPossible === 0) ? 0 : (($advancementTotal / $advancementMaxPossible) * 100);
|
||||
|
||||
$entry->removeFlag('no_show');
|
||||
if ($scoreSheet instanceof ScoreSheet) {
|
||||
|
|
@ -106,15 +116,16 @@ class EnterScore
|
|||
'user_id' => $user->id,
|
||||
'entry_id' => $entry->id,
|
||||
'subscores' => $subscoresStorageArray,
|
||||
'sheet_total' => ($scoreSheetTotal / $maxPossible) * 100,
|
||||
'seating_total' => $finalSeatingTotal,
|
||||
'advancement_total' => $finalAdvancementTotal,
|
||||
]);
|
||||
} else {
|
||||
$finalTotal = ($scoreSheetTotal / $maxPossible) * 100;
|
||||
$scoreSheet = ScoreSheet::create([
|
||||
'user_id' => $user->id,
|
||||
'entry_id' => $entry->id,
|
||||
'subscores' => $subscoresStorageArray,
|
||||
'sheet_total' => $finalTotal,
|
||||
'seating_total' => $finalSeatingTotal,
|
||||
'advancement_total' => $finalAdvancementTotal,
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -124,7 +135,8 @@ class EnterScore
|
|||
foreach ($scoreSheet->subscores as $subscore) {
|
||||
$log_message .= $subscore['subscore_name'].': '.$subscore['score'].'<br />';
|
||||
}
|
||||
$log_message .= 'Total: '.$scoreSheet->sheet_total;
|
||||
$log_message .= 'Seating Total: '.$scoreSheet->seating_total.'<br />';
|
||||
$log_message .= 'Advancement Total: '.$scoreSheet->advancement_total.'<br />';
|
||||
AuditLogEntry::create([
|
||||
'user' => auth()->user()->email ?? 'no user',
|
||||
'ip_address' => request()->ip(),
|
||||
|
|
|
|||
|
|
@ -13,7 +13,8 @@ class ScoreSheet extends Model
|
|||
'user_id',
|
||||
'entry_id',
|
||||
'subscores',
|
||||
'sheet_total',
|
||||
'seating_total',
|
||||
'advancement_total',
|
||||
];
|
||||
|
||||
protected $casts = ['subscores' => 'json'];
|
||||
|
|
|
|||
|
|
@ -12,7 +12,10 @@ return new class extends Migration
|
|||
public function up(): void
|
||||
{
|
||||
Schema::table('score_sheets', function (Blueprint $table) {
|
||||
$table->decimal('sheet_total', 9, 6)->after('subscores');
|
||||
$table->decimal('seating_total', 9, 6)->after('subscores');
|
||||
});
|
||||
Schema::table('score_sheets', function (Blueprint $table) {
|
||||
$table->decimal('advancement_total', 9, 6)->after('seating_total');
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -22,7 +25,8 @@ return new class extends Migration
|
|||
public function down(): void
|
||||
{
|
||||
Schema::table('score_sheets', function (Blueprint $table) {
|
||||
$table->dropColumn('sheet_total');
|
||||
$table->dropColumn('seating_total');
|
||||
$table->dropColumn('advancement_total');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue