- Crowd Types + Persons CRUD (73 tests) - Festival Sections + Time Slots + Shifts CRUD met assign/claim flow (84 tests) - Invite Flow + Member Management met InvitationService (109 tests) - Schema v1.6 migraties volledig uitgevoerd - DevSeeder bijgewerkt met crowd types voor testorganisatie
82 lines
1.7 KiB
PHP
82 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Concerns\HasUlids;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
final class UserInvitation extends Model
|
|
{
|
|
use HasFactory;
|
|
use HasUlids;
|
|
|
|
protected $fillable = [
|
|
'email',
|
|
'invited_by_user_id',
|
|
'organisation_id',
|
|
'event_id',
|
|
'role',
|
|
'token',
|
|
'status',
|
|
'expires_at',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'expires_at' => 'datetime',
|
|
];
|
|
}
|
|
|
|
public function invitedBy(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'invited_by_user_id');
|
|
}
|
|
|
|
public function organisation(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Organisation::class);
|
|
}
|
|
|
|
public function event(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Event::class);
|
|
}
|
|
|
|
public function isExpired(): bool
|
|
{
|
|
return $this->expires_at->isPast();
|
|
}
|
|
|
|
public function isPending(): bool
|
|
{
|
|
return $this->status === 'pending';
|
|
}
|
|
|
|
public function markAsAccepted(): void
|
|
{
|
|
$this->update(['status' => 'accepted']);
|
|
}
|
|
|
|
public function markAsExpired(): void
|
|
{
|
|
$this->update(['status' => 'expired']);
|
|
}
|
|
|
|
public function scopePending(Builder $query): Builder
|
|
{
|
|
return $query->where('status', 'pending');
|
|
}
|
|
|
|
public function scopeExpired(Builder $query): Builder
|
|
{
|
|
return $query->where('status', 'expired')
|
|
->orWhere(fn (Builder $q) => $q->where('status', 'pending')->where('expires_at', '<', now()));
|
|
}
|
|
}
|