Add configurable column widths (full/half) and optional descriptions for radio/select/checkbox options on registration form fields. - Migration adds display_width column to both tables - FieldDisplayWidth enum with smart defaults per field type - normalized_options accessor for backwards-compatible option format - Portal form renderer uses display_width for VRow/VCol grid layout - Radio/select/checkbox options render with descriptions - Admin field editor supports display_width toggle and description input - System templates updated with appropriate widths and descriptions Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
131 lines
5.5 KiB
PHP
131 lines
5.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\Api\V1;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Event;
|
|
use App\Models\FestivalSection;
|
|
use App\Models\PersonTag;
|
|
use App\Models\RegistrationFormField;
|
|
use App\Models\TimeSlot;
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
final class PublicRegistrationDataController extends Controller
|
|
{
|
|
public function __invoke(string $slug): JsonResponse
|
|
{
|
|
$event = Event::where('slug', $slug)
|
|
->where('status', 'registration_open')
|
|
->first();
|
|
|
|
if ($event === null) {
|
|
abort(404, 'Event not found or not accepting registrations.');
|
|
}
|
|
|
|
$festivalEvent = $event->isSubEvent() ? $event->parent : $event;
|
|
|
|
if ($festivalEvent->isFestival() || $festivalEvent->hasChildren()) {
|
|
// Festival: get child event sections only (skip parent operational sections)
|
|
$childIds = Event::where('parent_event_id', $festivalEvent->id)->pluck('id');
|
|
|
|
$sections = FestivalSection::whereIn('event_id', $childIds)
|
|
->where('show_in_registration', true)
|
|
->where('type', 'standard')
|
|
->select('id', 'name', 'category', 'icon', 'registration_description')
|
|
->orderBy('category')
|
|
->orderBy('sort_order')
|
|
->get()
|
|
->unique('name')
|
|
->values();
|
|
} else {
|
|
// Flat event: all sections of the event
|
|
$sections = FestivalSection::where('event_id', $festivalEvent->id)
|
|
->where('show_in_registration', true)
|
|
->where('type', 'standard')
|
|
->select('id', 'name', 'category', 'icon', 'registration_description')
|
|
->orderBy('category')
|
|
->orderBy('sort_order')
|
|
->get();
|
|
}
|
|
|
|
$timeSlots = $festivalEvent->getAllRelevantTimeSlots()
|
|
->where('person_type', 'VOLUNTEER')
|
|
->values();
|
|
|
|
$registrationFields = RegistrationFormField::where('event_id', $festivalEvent->id)
|
|
->portalVisible()
|
|
->ordered()
|
|
->get();
|
|
|
|
$organisationId = $festivalEvent->organisation_id;
|
|
|
|
return response()->json([
|
|
'data' => [
|
|
'event' => [
|
|
'id' => $festivalEvent->id,
|
|
'name' => $festivalEvent->name,
|
|
'start_date' => $festivalEvent->start_date->toDateString(),
|
|
'end_date' => $festivalEvent->end_date->toDateString(),
|
|
'organisation_id' => $organisationId,
|
|
'registration_banner_url' => $festivalEvent->registration_banner_url,
|
|
'registration_welcome_text' => $festivalEvent->registration_welcome_text,
|
|
'registration_logo_url' => $festivalEvent->registration_logo_url,
|
|
'registration_show_section_preferences' => (bool) $festivalEvent->registration_show_section_preferences,
|
|
'registration_show_availability' => (bool) $festivalEvent->registration_show_availability,
|
|
],
|
|
'sections' => $sections->map(fn (FestivalSection $section) => [
|
|
'id' => $section->id,
|
|
'name' => $section->name,
|
|
'category' => $section->category,
|
|
'icon' => $section->icon,
|
|
'registration_description' => $section->registration_description,
|
|
]),
|
|
'time_slots' => $timeSlots->map(fn (TimeSlot $slot) => [
|
|
'id' => $slot->id,
|
|
'name' => $slot->name,
|
|
'date' => $slot->date->toDateString(),
|
|
'start_time' => $slot->start_time,
|
|
'end_time' => $slot->end_time,
|
|
'duration_hours' => $slot->duration_hours,
|
|
]),
|
|
'registration_fields' => $registrationFields->map(function (RegistrationFormField $field) use ($organisationId) {
|
|
$data = [
|
|
'id' => $field->id,
|
|
'label' => $field->label,
|
|
'slug' => $field->slug,
|
|
'field_type' => $field->field_type->value,
|
|
'options' => $field->options,
|
|
'normalized_options' => $field->normalized_options,
|
|
'tag_category' => $field->tag_category,
|
|
'is_required' => $field->is_required,
|
|
'section' => $field->section,
|
|
'help_text' => $field->help_text,
|
|
'display_width' => $field->display_width->value,
|
|
];
|
|
|
|
if ($field->field_type === \App\Enums\RegistrationFieldType::TAG_PICKER) {
|
|
$query = PersonTag::where('organisation_id', $organisationId)
|
|
->where('is_active', true);
|
|
|
|
if ($field->tag_category) {
|
|
$query->where('category', $field->tag_category);
|
|
}
|
|
|
|
$data['available_tags'] = $query->orderBy('sort_order')
|
|
->get()
|
|
->map(fn (PersonTag $tag) => [
|
|
'id' => $tag->id,
|
|
'name' => $tag->name,
|
|
'category' => $tag->category,
|
|
]);
|
|
}
|
|
|
|
return $data;
|
|
}),
|
|
],
|
|
]);
|
|
}
|
|
}
|