From 34e22187ddf21ecc95f9b409fd587c092dc4731a Mon Sep 17 00:00:00 2001 From: Matt Young Date: Sat, 14 Jun 2025 11:12:36 -0500 Subject: [PATCH] Set foundation for new handling of doublers --- app/Models/Audition.php | 14 +++++++- app/Models/DoublerEntryCount.php | 21 +++++++++++ app/Models/Student.php | 18 ++++++++++ ...2025_06_14_142507_doubler_entry_counts.php | 35 +++++++++++++++++++ 4 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 app/Models/DoublerEntryCount.php create mode 100644 database/migrations/2025_06_14_142507_doubler_entry_counts.php diff --git a/app/Models/Audition.php b/app/Models/Audition.php index c8599cb..e3957d0 100644 --- a/app/Models/Audition.php +++ b/app/Models/Audition.php @@ -11,6 +11,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Support\Collection; use function in_array; class Audition extends Model @@ -81,7 +82,7 @@ class Audition extends Model */ public function getJudgesCountAttribute() { - if (! isset($this->attributes['judges_count'])) { + if (!isset($this->attributes['judges_count'])) { $this->attributes['judges_count'] = $this->judges()->count(); } @@ -129,6 +130,17 @@ class Audition extends Model return $this->hasMany(Seat::class); } + public function getDoublerEntries(): Collection + { + return $this->entries() + ->whereIn('student_id', function ($query) { + $query->select('student_id') + ->from('doubler_entry_counts') + ->where('event_id', $this->event_id); + }) + ->get(); + } + public function scopeOpen(Builder $query): void { $currentDate = Carbon::now('America/Chicago'); diff --git a/app/Models/DoublerEntryCount.php b/app/Models/DoublerEntryCount.php new file mode 100644 index 0000000..38ffb02 --- /dev/null +++ b/app/Models/DoublerEntryCount.php @@ -0,0 +1,21 @@ +belongsTo(Student::class); + } + + public function event(): BelongsTo + { + return $this->belongsTo(Event::class); + } +} diff --git a/app/Models/Student.php b/app/Models/Student.php index 2554aa2..004f4bf 100644 --- a/app/Models/Student.php +++ b/app/Models/Student.php @@ -50,6 +50,9 @@ class Student extends Model return $this->hasMany(HistoricalSeat::class); } + /** + * Returns the directors at this student's school. + */ public function users(): HasManyThrough { return $this->hasManyThrough( @@ -62,6 +65,11 @@ class Student extends Model ); } + /** + * Returns the directors at this student's school. + * Alias of users()) + * ' + */ public function directors(): HasManyThrough { return $this->users(); @@ -85,4 +93,14 @@ class Student extends Model { return $this->hasMany(DoublerRequest::class); } + + public function isDoublerInEvent(Event|int $event): bool + { + $eventId = $event instanceof Event ? $event->id : $event; + + return DoublerEntryCount::where([ + 'event_id' => $eventId, + 'student_id' => $this->id, + ])->exists(); + } } diff --git a/database/migrations/2025_06_14_142507_doubler_entry_counts.php b/database/migrations/2025_06_14_142507_doubler_entry_counts.php new file mode 100644 index 0000000..886aa51 --- /dev/null +++ b/database/migrations/2025_06_14_142507_doubler_entry_counts.php @@ -0,0 +1,35 @@ + 1 + '); + + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + // + } +};