Files
crewli/api/app/Models/RegistrationFieldTemplate.php
bert.hausmans 6a8d21a5b6 feat: registration field polish, multi-category tags, file uploads, Partner icon
- Restructure field editor dialog: move Options section to bottom with
  divider and subheader, fix delete button with flex layout
- Change tag_category (single string) to tag_categories (JSON array)
  supporting multiple category selection in tag picker fields
- Portal tag picker now groups tags by category with subheaders
- Add generic file upload endpoint (FileUploadService + UploadController)
- Replace email branding logo URL text field with ImageUploadField
- Update Partner crowd type default icon to tabler-affiliate
- Apply changes consistently to both field and template dialogs

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

100 lines
2.6 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Models;
use App\Enums\FieldDisplayWidth;
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;
final class RegistrationFieldTemplate extends Model
{
use HasFactory;
use HasUlids;
protected static function booted(): void
{
static::addGlobalScope(new OrganisationScope());
}
protected $fillable = [
'organisation_id',
'label',
'slug',
'field_type',
'options',
'tag_categories',
'is_required',
'is_filterable',
'is_portal_visible',
'is_admin_only',
'help_text',
'sort_order',
'display_width',
'is_system',
'is_active',
];
protected function casts(): array
{
return [
'field_type' => RegistrationFieldType::class,
'options' => 'array',
'tag_categories' => 'array',
'is_required' => 'boolean',
'is_filterable' => 'boolean',
'is_portal_visible' => 'boolean',
'is_admin_only' => 'boolean',
'sort_order' => 'integer',
'display_width' => FieldDisplayWidth::class,
'is_system' => 'boolean',
'is_active' => 'boolean',
];
}
/** @return array<int, array{label: string, description: string|null}>|null */
public function getNormalizedOptionsAttribute(): ?array
{
if ($this->options === null) {
return null;
}
return collect($this->options)->map(function (mixed $option): array {
if (is_string($option)) {
return ['label' => $option, 'description' => null];
}
return [
'label' => $option['label'] ?? (string) $option,
'description' => $option['description'] ?? null,
];
})->toArray();
}
public function organisation(): BelongsTo
{
return $this->belongsTo(Organisation::class);
}
public function scopeActive(Builder $query): Builder
{
return $query->where('is_active', true);
}
public function scopeSystem(Builder $query): Builder
{
return $query->where('is_system', true);
}
public function scopeOrdered(Builder $query): Builder
{
return $query->orderBy('sort_order');
}
}