Last touches on Audition model

This commit is contained in:
Matt Young 2024-06-30 21:45:49 -05:00
parent 1b67fbdfeb
commit 0c6c098edf
5 changed files with 79 additions and 43 deletions

View File

@ -19,7 +19,7 @@ class EntryController extends Controller
$entries = $entries->sortBy(function ($entry) { $entries = $entries->sortBy(function ($entry) {
return $entry->student->last_name.$entry->student->first_name.$entry->audition->score_order; return $entry->student->last_name.$entry->student->first_name.$entry->audition->score_order;
}); });
$auditions = Audition::deadlineNotPast(); $auditions = Audition::open()->get();
$students = Auth::user()->students; $students = Auth::user()->students;
return view('entries.index', ['entries' => $entries, 'students' => $students, 'auditions' => $auditions]); return view('entries.index', ['entries' => $entries, 'students' => $students, 'auditions' => $auditions]);

View File

@ -26,10 +26,6 @@ class Audition extends Model
protected $scored_entries_count; //Set by TabulationService protected $scored_entries_count; //Set by TabulationService
public static function deadlineNotPast()
{
return Audition::where('entry_deadline', '>=', now())->get();
}
public function event(): BelongsTo public function event(): BelongsTo
{ {
@ -51,7 +47,7 @@ class Audition extends Model
return $this->belongsTo(ScoringGuide::class); return $this->belongsTo(ScoringGuide::class);
} }
public function dislpay_fee(): string public function display_fee(): string
{ {
return '$'.number_format($this->entry_fee / 100, 2); 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 public function judges(): array|BelongsToMany
{ {
@ -201,4 +197,20 @@ class Audition extends Model
{ {
$query->where('for_advancement', 1); $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');
});
}
} }

View File

@ -17,9 +17,7 @@ class EventFactory extends Factory
public function definition(): array public function definition(): array
{ {
return [ return [
'name' => $this->faker->randomElement([ 'name' => $this->faker->name(),
'Concert Auditions', 'Jazz Auditions ',
]).$this->faker->randomNumber(1),
]; ];
} }
} }

View File

@ -25,40 +25,41 @@
</tr> </tr>
</thead> </thead>
<div x-data="sortableList()" x-init="init"> <div x-data="sortableList()" x-init="init">
<x-table.body id="sortable-list"> <x-table.body id="sortable-list">
@foreach($auditions as $audition) @foreach($auditions as $audition)
<tr data-id="{{ $audition->id }}" @dblclick="window.location.href='/admin/auditions/{{ $audition->id }}/edit'"> <tr data-id="{{ $audition->id }}"
<x-table.td>{{ $audition->event->name }}</x-table.td> @dblclick="window.location.href='/admin/auditions/{{ $audition->id }}/edit'">
<x-table.td>{{ $audition->name }}</x-table.td> <x-table.td>{{ $audition->event->name }}</x-table.td>
<x-table.td>{{ $audition->entry_deadline }}</x-table.td> <x-table.td>{{ $audition->name }}</x-table.td>
<x-table.td>{{ $audition->dislpay_fee() }}</x-table.td> <x-table.td>{{ $audition->entry_deadline }}</x-table.td>
<x-table.td>{{ $audition->minimum_grade }} - {{ $audition->maximum_grade }}</x-table.td> <x-table.td>{{ $audition->display_fee() }}</x-table.td>
@if(auditionSetting('advanceTo')) <x-table.td>{{ $audition->minimum_grade }} - {{ $audition->maximum_grade }}</x-table.td>
<x-table.td> @if(auditionSetting('advanceTo'))
@if($audition->for_seating) <x-table.td>
<x-icons.checkmark color="green" /> @if($audition->for_seating)
@else <x-icons.checkmark color="green"/>
<x-icons.circle-slash-no color="red" /> @else
@endif <x-icons.circle-slash-no color="red"/>
</x-table.td> @endif
<x-table.td> </x-table.td>
@if($audition->for_advancement) <x-table.td>
<x-icons.checkmark color="green" /> @if($audition->for_advancement)
@else <x-icons.checkmark color="green"/>
<x-icons.circle-slash-no color="red" /> @else
@endif <x-icons.circle-slash-no color="red"/>
</x-table.td> @endif
@endif </x-table.td>
<x-table.td>{{ $audition->entries->count() }}</x-table.td> @endif
</tr> <x-table.td>{{ $audition->entries->count() }}</x-table.td>
@endforeach </tr>
</x-table.body> @endforeach
</x-table.body>
</div> </div>
</x-table.table> </x-table.table>
</x-card.card> </x-card.card>
<div class="mt-3 mx-3"> <div class="mt-3 mx-3">
{{-- {{ $auditions->links('vendor.pagination.simple-audition') }}--}} {{-- {{ $auditions->links('vendor.pagination.simple-audition') }}--}}
</div> </div>
<script> <script>
@ -75,13 +76,12 @@
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'X-CSRF-TOKEN': '{{ csrf_token() }}' 'X-CSRF-TOKEN': '{{ csrf_token() }}'
}, },
body: JSON.stringify({ order }) body: JSON.stringify({order})
}).then(response => response.json()) }).then(response => response.json())
.then(data => { .then(data => {
if (data.status === 'success') { if (data.status === 'success') {
console.log('Order updated successfully'); console.log('Order updated successfully');
} } else {
else {
console.log(data.status); console.log(data.status);
} }
}); });

View File

@ -8,7 +8,7 @@ uses(RefreshDatabase::class);
test('only returns open auditions for open scope', function () { test('only returns open auditions for open scope', function () {
// Arrange // Arrange
$openAudition = Audition::factory()->create(); $openAudition = Audition::factory()->create();
$closedAudition = Audition::factory()->closed()->create(); Audition::factory()->closed()->create();
// Act & Assert // Act & Assert
expect(Audition::open()->get()) expect(Audition::open()->get())
@ -37,3 +37,29 @@ it('only returns auditions for advancement with for forAdvancement scope', funct
->toHaveCount(1) ->toHaveCount(1)
->first()->id->toEqual($advancementAudition->id); ->first()->id->toEqual($advancementAudition->id);
}); });
it('only returns published auditions for seatsPublished scope', function () {
// Arrange
Audition::factory()->create();
$published = Audition::factory()->create();
$published->addFlag('seats_published');
// Act & Assert
expect(Audition::seatsPublished()->get())
->toHaveCount(1)
->first()->id->toEqual($published->id);
});
it('only returns published advancement auditions for advancementPublished scope', function () {
// Arrange
Audition::factory()->create();
$published = Audition::factory()->create();
$published->addFlag('advancement_published');
// Act & Assert
expect(Audition::advancementPublished()->get())
->toHaveCount(1)
->first()->id->toEqual($published->id);
});