Auditionadmin 64 #71
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
enum UserFlags: string
|
||||||
|
{
|
||||||
|
case HEAD_DIRECTOR = 'head_director';
|
||||||
|
}
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Enums\UserFlags;
|
||||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
|
@ -158,6 +159,34 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||||
return $this->hasMany(ScoreSheet::class);
|
return $this->hasMany(ScoreSheet::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function flags(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(UserFlag::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function hasFlag($flag): bool
|
||||||
|
{
|
||||||
|
$flags = [];
|
||||||
|
foreach ($this->flags as $checkFlag) {
|
||||||
|
$flags[] = $checkFlag->flag_name->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return in_array($flag, $flags);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addFlag($flag): void
|
||||||
|
{
|
||||||
|
if ($this->hasFlag($flag)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$enum = match ($flag) {
|
||||||
|
'head_director' => UserFlags::HEAD_DIRECTOR,
|
||||||
|
};
|
||||||
|
$this->flags()->create(['flag_name' => $enum]);
|
||||||
|
$this->load('flags');
|
||||||
|
}
|
||||||
|
|
||||||
public function scoresForEntry($entry)
|
public function scoresForEntry($entry)
|
||||||
{
|
{
|
||||||
return $this->scoreSheets->where('entry_id', '=', $entry)->first()?->subscores;
|
return $this->scoreSheets->where('entry_id', '=', $entry)->first()?->subscores;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Enums\UserFlags;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
|
||||||
|
class UserFlag extends Model
|
||||||
|
{
|
||||||
|
protected $guarded = [];
|
||||||
|
|
||||||
|
protected $casts = [
|
||||||
|
'flag_name' => UserFlags::class,
|
||||||
|
];
|
||||||
|
|
||||||
|
public function user(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(User::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('user_flags', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignIdFor(User::class)->constrained()->cascadeOnUpdate()->cascadeOnDelete();
|
||||||
|
$table->string('flag_name');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('user_flags');
|
||||||
|
}
|
||||||
|
};
|
||||||
Loading…
Reference in New Issue