diff --git a/app/Enums/AuditionFlags.php b/app/Enums/AuditionFlags.php new file mode 100644 index 0000000..fa156a1 --- /dev/null +++ b/app/Enums/AuditionFlags.php @@ -0,0 +1,10 @@ +with('error', 'Cannot enter a no-show for an entry in an audition where seats are published'); } - if ($entry->audition->hasFlag('advance_published')) { + if ($entry->audition->hasFlag('advancement_published')) { return to_route('entry-flags.noShowSelect')->with('error', 'Cannot enter a no-show for an entry in an audition where advancement is published'); } @@ -71,7 +71,7 @@ class EntryFlagController extends Controller return to_route('entry-flags.noShowSelect')->with('error', 'Cannot enter a no-show for an entry in an audition where seats are published'); } - if ($entry->audition->hasFlag('advance_published')) { + if ($entry->audition->hasFlag('advancement_published')) { return to_route('entry-flags.noShowSelect')->with('error', 'Cannot enter a no-show for an entry in an audition where advancement is published'); } @@ -90,7 +90,7 @@ class EntryFlagController extends Controller return to_route('entry-flags.noShowSelect')->with('error', 'Cannot undo a no-show for an entry in an audition where seats are published'); } - if ($entry->audition->hasFlag('advance_published')) { + if ($entry->audition->hasFlag('advancement_published')) { return to_route('entry-flags.noShowSelect')->with('error', 'Cannot undo a no-show for an entry in an audition where advancement is published'); } diff --git a/app/Http/Controllers/Tabulation/ScoreController.php b/app/Http/Controllers/Tabulation/ScoreController.php index 5f2fe69..217801a 100644 --- a/app/Http/Controllers/Tabulation/ScoreController.php +++ b/app/Http/Controllers/Tabulation/ScoreController.php @@ -4,9 +4,9 @@ namespace App\Http\Controllers\Tabulation; use App\Http\Controllers\Controller; use App\Models\Entry; -use App\Models\ScoreSheet; use Illuminate\Http\Request; use Illuminate\Support\Facades\Session; +use Tests\Feature\Models\ScoreSheet; class ScoreController extends Controller { diff --git a/app/Models/Audition.php b/app/Models/Audition.php index d33b721..658fec1 100644 --- a/app/Models/Audition.php +++ b/app/Models/Audition.php @@ -2,6 +2,7 @@ namespace App\Models; +use App\Enums\AuditionFlags; use Carbon\Carbon; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Factories\HasFactory; @@ -10,6 +11,8 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasMany; +use function in_array; + class Audition extends Model { use HasFactory; @@ -75,8 +78,13 @@ class Audition extends Model public function hasFlag($flag): bool { + $flags = []; + foreach ($this->flags as $checkFlag) { + $flags[] = $checkFlag->flag_name->value; + } + // return true if any flag in $this->flags has a flag_name of declined without making another db query if flags are loaded - return $this->flags->contains('flag_name', $flag); + return in_array($flag, $flags); } public function addFlag($flag): void @@ -84,8 +92,12 @@ class Audition extends Model if ($this->hasFlag($flag)) { return; } - - $this->flags()->create(['flag_name' => $flag]); + $enum = match ($flag) { + 'drawn' => AuditionFlags::DRAWN, + 'seats_published' => AuditionFlags::SEATS_PUBLISHED, + 'advancement_published' => AuditionFlags::ADVANCEMENT_PUBLISHED, + }; + $this->flags()->create(['flag_name' => $enum]); $this->load('flags'); } diff --git a/app/Models/AuditionFlag.php b/app/Models/AuditionFlag.php index 7b11fba..26429a6 100644 --- a/app/Models/AuditionFlag.php +++ b/app/Models/AuditionFlag.php @@ -2,7 +2,7 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Factories\HasFactory; +use App\Enums\AuditionFlags; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; @@ -10,6 +10,10 @@ class AuditionFlag extends Model { protected $guarded = []; + protected $casts = [ + 'flag_name' => AuditionFlags::class, + ]; + public function audition(): BelongsTo { return $this->belongsTo(Audition::class); diff --git a/app/Models/Entry.php b/app/Models/Entry.php index 9b08f7e..0a4c608 100644 --- a/app/Models/Entry.php +++ b/app/Models/Entry.php @@ -9,6 +9,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\Relations\HasOneThrough; +use Tests\Feature\Models\ScoreSheet; class Entry extends Model { diff --git a/app/Models/User.php b/app/Models/User.php index 361da51..c3ec38b 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -11,6 +11,7 @@ use Illuminate\Database\Eloquent\Relations\HasManyThrough; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Illuminate\Support\Collection; +use Tests\Feature\Models\ScoreSheet; class User extends Authenticatable implements MustVerifyEmail { diff --git a/app/Observers/ScoreSheetObserver.php b/app/Observers/ScoreSheetObserver.php index 533763e..3b31bc2 100644 --- a/app/Observers/ScoreSheetObserver.php +++ b/app/Observers/ScoreSheetObserver.php @@ -3,7 +3,7 @@ namespace App\Observers; use App\Events\ScoreSheetChange; -use App\Models\ScoreSheet; +use Tests\Feature\Models\ScoreSheet; class ScoreSheetObserver { diff --git a/app/Policies/ScoreSheetPolicy.php b/app/Policies/ScoreSheetPolicy.php index c83ebdd..2a897b8 100644 --- a/app/Policies/ScoreSheetPolicy.php +++ b/app/Policies/ScoreSheetPolicy.php @@ -3,9 +3,8 @@ namespace App\Policies; use App\Models\Entry; -use App\Models\ScoreSheet; use App\Models\User; -use Illuminate\Auth\Access\Response; +use Tests\Feature\Models\ScoreSheet; class ScoreSheetPolicy { diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 6d1eea9..62097a7 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -17,7 +17,6 @@ use App\Models\Entry; use App\Models\Room; use App\Models\RoomUser; use App\Models\School; -use App\Models\ScoreSheet; use App\Models\ScoringGuide; use App\Models\SeatingLimit; use App\Models\Student; @@ -43,6 +42,7 @@ use App\Services\SeatingService; use App\Services\TabulationService; use Illuminate\Support\Facades\Event; use Illuminate\Support\ServiceProvider; +use Tests\Feature\Models\ScoreSheet; class AppServiceProvider extends ServiceProvider diff --git a/app/Services/ScoreService.php b/app/Services/ScoreService.php index c7db47c..106a477 100644 --- a/app/Services/ScoreService.php +++ b/app/Services/ScoreService.php @@ -3,12 +3,11 @@ namespace App\Services; use App\Models\Entry; -use App\Models\ScoreSheet; use App\Models\ScoringGuide; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\DB; - +use Tests\Feature\Models\ScoreSheet; use function array_unshift; class ScoreService diff --git a/database/seeders/ScoreAllAuditions.php b/database/seeders/ScoreAllAuditions.php index 9a9f569..35e10b5 100644 --- a/database/seeders/ScoreAllAuditions.php +++ b/database/seeders/ScoreAllAuditions.php @@ -2,9 +2,9 @@ namespace Database\Seeders; -use App\Models\ScoreSheet; use App\Models\User; use Illuminate\Database\Seeder; +use Tests\Feature\Models\ScoreSheet; class ScoreAllAuditions extends Seeder { diff --git a/resources/views/components/layout/navbar/menus/tabulation.blade.php b/resources/views/components/layout/navbar/menus/tabulation.blade.php index 10617d7..48e8507 100644 --- a/resources/views/components/layout/navbar/menus/tabulation.blade.php +++ b/resources/views/components/layout/navbar/menus/tabulation.blade.php @@ -21,6 +21,7 @@