Model updates dealing with doublers.

This commit is contained in:
Matt Young 2025-06-23 02:36:44 -05:00
parent 630efaf00f
commit f0daa05fcf
2 changed files with 16 additions and 11 deletions

View File

@ -4,6 +4,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Collection;
class Doubler extends Model
{
@ -28,6 +29,11 @@ class Doubler extends Model
return $this->belongsTo(Event::class);
}
public function entries(): Collection
{
return Entry::whereIn('id', $this->entries)->get();
}
// Find a doubler based on both keys
public static function findDoubler($studentId, $eventId)
{
@ -54,20 +60,19 @@ class Doubler extends Model
->where('auditions.event_id', $eventId)
->groupBy('students.id')
->havingRaw('COUNT(entries.id) > 1')
->with('entries')
->get();
foreach ($studentsWithMultipleEntries as $student) {
// Get entries that are not declined. If only one, they're our accepted entry.
$availableEntries = $student->entries()->available()->get();
if ($availableEntries->count() === 1) {
$acceptedEntryId = $availableEntries->first()->id;
} else {
$acceptedEntryId = null;
}
// Form a list of entry IDs for this doubler
$entryList = [];
$entryList = $student->entriesForEvent($eventId)->pluck('id')->toArray();
$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
$entryList = $student->entriesForEvent($eventId)->pluck('id');
$undecidedEntries = $student->entriesForEvent($eventId)
->whereDoesntHave('flags', function ($query) {
$query->whereIn('flag_name', ['declined', 'no-show', 'failed-prelim']);
})
->pluck('id');
// Create or update the doubler record
static::updateOrCreate(

View File

@ -99,7 +99,7 @@ class Student extends Model
{
$eventId = $event instanceof Event ? $event->id : $event;
return DoublerEntryCount::where([
return Doubler::where([
'event_id' => $eventId,
'student_id' => $this->id,
])->exists();