feat: registration section preferences with show_in_registration filtering and deduplication
Add show_in_registration and registration_description columns to festival_sections. Registration form now shows deduplicated sections by name (across sub-events), filtered by show_in_registration=true, grouped by category with card-based UI. Section preferences use section_name instead of section_id. Add GET/PUT registration-settings endpoints for festival-level bulk management. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,7 @@ use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Api\V1\ReorderFestivalSectionsRequest;
|
||||
use App\Http\Requests\Api\V1\StoreFestivalSectionRequest;
|
||||
use App\Http\Requests\Api\V1\UpdateFestivalSectionRequest;
|
||||
use App\Http\Requests\Api\V1\UpdateRegistrationSettingsRequest;
|
||||
use App\Http\Resources\Api\V1\FestivalSectionResource;
|
||||
use App\Models\Event;
|
||||
use App\Models\FestivalSection;
|
||||
@@ -94,6 +95,82 @@ final class FestivalSectionController extends Controller
|
||||
return response()->json(null, 204);
|
||||
}
|
||||
|
||||
public function registrationSettings(Event $event): JsonResponse
|
||||
{
|
||||
Gate::authorize('viewAny', [FestivalSection::class, $event]);
|
||||
|
||||
$sections = $this->getFestivalSections($event);
|
||||
|
||||
$grouped = $sections->groupBy('name')->map(function ($group) {
|
||||
$first = $group->first();
|
||||
|
||||
return [
|
||||
'name' => $first->name,
|
||||
'category' => $first->category,
|
||||
'icon' => $first->icon,
|
||||
'show_in_registration' => $group->contains('show_in_registration', true),
|
||||
'registration_description' => $group->whereNotNull('registration_description')->first()?->registration_description,
|
||||
'section_count' => $group->count(),
|
||||
'section_ids' => $group->pluck('id')->values()->toArray(),
|
||||
];
|
||||
})->values();
|
||||
|
||||
return response()->json(['data' => $grouped]);
|
||||
}
|
||||
|
||||
public function updateRegistrationSettings(UpdateRegistrationSettingsRequest $request, Event $event): JsonResponse
|
||||
{
|
||||
Gate::authorize('create', [FestivalSection::class, $event]);
|
||||
|
||||
$validated = $request->validated();
|
||||
$sections = $this->getFestivalSections($event);
|
||||
|
||||
$matching = $sections->where('name', $validated['name']);
|
||||
|
||||
if ($matching->isEmpty()) {
|
||||
return $this->error('Sectie niet gevonden.', 404);
|
||||
}
|
||||
|
||||
FestivalSection::whereIn('id', $matching->pluck('id'))
|
||||
->update([
|
||||
'show_in_registration' => $validated['show_in_registration'],
|
||||
'registration_description' => $validated['registration_description'],
|
||||
]);
|
||||
|
||||
activity('section_management')
|
||||
->performedOn($event)
|
||||
->causedBy(auth()->user())
|
||||
->withProperties([
|
||||
'section_name' => $validated['name'],
|
||||
'show_in_registration' => $validated['show_in_registration'],
|
||||
'sections_updated' => $matching->count(),
|
||||
])
|
||||
->log('section.registration_settings_updated');
|
||||
|
||||
// Return updated settings
|
||||
return $this->registrationSettings($event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all sections across the festival context (parent + children).
|
||||
*/
|
||||
private function getFestivalSections(Event $event): \Illuminate\Support\Collection
|
||||
{
|
||||
$eventIds = collect([$event->id]);
|
||||
|
||||
if ($event->isSubEvent()) {
|
||||
$parentId = $event->parent_event_id;
|
||||
$eventIds = Event::where('parent_event_id', $parentId)
|
||||
->orWhere('id', $parentId)
|
||||
->pluck('id');
|
||||
} elseif ($event->hasChildren()) {
|
||||
$childIds = $event->children()->pluck('id');
|
||||
$eventIds = $childIds->push($event->id);
|
||||
}
|
||||
|
||||
return FestivalSection::whereIn('event_id', $eventIds)->ordered()->get();
|
||||
}
|
||||
|
||||
public function reorder(ReorderFestivalSectionsRequest $request, Event $event): JsonResponse
|
||||
{
|
||||
Gate::authorize('reorder', [FestivalSection::class, $event]);
|
||||
|
||||
@@ -24,26 +24,30 @@ final class PublicRegistrationDataController extends Controller
|
||||
|
||||
$festivalEvent = $event->isSubEvent() ? $event->parent : $event;
|
||||
|
||||
$sectionQuery = FestivalSection::where('event_id', $festivalEvent->id)
|
||||
->where(function ($query) {
|
||||
$query->where('type', '!=', 'cross_event')
|
||||
->orWhereNull('type');
|
||||
})
|
||||
->ordered();
|
||||
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');
|
||||
|
||||
if ($festivalEvent->isFestival()) {
|
||||
$childIds = $festivalEvent->children()->pluck('id');
|
||||
$sectionQuery->orWhere(function ($query) use ($childIds) {
|
||||
$query->whereIn('event_id', $childIds)
|
||||
->where(function ($q) {
|
||||
$q->where('type', '!=', 'cross_event')
|
||||
->orWhereNull('type');
|
||||
});
|
||||
});
|
||||
$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();
|
||||
}
|
||||
|
||||
$sections = $sectionQuery->get(['id', 'name', 'category', 'icon']);
|
||||
|
||||
$timeSlots = $festivalEvent->getAllRelevantTimeSlots()
|
||||
->where('person_type', 'VOLUNTEER')
|
||||
->values();
|
||||
@@ -62,6 +66,7 @@ final class PublicRegistrationDataController extends Controller
|
||||
'name' => $section->name,
|
||||
'category' => $section->category,
|
||||
'icon' => $section->icon,
|
||||
'registration_description' => $section->registration_description,
|
||||
]),
|
||||
'time_slots' => $timeSlots->map(fn (TimeSlot $slot) => [
|
||||
'id' => $slot->id,
|
||||
|
||||
@@ -31,6 +31,8 @@ final class StoreFestivalSectionRequest extends FormRequest
|
||||
'crew_accreditation_level' => ['nullable', 'string', 'max:50'],
|
||||
'public_form_accreditation_level' => ['nullable', 'string', 'max:50'],
|
||||
'timed_accreditations' => ['nullable', 'boolean'],
|
||||
'show_in_registration' => ['nullable', 'boolean'],
|
||||
'registration_description' => ['nullable', 'string', 'max:500'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,8 @@ final class UpdateFestivalSectionRequest extends FormRequest
|
||||
'timed_accreditations' => ['sometimes', 'boolean'],
|
||||
'crew_accreditation_level' => ['nullable', 'string', 'max:50'],
|
||||
'public_form_accreditation_level' => ['nullable', 'string', 'max:50'],
|
||||
'show_in_registration' => ['sometimes', 'boolean'],
|
||||
'registration_description' => ['sometimes', 'nullable', 'string', 'max:500'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Requests\Api\V1;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
final class UpdateRegistrationSettingsRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'show_in_registration' => ['required', 'boolean'],
|
||||
'registration_description' => ['nullable', 'string', 'max:500'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Requests\Api\V1;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
final class VolunteerRegistrationRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$user = auth('sanctum')->user();
|
||||
|
||||
if ($user) {
|
||||
$this->merge([
|
||||
'name' => $user->name,
|
||||
'email' => $user->email,
|
||||
'_authenticated' => true,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => ['required_without:_authenticated', 'string', 'max:255'],
|
||||
'email' => ['required_without:_authenticated', 'email', 'max:255'],
|
||||
'phone' => ['nullable', 'string', 'max:50'],
|
||||
|
||||
'tshirt_size' => ['nullable', 'string', 'in:XS,S,M,L,XL,XXL,XXXL'],
|
||||
'first_aid' => ['nullable', 'boolean'],
|
||||
'allergies' => ['nullable', 'string', 'max:500'],
|
||||
'access_requirements' => ['nullable', 'string', 'max:500'],
|
||||
'driving_licence' => ['nullable', 'boolean'],
|
||||
|
||||
'motivation' => ['nullable', 'string', 'max:1000'],
|
||||
'motivation_other' => ['nullable', 'string', 'max:500'],
|
||||
|
||||
'section_preferences' => ['nullable', 'array', 'max:5'],
|
||||
'section_preferences.*.section_name' => ['required', 'string', 'max:255'],
|
||||
'section_preferences.*.priority' => ['required', 'integer', 'min:1', 'max:5'],
|
||||
|
||||
'availabilities' => ['nullable', 'array'],
|
||||
'availabilities.*.time_slot_id' => ['required', 'ulid', 'exists:time_slots,id'],
|
||||
'availabilities.*.preference_level' => ['nullable', 'integer', 'min:1', 'max:5'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,8 @@ final class FestivalSectionResource extends JsonResource
|
||||
'crew_accreditation_level' => $this->crew_accreditation_level,
|
||||
'public_form_accreditation_level' => $this->public_form_accreditation_level,
|
||||
'timed_accreditations' => $this->timed_accreditations,
|
||||
'show_in_registration' => $this->show_in_registration,
|
||||
'registration_description' => $this->registration_description,
|
||||
'created_at' => $this->created_at->toIso8601String(),
|
||||
'shifts_count' => $this->whenCounted('shifts'),
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user