From f0daa05fcf240db7ba64c55435bcad11abbeace1 Mon Sep 17 00:00:00 2001 From: Matt Young Date: Mon, 23 Jun 2025 02:36:44 -0500 Subject: [PATCH] Model updates dealing with doublers. --- app/Models/Doubler.php | 25 +++++++++++++++---------- app/Models/Student.php | 2 +- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/app/Models/Doubler.php b/app/Models/Doubler.php index 0da8d7a..74d1c56 100644 --- a/app/Models/Doubler.php +++ b/app/Models/Doubler.php @@ -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( diff --git a/app/Models/Student.php b/app/Models/Student.php index 3769f74..6b3c943 100644 --- a/app/Models/Student.php +++ b/app/Models/Student.php @@ -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();