From d5b5b2b84a9654068f05f009da9d209299b2e96d Mon Sep 17 00:00:00 2001 From: Matt Young Date: Sun, 30 Jun 2024 17:40:32 -0500 Subject: [PATCH 1/5] Add open scope to auditoins --- app/Models/Audition.php | 8 +++++- database/factories/AuditionFactory.php | 40 +++++++++++++++++++++++++- database/factories/EventFactory.php | 4 ++- resources/views/test.blade.php | 4 +-- tests/Feature/Models/AuditionTest.php | 17 +++++++++++ 5 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 tests/Feature/Models/AuditionTest.php diff --git a/app/Models/Audition.php b/app/Models/Audition.php index dfa3057..160f6db 100644 --- a/app/Models/Audition.php +++ b/app/Models/Audition.php @@ -2,6 +2,8 @@ namespace App\Models; +use Carbon\Carbon; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; @@ -24,7 +26,6 @@ class Audition extends Model protected $scored_entries_count; //Set by TabulationService - public static function deadlineNotPast() { return Audition::where('entry_deadline', '>=', now())->get(); @@ -185,4 +186,9 @@ class Audition extends Model // remove related auditionFlag where flag_name = $flag $this->flags()->where('flag_name', $flag)->delete(); } + + public function scopeOpen(Builder $query): void + { + $query->where('entry_deadline', '>=', Carbon::now()); + } } diff --git a/database/factories/AuditionFactory.php b/database/factories/AuditionFactory.php index 3b52d27..4cefeff 100644 --- a/database/factories/AuditionFactory.php +++ b/database/factories/AuditionFactory.php @@ -2,6 +2,8 @@ namespace Database\Factories; +use App\Models\Event; +use Carbon\Carbon; use Illuminate\Database\Eloquent\Factories\Factory; /** @@ -16,8 +18,44 @@ class AuditionFactory extends Factory */ public function definition(): array { + $instruments = [ + 'Flute', + 'Oboe', + 'Clarinet', + 'Bass Clarinet', + 'Contra Clarinet', + 'Bassoon', + 'Alto Sax', + 'Tenor Sax', + 'Bari Sax', + 'Trumpet', + 'Horn', + 'Trombone', + 'Euphonium', + 'Tuba', + 'String Bass', + 'Percussion', + ]; + + $event = Event::factory()->create(); + return [ - // + 'event_id' => $event->id, + 'name' => $this->faker->randomElement($instruments).$this->faker->randomNumber(1), + 'score_order' => 1, + 'entry_deadline' => Carbon::tomorrow(), + 'entry_fee' => 1000, + 'minimum_grade' => 7, + 'maximum_grade' => 12, + 'for_seating' => 1, + 'for_advancement' => 1, ]; } + + public function closed(?Carbon $entryDeadline = null): self + { + return $this->state( + fn (array $attributes) => ['entry_deadline' => $entryDeadline ?? Carbon::yesterday()] + ); + } } diff --git a/database/factories/EventFactory.php b/database/factories/EventFactory.php index 19b0bf9..006a07b 100644 --- a/database/factories/EventFactory.php +++ b/database/factories/EventFactory.php @@ -17,7 +17,9 @@ class EventFactory extends Factory public function definition(): array { return [ - 'name' => 'Concert Band Auditions' + 'name' => $this->faker->randomElement([ + 'Concert Auditions', 'Jazz Auditions ', + ]).$this->faker->randomNumber(1), ]; } } diff --git a/resources/views/test.blade.php b/resources/views/test.blade.php index ddd5fa6..88a3835 100644 --- a/resources/views/test.blade.php +++ b/resources/views/test.blade.php @@ -16,9 +16,7 @@ Test Page @php - dump($totalFees); - dump($lines); - + dump(Audition::open()->get()); @endphp diff --git a/tests/Feature/Models/AuditionTest.php b/tests/Feature/Models/AuditionTest.php new file mode 100644 index 0000000..901cd48 --- /dev/null +++ b/tests/Feature/Models/AuditionTest.php @@ -0,0 +1,17 @@ +create(); + $closedAudition = Audition::factory()->closed()->create(); + + // Act & Assert + expect(Audition::open()->get()) + ->toHaveCount(1) + ->first()->id->toEqual($openAudition->id); +}); From 1b67fbdfebe9a919c61593ed3496be4359c57423 Mon Sep 17 00:00:00 2001 From: Matt Young Date: Sun, 30 Jun 2024 18:17:51 -0500 Subject: [PATCH 2/5] Add forSeating and forAdvancement scope to Audition --- app/Models/Audition.php | 10 ++++++++++ tests/Feature/Models/AuditionTest.php | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/app/Models/Audition.php b/app/Models/Audition.php index 160f6db..836109a 100644 --- a/app/Models/Audition.php +++ b/app/Models/Audition.php @@ -191,4 +191,14 @@ class Audition extends Model { $query->where('entry_deadline', '>=', Carbon::now()); } + + public function scopeForSeating(Builder $query): void + { + $query->where('for_seating', 1); + } + + public function scopeForAdvancement(Builder $query): void + { + $query->where('for_advancement', 1); + } } diff --git a/tests/Feature/Models/AuditionTest.php b/tests/Feature/Models/AuditionTest.php index 901cd48..8f28d9c 100644 --- a/tests/Feature/Models/AuditionTest.php +++ b/tests/Feature/Models/AuditionTest.php @@ -15,3 +15,25 @@ test('only returns open auditions for open scope', function () { ->toHaveCount(1) ->first()->id->toEqual($openAudition->id); }); + +it('only returns auditions for seating with forSeating scope', function () { + // Arrange + Audition::factory(['for_seating' => 0])->create(); + $seatingAudition = Audition::factory()->create(); + + // Act & Assert + expect(Audition::forSeating()->get()) + ->toHaveCount(1) + ->first()->id->toEqual($seatingAudition->id); +}); + +it('only returns auditions for advancement with for forAdvancement scope', function () { + // Arrange + Audition::factory(['for_advancement' => 0])->create(); + $advancementAudition = Audition::factory()->create(); + + // Act & Assert + expect(Audition::forAdvancement()->get()) + ->toHaveCount(1) + ->first()->id->toEqual($advancementAudition->id); +}); From 0c6c098edf63dd269b59107c5ba2ef5e477eb06a Mon Sep 17 00:00:00 2001 From: Matt Young Date: Sun, 30 Jun 2024 21:45:49 -0500 Subject: [PATCH 3/5] Last touches on Audition model --- app/Http/Controllers/EntryController.php | 2 +- app/Models/Audition.php | 24 +++++-- database/factories/EventFactory.php | 4 +- .../views/admin/auditions/index.blade.php | 64 +++++++++---------- tests/Feature/Models/AuditionTest.php | 28 +++++++- 5 files changed, 79 insertions(+), 43 deletions(-) diff --git a/app/Http/Controllers/EntryController.php b/app/Http/Controllers/EntryController.php index 9243145..6c16d8f 100644 --- a/app/Http/Controllers/EntryController.php +++ b/app/Http/Controllers/EntryController.php @@ -19,7 +19,7 @@ class EntryController extends Controller $entries = $entries->sortBy(function ($entry) { return $entry->student->last_name.$entry->student->first_name.$entry->audition->score_order; }); - $auditions = Audition::deadlineNotPast(); + $auditions = Audition::open()->get(); $students = Auth::user()->students; return view('entries.index', ['entries' => $entries, 'students' => $students, 'auditions' => $auditions]); diff --git a/app/Models/Audition.php b/app/Models/Audition.php index 836109a..66be60c 100644 --- a/app/Models/Audition.php +++ b/app/Models/Audition.php @@ -26,10 +26,6 @@ class Audition extends Model protected $scored_entries_count; //Set by TabulationService - public static function deadlineNotPast() - { - return Audition::where('entry_deadline', '>=', now())->get(); - } public function event(): BelongsTo { @@ -51,7 +47,7 @@ class Audition extends Model return $this->belongsTo(ScoringGuide::class); } - public function dislpay_fee(): string + public function display_fee(): string { return '$'.number_format($this->entry_fee / 100, 2); } @@ -135,7 +131,7 @@ class Audition extends Model } /** - * @return BelongsToMany|\App\Models\User[] + * @return BelongsToMany|User[] */ public function judges(): array|BelongsToMany { @@ -201,4 +197,20 @@ class Audition extends Model { $query->where('for_advancement', 1); } + + public function scopeSeatsPublished(Builder $query): Builder + { + return $query->whereHas('flags', function (Builder $query) { + $query->where('flag_name', 'seats_published'); + }); + + } + + public function scopeAdvancementPublished(Builder $query): Builder + { + return $query->whereHas('flags', function (Builder $query) { + $query->where('flag_name', 'advancement_published'); + }); + + } } diff --git a/database/factories/EventFactory.php b/database/factories/EventFactory.php index 006a07b..ae4a7c9 100644 --- a/database/factories/EventFactory.php +++ b/database/factories/EventFactory.php @@ -17,9 +17,7 @@ class EventFactory extends Factory public function definition(): array { return [ - 'name' => $this->faker->randomElement([ - 'Concert Auditions', 'Jazz Auditions ', - ]).$this->faker->randomNumber(1), + 'name' => $this->faker->name(), ]; } } diff --git a/resources/views/admin/auditions/index.blade.php b/resources/views/admin/auditions/index.blade.php index 4f84350..527d197 100644 --- a/resources/views/admin/auditions/index.blade.php +++ b/resources/views/admin/auditions/index.blade.php @@ -25,40 +25,41 @@
- - @foreach($auditions as $audition) - - {{ $audition->event->name }} - {{ $audition->name }} - {{ $audition->entry_deadline }} - {{ $audition->dislpay_fee() }} - {{ $audition->minimum_grade }} - {{ $audition->maximum_grade }} - @if(auditionSetting('advanceTo')) - - @if($audition->for_seating) - - @else - - @endif - - - @if($audition->for_advancement) - - @else - - @endif - - @endif - {{ $audition->entries->count() }} - - @endforeach - + + @foreach($auditions as $audition) + + {{ $audition->event->name }} + {{ $audition->name }} + {{ $audition->entry_deadline }} + {{ $audition->display_fee() }} + {{ $audition->minimum_grade }} - {{ $audition->maximum_grade }} + @if(auditionSetting('advanceTo')) + + @if($audition->for_seating) + + @else + + @endif + + + @if($audition->for_advancement) + + @else + + @endif + + @endif + {{ $audition->entries->count() }} + + @endforeach +
-{{-- {{ $auditions->links('vendor.pagination.simple-audition') }}--}} + {{-- {{ $auditions->links('vendor.pagination.simple-audition') }}--}}