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()
|
public function handle()
|
||||||
{
|
{
|
||||||
// 1. Reset the winners table
|
|
||||||
CarShowWinner::truncate();
|
CarShowWinner::truncate();
|
||||||
|
|
||||||
$this->info('Starting tabulation...');
|
$this->info('Starting tabulation...');
|
||||||
@@ -36,35 +35,21 @@ class TabulateWinnersNew extends Command
|
|||||||
|
|
||||||
foreach ($yearConfigs as $config) {
|
foreach ($yearConfigs as $config) {
|
||||||
$this->info("Processing Category: {$config['name']}");
|
$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);
|
$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);
|
$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);
|
$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);
|
$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->recordJudgedWinners($config['id'], 'fifth', $config['start'], $config['end'], true);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->info('Winners tabulated successfully.');
|
$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)
|
private function recordJudgedWinners($categoryId, $place, $startYear = null, $endYear = null, $excludeExisting = true)
|
||||||
{
|
{
|
||||||
$query = VehicleScores::join('vehicles', 'vehicle_scores.vehicle', '=', 'vehicles.id')
|
$query = VehicleScores::join('vehicles', 'vehicle_scores.vehicle', '=', 'vehicles.id')
|
||||||
->where('vehicles.doNotJudge', 0);
|
->where('vehicles.doNotJudge', 0);
|
||||||
|
|
||||||
// Conditional exclusion
|
|
||||||
if ($excludeExisting) {
|
if ($excludeExisting) {
|
||||||
$query->whereNotIn('vehicle_scores.vehicle', function ($q) {
|
$query->whereNotIn('vehicle_scores.vehicle', function ($q) {
|
||||||
$q->select('vehicle')->from('car_show_winners');
|
$q->select('vehicle')->from('car_show_winners');
|
||||||
@@ -87,12 +72,13 @@ class TabulateWinnersNew extends Command
|
|||||||
->get();
|
->get();
|
||||||
|
|
||||||
foreach ($winners as $winner) {
|
foreach ($winners as $winner) {
|
||||||
// Use updateOrCreate to prevent the exact same car/category/place combo doubling up
|
|
||||||
CarShowWinner::updateOrCreate([
|
CarShowWinner::updateOrCreate([
|
||||||
'category' => $categoryId,
|
'category' => $categoryId,
|
||||||
'place' => $place,
|
'place' => $place,
|
||||||
'vehicle' => $winner->vehicle_id,
|
'vehicle' => $winner->vehicle_id
|
||||||
'total_score' => $winner->totalscore
|
], [
|
||||||
|
// Added totalscore here
|
||||||
|
'total_score' => $winner->totalscore
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -100,7 +86,6 @@ class TabulateWinnersNew extends Command
|
|||||||
|
|
||||||
private function recordPeoplesChoiceWinners($categoryId, $place)
|
private function recordPeoplesChoiceWinners($categoryId, $place)
|
||||||
{
|
{
|
||||||
// People's Choice usually excludes the Best in Show winner
|
|
||||||
$maxVotes = PeoplesChoice::join('vehicles', 'peoples_choice.vehicle', '=', 'vehicles.id')
|
$maxVotes = PeoplesChoice::join('vehicles', 'peoples_choice.vehicle', '=', 'vehicles.id')
|
||||||
->where('vehicles.doNotJudge', 0)
|
->where('vehicles.doNotJudge', 0)
|
||||||
->whereNotIn('peoples_choice.vehicle', function ($q) {
|
->whereNotIn('peoples_choice.vehicle', function ($q) {
|
||||||
@@ -127,7 +112,8 @@ class TabulateWinnersNew extends Command
|
|||||||
'category' => $categoryId,
|
'category' => $categoryId,
|
||||||
'place' => $place,
|
'place' => $place,
|
||||||
'vehicle' => $winner->vehicle_id,
|
'vehicle' => $winner->vehicle_id,
|
||||||
'total_score' => $winner->totalvotes
|
// Added totalvotes here
|
||||||
|
'total_score' => $winner->totalvotes
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user