forked from TFMM/silent-auction
add score to winner table
This commit is contained in:
@@ -15,7 +15,6 @@ class TabulateWinnersNew extends Command
|
||||
|
||||
public function handle()
|
||||
{
|
||||
// 1. Reset the winners table
|
||||
CarShowWinner::truncate();
|
||||
|
||||
$this->info('Starting tabulation...');
|
||||
@@ -36,35 +35,21 @@ class TabulateWinnersNew extends Command
|
||||
|
||||
foreach ($yearConfigs as $config) {
|
||||
$this->info("Processing Category: {$config['name']}");
|
||||
|
||||
// Rank 1st: Set $excludeExisting to FALSE so they can win even if they won Best in Show
|
||||
$this->recordJudgedWinners($config['id'], 'first', $config['start'], $config['end'], false);
|
||||
|
||||
// Rank 2nd: Set $excludeExisting to TRUE (standard behavior)
|
||||
$this->recordJudgedWinners($config['id'], 'second', $config['start'], $config['end'], true);
|
||||
|
||||
// Rank 3rd: Set $excludeExisting to TRUE
|
||||
$this->recordJudgedWinners($config['id'], 'third', $config['start'], $config['end'], true);
|
||||
|
||||
// Rank 4th: Set $excludeExisting to TRUE
|
||||
$this->recordJudgedWinners($config['id'], 'fourth', $config['start'], $config['end'], true);
|
||||
|
||||
// Rank 5th: Set $excludeExisting to TRUE
|
||||
$this->recordJudgedWinners($config['id'], 'fifth', $config['start'], $config['end'], true);
|
||||
}
|
||||
|
||||
$this->info('Winners tabulated successfully.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $excludeExisting If true, ignores vehicles already in the winners table.
|
||||
*/
|
||||
private function recordJudgedWinners($categoryId, $place, $startYear = null, $endYear = null, $excludeExisting = true)
|
||||
{
|
||||
$query = VehicleScores::join('vehicles', 'vehicle_scores.vehicle', '=', 'vehicles.id')
|
||||
->where('vehicles.doNotJudge', 0);
|
||||
|
||||
// Conditional exclusion
|
||||
if ($excludeExisting) {
|
||||
$query->whereNotIn('vehicle_scores.vehicle', function ($q) {
|
||||
$q->select('vehicle')->from('car_show_winners');
|
||||
@@ -87,11 +72,12 @@ class TabulateWinnersNew extends Command
|
||||
->get();
|
||||
|
||||
foreach ($winners as $winner) {
|
||||
// Use updateOrCreate to prevent the exact same car/category/place combo doubling up
|
||||
CarShowWinner::updateOrCreate([
|
||||
'category' => $categoryId,
|
||||
'place' => $place,
|
||||
'vehicle' => $winner->vehicle_id,
|
||||
'vehicle' => $winner->vehicle_id
|
||||
], [
|
||||
// Added totalscore here
|
||||
'total_score' => $winner->totalscore
|
||||
]);
|
||||
}
|
||||
@@ -100,7 +86,6 @@ class TabulateWinnersNew extends Command
|
||||
|
||||
private function recordPeoplesChoiceWinners($categoryId, $place)
|
||||
{
|
||||
// People's Choice usually excludes the Best in Show winner
|
||||
$maxVotes = PeoplesChoice::join('vehicles', 'peoples_choice.vehicle', '=', 'vehicles.id')
|
||||
->where('vehicles.doNotJudge', 0)
|
||||
->whereNotIn('peoples_choice.vehicle', function ($q) {
|
||||
@@ -127,6 +112,7 @@ class TabulateWinnersNew extends Command
|
||||
'category' => $categoryId,
|
||||
'place' => $place,
|
||||
'vehicle' => $winner->vehicle_id,
|
||||
// Added totalvotes here
|
||||
'total_score' => $winner->totalvotes
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user