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
|
// Check the validity of submitted subscores, format array for storage, and sum score
|
||||||
$subscoresRequired = $entry->audition->scoringGuide->subscores;
|
$subscoresRequired = $entry->audition->scoringGuide->subscores;
|
||||||
$subscoresStorageArray = [];
|
$subscoresStorageArray = [];
|
||||||
$scoreSheetTotal = 0;
|
$seatingTotal = 0;
|
||||||
$maxPossible = 0;
|
$seatingMaxPossible = 0;
|
||||||
|
$advancementTotal = 0;
|
||||||
|
$advancementMaxPossible = 0;
|
||||||
if ($scores->count() !== $subscoresRequired->count()) {
|
if ($scores->count() !== $subscoresRequired->count()) {
|
||||||
throw new ScoreEntryException('Invalid number of scores');
|
throw new ScoreEntryException('Invalid number of scores');
|
||||||
}
|
}
|
||||||
|
|
@ -93,28 +95,37 @@ class EnterScore
|
||||||
'subscore_name' => $subscore->name,
|
'subscore_name' => $subscore->name,
|
||||||
];
|
];
|
||||||
|
|
||||||
// Multiply subscore by weight and add to the total
|
// If included in seating, multiply by weight and add to the total and max possible
|
||||||
$scoreSheetTotal += ($subscore->weight * $scores[$subscore->id]);
|
if ($subscore->for_seating) {
|
||||||
|
$seatingTotal += ($subscore->weight * $scores[$subscore->id]);
|
||||||
// Add weight to total weights
|
$seatingMaxPossible += ($subscore->weight * $subscore->max_score);
|
||||||
$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');
|
$entry->removeFlag('no_show');
|
||||||
if ($scoreSheet instanceof ScoreSheet) {
|
if ($scoreSheet instanceof ScoreSheet) {
|
||||||
$scoreSheet->update([
|
$scoreSheet->update([
|
||||||
'user_id' => $user->id,
|
'user_id' => $user->id,
|
||||||
'entry_id' => $entry->id,
|
'entry_id' => $entry->id,
|
||||||
'subscores' => $subscoresStorageArray,
|
'subscores' => $subscoresStorageArray,
|
||||||
'sheet_total' => ($scoreSheetTotal / $maxPossible) * 100,
|
'seating_total' => $finalSeatingTotal,
|
||||||
|
'advancement_total' => $finalAdvancementTotal,
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
$finalTotal = ($scoreSheetTotal / $maxPossible) * 100;
|
|
||||||
$scoreSheet = ScoreSheet::create([
|
$scoreSheet = ScoreSheet::create([
|
||||||
'user_id' => $user->id,
|
'user_id' => $user->id,
|
||||||
'entry_id' => $entry->id,
|
'entry_id' => $entry->id,
|
||||||
'subscores' => $subscoresStorageArray,
|
'subscores' => $subscoresStorageArray,
|
||||||
'sheet_total' => $finalTotal,
|
'seating_total' => $finalSeatingTotal,
|
||||||
|
'advancement_total' => $finalAdvancementTotal,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -124,7 +135,8 @@ class EnterScore
|
||||||
foreach ($scoreSheet->subscores as $subscore) {
|
foreach ($scoreSheet->subscores as $subscore) {
|
||||||
$log_message .= $subscore['subscore_name'].': '.$subscore['score'].'<br />';
|
$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([
|
AuditLogEntry::create([
|
||||||
'user' => auth()->user()->email ?? 'no user',
|
'user' => auth()->user()->email ?? 'no user',
|
||||||
'ip_address' => request()->ip(),
|
'ip_address' => request()->ip(),
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,8 @@ class ScoreSheet extends Model
|
||||||
'user_id',
|
'user_id',
|
||||||
'entry_id',
|
'entry_id',
|
||||||
'subscores',
|
'subscores',
|
||||||
'sheet_total',
|
'seating_total',
|
||||||
|
'advancement_total',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $casts = ['subscores' => 'json'];
|
protected $casts = ['subscores' => 'json'];
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,10 @@ return new class extends Migration
|
||||||
public function up(): void
|
public function up(): void
|
||||||
{
|
{
|
||||||
Schema::table('score_sheets', function (Blueprint $table) {
|
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
|
public function down(): void
|
||||||
{
|
{
|
||||||
Schema::table('score_sheets', function (Blueprint $table) {
|
Schema::table('score_sheets', function (Blueprint $table) {
|
||||||
$table->dropColumn('sheet_total');
|
$table->dropColumn('seating_total');
|
||||||
|
$table->dropColumn('advancement_total');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue