Add scopes to models #10
|
|
@ -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]);
|
||||||
|
|
|
||||||
|
|
@ -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');
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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),
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,11 +27,12 @@
|
||||||
<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 }}"
|
||||||
|
@dblclick="window.location.href='/admin/auditions/{{ $audition->id }}/edit'">
|
||||||
<x-table.td>{{ $audition->event->name }}</x-table.td>
|
<x-table.td>{{ $audition->event->name }}</x-table.td>
|
||||||
<x-table.td>{{ $audition->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->entry_deadline }}</x-table.td>
|
||||||
<x-table.td>{{ $audition->dislpay_fee() }}</x-table.td>
|
<x-table.td>{{ $audition->display_fee() }}</x-table.td>
|
||||||
<x-table.td>{{ $audition->minimum_grade }} - {{ $audition->maximum_grade }}</x-table.td>
|
<x-table.td>{{ $audition->minimum_grade }} - {{ $audition->maximum_grade }}</x-table.td>
|
||||||
@if(auditionSetting('advanceTo'))
|
@if(auditionSetting('advanceTo'))
|
||||||
<x-table.td>
|
<x-table.td>
|
||||||
|
|
@ -80,8 +81,7 @@
|
||||||
.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);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue