Add scopes to models #10
|
|
@ -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]);
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,40 +25,41 @@
|
|||
</tr>
|
||||
</thead>
|
||||
<div x-data="sortableList()" x-init="init">
|
||||
<x-table.body id="sortable-list">
|
||||
@foreach($auditions as $audition)
|
||||
<tr data-id="{{ $audition->id }}" @dblclick="window.location.href='/admin/auditions/{{ $audition->id }}/edit'">
|
||||
<x-table.td>{{ $audition->event->name }}</x-table.td>
|
||||
<x-table.td>{{ $audition->name }}</x-table.td>
|
||||
<x-table.td>{{ $audition->entry_deadline }}</x-table.td>
|
||||
<x-table.td>{{ $audition->dislpay_fee() }}</x-table.td>
|
||||
<x-table.td>{{ $audition->minimum_grade }} - {{ $audition->maximum_grade }}</x-table.td>
|
||||
@if(auditionSetting('advanceTo'))
|
||||
<x-table.td>
|
||||
@if($audition->for_seating)
|
||||
<x-icons.checkmark color="green" />
|
||||
@else
|
||||
<x-icons.circle-slash-no color="red" />
|
||||
@endif
|
||||
</x-table.td>
|
||||
<x-table.td>
|
||||
@if($audition->for_advancement)
|
||||
<x-icons.checkmark color="green" />
|
||||
@else
|
||||
<x-icons.circle-slash-no color="red" />
|
||||
@endif
|
||||
</x-table.td>
|
||||
@endif
|
||||
<x-table.td>{{ $audition->entries->count() }}</x-table.td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</x-table.body>
|
||||
<x-table.body id="sortable-list">
|
||||
@foreach($auditions as $audition)
|
||||
<tr data-id="{{ $audition->id }}"
|
||||
@dblclick="window.location.href='/admin/auditions/{{ $audition->id }}/edit'">
|
||||
<x-table.td>{{ $audition->event->name }}</x-table.td>
|
||||
<x-table.td>{{ $audition->name }}</x-table.td>
|
||||
<x-table.td>{{ $audition->entry_deadline }}</x-table.td>
|
||||
<x-table.td>{{ $audition->display_fee() }}</x-table.td>
|
||||
<x-table.td>{{ $audition->minimum_grade }} - {{ $audition->maximum_grade }}</x-table.td>
|
||||
@if(auditionSetting('advanceTo'))
|
||||
<x-table.td>
|
||||
@if($audition->for_seating)
|
||||
<x-icons.checkmark color="green"/>
|
||||
@else
|
||||
<x-icons.circle-slash-no color="red"/>
|
||||
@endif
|
||||
</x-table.td>
|
||||
<x-table.td>
|
||||
@if($audition->for_advancement)
|
||||
<x-icons.checkmark color="green"/>
|
||||
@else
|
||||
<x-icons.circle-slash-no color="red"/>
|
||||
@endif
|
||||
</x-table.td>
|
||||
@endif
|
||||
<x-table.td>{{ $audition->entries->count() }}</x-table.td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</x-table.body>
|
||||
</div>
|
||||
</x-table.table>
|
||||
|
||||
</x-card.card>
|
||||
<div class="mt-3 mx-3">
|
||||
{{-- {{ $auditions->links('vendor.pagination.simple-audition') }}--}}
|
||||
{{-- {{ $auditions->links('vendor.pagination.simple-audition') }}--}}
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
|
@ -75,13 +76,12 @@
|
|||
'Content-Type': 'application/json',
|
||||
'X-CSRF-TOKEN': '{{ csrf_token() }}'
|
||||
},
|
||||
body: JSON.stringify({ order })
|
||||
body: JSON.stringify({order})
|
||||
}).then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.status === 'success') {
|
||||
console.log('Order updated successfully');
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
console.log(data.status);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ uses(RefreshDatabase::class);
|
|||
test('only returns open auditions for open scope', function () {
|
||||
// Arrange
|
||||
$openAudition = Audition::factory()->create();
|
||||
$closedAudition = Audition::factory()->closed()->create();
|
||||
Audition::factory()->closed()->create();
|
||||
|
||||
// Act & Assert
|
||||
expect(Audition::open()->get())
|
||||
|
|
@ -37,3 +37,29 @@ it('only returns auditions for advancement with for forAdvancement scope', funct
|
|||
->toHaveCount(1)
|
||||
->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);
|
||||
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue