Files
crewli/api/app/Models/Person.php
bert.hausmans f6e3568011 feat: registration form fields, section preferences, tag sync & schema updates
Implement EAV system for dynamic event-specific registration fields
with organisation-level templates, person section preferences with
priority ranking, and TagSyncService for deferred tag_picker sync.

New tables: registration_field_templates, registration_form_fields,
person_field_values, person_section_preferences.
New columns: persons.remarks, events.registration_show_section_preferences,
events.registration_show_availability.

58 tests, 126 assertions — all 432 tests pass (zero regressions).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 22:10:16 +02:00

134 lines
3.2 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Models;
use App\Enums\IdentityMatchStatus;
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;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\SoftDeletes;
final class Person extends Model
{
use HasFactory;
use HasUlids;
use SoftDeletes;
protected $table = 'persons';
protected $fillable = [
'user_id',
'event_id',
'crowd_type_id',
'company_id',
'first_name',
'last_name',
'date_of_birth',
'email',
'phone',
'status',
'is_blacklisted',
'admin_notes',
'remarks',
'custom_fields',
];
public function getFullNameAttribute(): string
{
return trim("{$this->first_name} {$this->last_name}");
}
public function getNameAttribute(): string
{
return $this->full_name;
}
protected function casts(): array
{
return [
'date_of_birth' => 'date',
'is_blacklisted' => 'boolean',
'custom_fields' => 'array',
];
}
public function event(): BelongsTo
{
return $this->belongsTo(Event::class);
}
public function crowdType(): BelongsTo
{
return $this->belongsTo(CrowdType::class);
}
public function company(): BelongsTo
{
return $this->belongsTo(Company::class);
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function crowdLists(): BelongsToMany
{
return $this->belongsToMany(CrowdList::class, 'crowd_list_persons')
->withPivot('added_at', 'added_by_user_id');
}
public function shiftAssignments(): HasMany
{
return $this->hasMany(ShiftAssignment::class);
}
public function volunteerAvailabilities(): HasMany
{
return $this->hasMany(VolunteerAvailability::class);
}
public function fieldValues(): HasMany
{
return $this->hasMany(PersonFieldValue::class);
}
public function sectionPreferences(): HasMany
{
return $this->hasMany(PersonSectionPreference::class);
}
public function identityMatches(): HasMany
{
return $this->hasMany(PersonIdentityMatch::class);
}
public function pendingIdentityMatch(): HasOne
{
return $this->hasOne(PersonIdentityMatch::class)
->where('status', IdentityMatchStatus::PENDING);
}
public function scopeApproved(Builder $query): Builder
{
return $query->where('status', 'approved');
}
public function scopePending(Builder $query): Builder
{
return $query->where('status', 'pending');
}
public function scopeForCrowdType(Builder $query, string $type): Builder
{
return $query->whereHas('crowdType', fn (Builder $q) => $q->where('system_type', $type));
}
}