Cleanup on doubler model
This commit is contained in:
parent
f0daa05fcf
commit
88ef36d8be
|
|
@ -62,29 +62,31 @@ class Doubler extends Model
|
||||||
->havingRaw('COUNT(entries.id) > 1')
|
->havingRaw('COUNT(entries.id) > 1')
|
||||||
->with('entries')
|
->with('entries')
|
||||||
->get();
|
->get();
|
||||||
|
Doubler::where('event_id', $eventId)->delete();
|
||||||
foreach ($studentsWithMultipleEntries as $student) {
|
foreach ($studentsWithMultipleEntries as $student) {
|
||||||
// Get entries that are not declined. If only one, they're our accepted entry.
|
// Get entries that are not declined. If only one, they're our accepted entry.
|
||||||
$entryList = collect(); // List of entry ids for th is student in this event
|
$entryList = collect(); // List of entry ids for th is student in this event
|
||||||
$undecidedEntries = collect(); // List of entry ids that are not declined, no-show, or failed prelim
|
$undecidedEntries = collect(); // List of entry ids that are not declined, no-show, or failed prelim
|
||||||
$entryList = $student->entriesForEvent($eventId)->pluck('id');
|
$entryList = $student->entriesForEvent($eventId)->pluck('id');
|
||||||
$undecidedEntries = $student->entriesForEvent($eventId)
|
$undecidedEntries = $student->entriesForEvent($eventId)->filter(function ($entry) {
|
||||||
->whereDoesntHave('flags', function ($query) {
|
return ! $entry->hasFlag('declined')
|
||||||
$query->whereIn('flag_name', ['declined', 'no-show', 'failed-prelim']);
|
&& ! $entry->hasFlag('no_show')
|
||||||
})
|
&& ! $entry->hasFlag('failed_prelim');
|
||||||
->pluck('id');
|
})->pluck('id');
|
||||||
|
if ($undecidedEntries->count() < 2) {
|
||||||
|
$acceptedEntryId = $undecidedEntries->first();
|
||||||
|
} else {
|
||||||
|
$acceptedEntryId = null;
|
||||||
|
}
|
||||||
|
|
||||||
// Create or update the doubler record
|
// Create or update the doubler record
|
||||||
static::updateOrCreate(
|
static::create([
|
||||||
[
|
'student_id' => $student->id,
|
||||||
'student_id' => $student->id,
|
'event_id' => $eventId,
|
||||||
'event_id' => $eventId,
|
'entries' => $entryList,
|
||||||
],
|
'accepted_entry' => $acceptedEntryId,
|
||||||
[
|
]);
|
||||||
'entries' => $entryList,
|
|
||||||
'accepted_entry' => $acceptedEntryId,
|
|
||||||
]
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove doubler records for students who no longer have multiple entries
|
// remove doubler records for students who no longer have multiple entries
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue