83 lines
2.1 KiB
PHP
83 lines
2.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\RegistrationFieldType;
|
|
use App\Models\Scopes\OrganisationScope;
|
|
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\HasMany;
|
|
|
|
final class RegistrationFormField extends Model
|
|
{
|
|
use HasFactory;
|
|
use HasUlids;
|
|
|
|
/** @var string Used by OrganisationScope to determine filtering strategy */
|
|
public string $organisationScopeColumn = 'event_id';
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::addGlobalScope(new OrganisationScope());
|
|
}
|
|
|
|
protected $fillable = [
|
|
'event_id',
|
|
'label',
|
|
'slug',
|
|
'field_type',
|
|
'options',
|
|
'tag_category',
|
|
'is_required',
|
|
'is_portal_visible',
|
|
'is_admin_only',
|
|
'is_filterable',
|
|
'section',
|
|
'help_text',
|
|
'sort_order',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'field_type' => RegistrationFieldType::class,
|
|
'options' => 'array',
|
|
'is_required' => 'boolean',
|
|
'is_portal_visible' => 'boolean',
|
|
'is_admin_only' => 'boolean',
|
|
'is_filterable' => 'boolean',
|
|
'sort_order' => 'integer',
|
|
];
|
|
}
|
|
|
|
public function event(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Event::class);
|
|
}
|
|
|
|
public function personFieldValues(): HasMany
|
|
{
|
|
return $this->hasMany(PersonFieldValue::class, 'registration_form_field_id');
|
|
}
|
|
|
|
public function isMultiValue(): bool
|
|
{
|
|
return $this->field_type->isMultiValue();
|
|
}
|
|
|
|
public function scopeOrdered(Builder $query): Builder
|
|
{
|
|
return $query->orderBy('sort_order');
|
|
}
|
|
|
|
public function scopePortalVisible(Builder $query): Builder
|
|
{
|
|
return $query->where('is_portal_visible', true)->where('is_admin_only', false);
|
|
}
|
|
}
|