S2a: purge legacy Form Builder PHP code and routes

This commit is contained in:
2026-04-17 18:43:00 +02:00
parent cfc7610497
commit a3ca596362
55 changed files with 128 additions and 6057 deletions

View File

@@ -19,7 +19,6 @@ use App\Models\Person;
use App\Models\User;
use App\Services\EmailService;
use App\Services\PersonIdentityService;
use App\Services\TagSyncService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate;
@@ -34,7 +33,6 @@ final class PersonController extends Controller
public function __construct(
private readonly PersonIdentityService $identityService,
private readonly TagSyncService $tagSyncService,
private readonly EmailService $emailService,
) {}
@@ -188,8 +186,6 @@ final class PersonController extends Controller
$person->save();
}
$this->tagSyncService->syncFromRegistration($person);
if ($person->email) {
$portalUrl = config('app.frontend_portal_url');

View File

@@ -1,48 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Http\Controllers\Api\V1;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Api\V1\Traits\VerifiesOrganisationEvent;
use App\Http\Requests\Api\V1\UpsertPersonFieldValuesRequest;
use App\Http\Resources\Api\V1\PersonFieldValueResource;
use App\Models\Event;
use App\Models\Organisation;
use App\Models\Person;
use App\Services\RegistrationFormFieldService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
use Illuminate\Support\Facades\Gate;
final class PersonFieldValueController extends Controller
{
use VerifiesOrganisationEvent;
public function __construct(
private readonly RegistrationFormFieldService $service,
) {}
public function index(Organisation $organisation, Event $event, Person $person): AnonymousResourceCollection
{
$this->verifyEventBelongsToOrganisation($organisation, $event);
Gate::authorize('view', [$person, $event]);
$values = $this->service->getPersonValues($person);
return PersonFieldValueResource::collection($values);
}
public function upsert(UpsertPersonFieldValuesRequest $request, Organisation $organisation, Event $event, Person $person): JsonResponse
{
$this->verifyEventBelongsToOrganisation($organisation, $event);
Gate::authorize('update', [$person, $event]);
$this->service->upsertPersonValues($person, $request->validated()['values']);
$values = $this->service->getPersonValues($person);
return $this->success(PersonFieldValueResource::collection($values));
}
}

View File

@@ -1,48 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Http\Controllers\Api\V1;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Api\V1\Traits\VerifiesOrganisationEvent;
use App\Http\Requests\Api\V1\ReplacePersonSectionPreferencesRequest;
use App\Http\Resources\Api\V1\PersonSectionPreferenceResource;
use App\Models\Event;
use App\Models\Organisation;
use App\Models\Person;
use App\Services\PersonSectionPreferenceService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
use Illuminate\Support\Facades\Gate;
final class PersonSectionPreferenceController extends Controller
{
use VerifiesOrganisationEvent;
public function __construct(
private readonly PersonSectionPreferenceService $service,
) {}
public function index(Organisation $organisation, Event $event, Person $person): AnonymousResourceCollection
{
$this->verifyEventBelongsToOrganisation($organisation, $event);
Gate::authorize('view', [$person, $event]);
$preferences = $this->service->getPreferences($person);
return PersonSectionPreferenceResource::collection($preferences);
}
public function replace(ReplacePersonSectionPreferencesRequest $request, Organisation $organisation, Event $event, Person $person): JsonResponse
{
$this->verifyEventBelongsToOrganisation($organisation, $event);
Gate::authorize('update', [$person, $event]);
$this->service->replacePreferences($person, $request->validated()['preferences']);
$preferences = $this->service->getPreferences($person);
return $this->success(PersonSectionPreferenceResource::collection($preferences));
}
}

View File

@@ -37,7 +37,6 @@ final class PortalMeController extends Controller
'shiftAssignments.shift.festivalSection',
'shiftAssignments.shift.timeSlot',
'volunteerAvailabilities.timeSlot',
'fieldValues.registrationFormField',
'sectionPreferences.festivalSection',
])
->first();

View File

@@ -1,129 +0,0 @@
<?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_categories' => $field->tag_categories,
'is_required' => $field->is_required,
'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 (!empty($field->tag_categories)) {
$query->whereIn('category', $field->tag_categories);
}
$data['available_tags'] = $query->orderBy('category')->orderBy('sort_order')
->get()
->map(fn (PersonTag $tag) => [
'id' => $tag->id,
'name' => $tag->name,
'category' => $tag->category,
]);
}
return $data;
}),
],
]);
}
}

View File

@@ -1,62 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Http\Controllers\Api\V1;
use App\Http\Controllers\Controller;
use App\Http\Requests\Api\V1\StoreRegistrationFieldTemplateRequest;
use App\Http\Requests\Api\V1\UpdateRegistrationFieldTemplateRequest;
use App\Http\Resources\Api\V1\RegistrationFieldTemplateResource;
use App\Models\Organisation;
use App\Models\RegistrationFieldTemplate;
use App\Services\RegistrationFieldTemplateService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
use Illuminate\Support\Facades\Gate;
final class RegistrationFieldTemplateController extends Controller
{
public function __construct(
private readonly RegistrationFieldTemplateService $service,
) {}
public function index(Organisation $organisation): AnonymousResourceCollection
{
Gate::authorize('viewAny', [RegistrationFieldTemplate::class, $organisation]);
$templates = $this->service->listForOrganisation($organisation);
return RegistrationFieldTemplateResource::collection($templates);
}
public function store(StoreRegistrationFieldTemplateRequest $request, Organisation $organisation): JsonResponse
{
Gate::authorize('create', [RegistrationFieldTemplate::class, $organisation]);
$template = $this->service->createTemplate($organisation, $request->validated());
return $this->created(new RegistrationFieldTemplateResource($template));
}
public function update(
UpdateRegistrationFieldTemplateRequest $request,
Organisation $organisation,
RegistrationFieldTemplate $registrationFieldTemplate,
): JsonResponse {
Gate::authorize('update', [$registrationFieldTemplate, $organisation]);
$template = $this->service->updateTemplate($registrationFieldTemplate, $request->validated());
return $this->success(new RegistrationFieldTemplateResource($template));
}
public function destroy(Organisation $organisation, RegistrationFieldTemplate $registrationFieldTemplate): JsonResponse
{
Gate::authorize('delete', [$registrationFieldTemplate, $organisation]);
$this->service->deleteTemplate($registrationFieldTemplate);
return response()->json(null, 204);
}
}

View File

@@ -1,119 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Http\Controllers\Api\V1;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Api\V1\Traits\VerifiesOrganisationEvent;
use App\Http\Requests\Api\V1\ImportFromEventRequest;
use App\Http\Requests\Api\V1\ReorderRegistrationFormFieldsRequest;
use App\Http\Requests\Api\V1\StoreRegistrationFormFieldRequest;
use App\Http\Requests\Api\V1\UpdateRegistrationFormFieldRequest;
use App\Http\Resources\Api\V1\RegistrationFormFieldResource;
use App\Models\Event;
use App\Models\Organisation;
use App\Models\RegistrationFieldTemplate;
use App\Models\RegistrationFormField;
use App\Services\RegistrationFieldTemplateService;
use App\Services\RegistrationFormFieldService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
use Illuminate\Support\Facades\Gate;
final class RegistrationFormFieldController extends Controller
{
use VerifiesOrganisationEvent;
public function __construct(
private readonly RegistrationFormFieldService $service,
private readonly RegistrationFieldTemplateService $templateService,
) {}
public function index(Organisation $organisation, Event $event): AnonymousResourceCollection
{
$this->verifyEventBelongsToOrganisation($organisation, $event);
Gate::authorize('viewAny', [RegistrationFormField::class, $event]);
$fields = $this->service->listForEvent($event);
return RegistrationFormFieldResource::collection($fields);
}
public function store(StoreRegistrationFormFieldRequest $request, Organisation $organisation, Event $event): JsonResponse
{
$this->verifyEventBelongsToOrganisation($organisation, $event);
Gate::authorize('create', [RegistrationFormField::class, $event]);
$field = $this->service->createField($event, $request->validated());
return $this->created(new RegistrationFormFieldResource($field));
}
public function update(
UpdateRegistrationFormFieldRequest $request,
Organisation $organisation,
Event $event,
RegistrationFormField $registrationField,
): JsonResponse {
$this->verifyEventBelongsToOrganisation($organisation, $event);
Gate::authorize('update', [$registrationField, $event]);
$field = $this->service->updateField($registrationField, $request->validated());
return $this->success(new RegistrationFormFieldResource($field));
}
public function destroy(Organisation $organisation, Event $event, RegistrationFormField $registrationField): JsonResponse
{
$this->verifyEventBelongsToOrganisation($organisation, $event);
Gate::authorize('delete', [$registrationField, $event]);
$this->service->deleteField($registrationField);
return response()->json(null, 204);
}
public function reorder(ReorderRegistrationFormFieldsRequest $request, Organisation $organisation, Event $event): JsonResponse
{
$this->verifyEventBelongsToOrganisation($organisation, $event);
Gate::authorize('reorder', [RegistrationFormField::class, $event]);
$this->service->reorderFields($event, $request->validated()['ids']);
return response()->json(null, 204);
}
public function fromTemplate(Request $request, Organisation $organisation, Event $event): JsonResponse
{
$this->verifyEventBelongsToOrganisation($organisation, $event);
Gate::authorize('create', [RegistrationFormField::class, $event]);
$request->validate([
'template_id' => ['required', 'ulid', 'exists:registration_field_templates,id'],
]);
$template = RegistrationFieldTemplate::findOrFail($request->input('template_id'));
if ($template->organisation_id !== $event->organisation_id) {
return $this->error('Template does not belong to this organisation.', 422);
}
$field = $this->templateService->createFieldFromTemplate($event, $template);
return $this->created(new RegistrationFormFieldResource($field));
}
public function importFromEvent(ImportFromEventRequest $request, Organisation $organisation, Event $event): JsonResponse
{
$this->verifyEventBelongsToOrganisation($organisation, $event);
Gate::authorize('create', [RegistrationFormField::class, $event]);
$sourceEvent = Event::findOrFail($request->validated()['source_event_id']);
$fields = $this->service->importFromEvent($event, $sourceEvent);
return $this->success(RegistrationFormFieldResource::collection($fields));
}
}

View File

@@ -1,42 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Http\Controllers\Api\V1;
use App\Http\Controllers\Controller;
use App\Http\Requests\Api\V1\VolunteerRegistrationRequest;
use App\Http\Resources\Api\V1\PersonResource;
use App\Models\Event;
use App\Services\VolunteerRegistrationService;
use Illuminate\Http\JsonResponse;
final class VolunteerRegistrationController extends Controller
{
public function __construct(
private readonly VolunteerRegistrationService $registrationService,
) {}
public function __invoke(VolunteerRegistrationRequest $request, Event $event): JsonResponse
{
$user = auth('sanctum')->user();
$person = $this->registrationService->register(
$event,
$request->validated(),
$user
);
$person->load('crowdType');
$responseData = [
'person' => new PersonResource($person),
];
if ($person->wasRecentlyCreated) {
return $this->created($responseData);
}
return $this->success($responseData);
}
}

View File

@@ -1,27 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Http\Requests\Api\V1;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
final class ReorderRegistrationFormFieldsRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
/** @return array<string, mixed> */
public function rules(): array
{
$event = $this->route('event');
return [
'ids' => ['required', 'array', 'min:1'],
'ids.*' => ['required', 'ulid', Rule::exists('registration_form_fields', 'id')->where('event_id', $event->id)],
];
}
}

View File

@@ -1,72 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Http\Requests\Api\V1;
use App\Models\FestivalSection;
use Illuminate\Foundation\Http\FormRequest;
final class ReplacePersonSectionPreferencesRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
/** @return array<string, mixed> */
public function rules(): array
{
return [
'preferences' => ['required', 'array', 'min:1', 'max:5'],
'preferences.*.festival_section_id' => ['required', 'ulid'],
'preferences.*.priority' => ['required', 'integer', 'min:1', 'max:5'],
];
}
public function withValidator($validator): void
{
$validator->after(function ($validator) {
$preferences = $this->input('preferences', []);
if (!is_array($preferences)) {
return;
}
// Priorities must be unique
$priorities = array_column($preferences, 'priority');
if (count($priorities) !== count(array_unique($priorities))) {
$validator->errors()->add('preferences', 'Priorities must be unique within the request.');
}
// Validate section IDs belong to the event
$event = $this->route('event');
$person = $this->route('person');
if (!$event || !$person) {
return;
}
// Valid sections: own event's sections + parent festival's cross_event sections
$validSectionIds = FestivalSection::where('event_id', $event->id)
->pluck('id');
if ($event->parent_event_id) {
$parentCrossEventSections = FestivalSection::where('event_id', $event->parent_event_id)
->where('type', 'cross_event')
->pluck('id');
$validSectionIds = $validSectionIds->merge($parentCrossEventSections);
}
foreach ($preferences as $index => $pref) {
$sectionId = $pref['festival_section_id'] ?? null;
if ($sectionId && !$validSectionIds->contains($sectionId)) {
$validator->errors()->add(
"preferences.{$index}.festival_section_id",
'Section does not belong to this event.'
);
}
}
});
}
}

View File

@@ -1,57 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Http\Requests\Api\V1;
use App\Enums\FieldDisplayWidth;
use App\Enums\RegistrationFieldType;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
final class StoreRegistrationFieldTemplateRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
/** @return array<string, mixed> */
public function rules(): array
{
$fieldType = $this->input('field_type');
$type = RegistrationFieldType::tryFrom($fieldType);
$rules = [
'label' => ['required', 'string', 'max:255'],
'field_type' => ['required', Rule::in(array_column(RegistrationFieldType::cases(), 'value'))],
'help_text' => ['nullable', 'string', 'max:5000'],
'sort_order' => ['nullable', 'integer', 'min:0'],
'display_width' => ['sometimes', Rule::in(array_column(FieldDisplayWidth::cases(), 'value'))],
];
if ($type?->isStructural()) {
return $rules;
}
return array_merge($rules, [
'options' => [
$type?->requiresOptions() ? 'required' : 'nullable',
$type?->prohibitsOptions() ? 'prohibited' : 'nullable',
'array',
],
'options.*' => ['required'],
'options.*.label' => ['required_if:options.*,array', 'string', 'max:255'],
'options.*.description' => ['nullable', 'string', 'max:200'],
'tag_categories' => [
$type === RegistrationFieldType::TAG_PICKER ? 'nullable' : 'prohibited',
'array',
],
'tag_categories.*' => ['string', 'max:50'],
'is_required' => ['nullable', 'boolean'],
'is_filterable' => ['nullable', 'boolean'],
'is_portal_visible' => ['nullable', 'boolean'],
'is_admin_only' => ['nullable', 'boolean'],
]);
}
}

View File

@@ -1,57 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Http\Requests\Api\V1;
use App\Enums\FieldDisplayWidth;
use App\Enums\RegistrationFieldType;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
final class StoreRegistrationFormFieldRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
/** @return array<string, mixed> */
public function rules(): array
{
$fieldType = $this->input('field_type');
$type = RegistrationFieldType::tryFrom($fieldType);
$rules = [
'label' => ['required', 'string', 'max:255'],
'field_type' => ['required', Rule::in(array_column(RegistrationFieldType::cases(), 'value'))],
'help_text' => ['nullable', 'string', 'max:5000'],
'sort_order' => ['nullable', 'integer', 'min:0'],
'display_width' => ['sometimes', Rule::in(array_column(FieldDisplayWidth::cases(), 'value'))],
];
if ($type?->isStructural()) {
return $rules;
}
return array_merge($rules, [
'options' => [
$type?->requiresOptions() ? 'required' : 'nullable',
$type?->prohibitsOptions() ? 'prohibited' : 'nullable',
'array',
],
'options.*' => ['required'],
'options.*.label' => ['required_if:options.*,array', 'string', 'max:255'],
'options.*.description' => ['nullable', 'string', 'max:200'],
'tag_categories' => [
$type === RegistrationFieldType::TAG_PICKER ? 'nullable' : 'prohibited',
'array',
],
'tag_categories.*' => ['string', 'max:50'],
'is_required' => ['nullable', 'boolean'],
'is_portal_visible' => ['nullable', 'boolean'],
'is_admin_only' => ['nullable', 'boolean'],
'is_filterable' => ['nullable', 'boolean'],
]);
}
}

View File

@@ -1,39 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Http\Requests\Api\V1;
use App\Enums\FieldDisplayWidth;
use App\Enums\RegistrationFieldType;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
final class UpdateRegistrationFieldTemplateRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
/** @return array<string, mixed> */
public function rules(): array
{
return [
'label' => ['sometimes', 'string', 'max:255'],
'options' => ['nullable', 'array'],
'options.*' => ['required'],
'options.*.label' => ['required_if:options.*,array', 'string', 'max:255'],
'options.*.description' => ['nullable', 'string', 'max:200'],
'tag_categories' => ['nullable', 'array'],
'tag_categories.*' => ['string', 'max:50'],
'is_required' => ['nullable', 'boolean'],
'is_filterable' => ['nullable', 'boolean'],
'is_portal_visible' => ['nullable', 'boolean'],
'is_admin_only' => ['nullable', 'boolean'],
'help_text' => ['nullable', 'string', 'max:5000'],
'sort_order' => ['nullable', 'integer', 'min:0'],
'display_width' => ['sometimes', Rule::in(array_column(FieldDisplayWidth::cases(), 'value'))],
];
}
}

View File

@@ -1,38 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Http\Requests\Api\V1;
use App\Enums\FieldDisplayWidth;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
final class UpdateRegistrationFormFieldRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
/** @return array<string, mixed> */
public function rules(): array
{
return [
'label' => ['sometimes', 'string', 'max:255'],
'options' => ['nullable', 'array'],
'options.*' => ['required'],
'options.*.label' => ['required_if:options.*,array', 'string', 'max:255'],
'options.*.description' => ['nullable', 'string', 'max:200'],
'tag_categories' => ['nullable', 'array'],
'tag_categories.*' => ['string', 'max:50'],
'is_required' => ['nullable', 'boolean'],
'is_portal_visible' => ['nullable', 'boolean'],
'is_admin_only' => ['nullable', 'boolean'],
'is_filterable' => ['nullable', 'boolean'],
'help_text' => ['nullable', 'string', 'max:5000'],
'sort_order' => ['nullable', 'integer', 'min:0'],
'display_width' => ['sometimes', Rule::in(array_column(FieldDisplayWidth::cases(), 'value'))],
];
}
}

View File

@@ -1,133 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Http\Requests\Api\V1;
use App\Enums\RegistrationFieldType;
use App\Models\PersonTag;
use App\Models\RegistrationFormField;
use Illuminate\Foundation\Http\FormRequest;
final class UpsertPersonFieldValuesRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
/** @return array<string, mixed> */
public function rules(): array
{
return [
'values' => ['required', 'array'],
];
}
public function withValidator($validator): void
{
$validator->after(function ($validator) {
$values = $this->input('values', []);
$event = $this->route('event');
if (!$event || !is_array($values)) {
return;
}
$fields = RegistrationFormField::where('event_id', $event->id)
->get()
->keyBy('slug');
$orgId = $event->organisation_id;
foreach ($values as $slug => $value) {
$field = $fields->get($slug);
if ($field === null) {
$validator->errors()->add("values.{$slug}", "Unknown field: {$slug}");
continue;
}
if ($field->is_required && ($value === null || $value === '' || $value === [])) {
$validator->errors()->add("values.{$slug}", "The {$slug} field is required.");
continue;
}
if ($value === null || $value === '') {
continue;
}
match ($field->field_type) {
RegistrationFieldType::TEXT, RegistrationFieldType::TEXTAREA => $this->validateString($validator, $slug, $value),
RegistrationFieldType::NUMBER => $this->validateNumber($validator, $slug, $value),
RegistrationFieldType::BOOLEAN => $this->validateBoolean($validator, $slug, $value),
RegistrationFieldType::SELECT, RegistrationFieldType::RADIO => $this->validateSingleOption($validator, $slug, $value, $field),
RegistrationFieldType::MULTISELECT, RegistrationFieldType::CHECKBOX => $this->validateMultiOption($validator, $slug, $value, $field),
RegistrationFieldType::TAG_PICKER => $this->validateTagPicker($validator, $slug, $value, $orgId),
};
}
});
}
private function validateString($validator, string $slug, mixed $value): void
{
if (!is_string($value) || mb_strlen($value) > 5000) {
$validator->errors()->add("values.{$slug}", "Must be a string (max 5000 characters).");
}
}
private function validateNumber($validator, string $slug, mixed $value): void
{
if (!is_numeric($value)) {
$validator->errors()->add("values.{$slug}", "Must be a number.");
}
}
private function validateBoolean($validator, string $slug, mixed $value): void
{
if (!in_array($value, [true, false, 0, 1, '0', '1'], true)) {
$validator->errors()->add("values.{$slug}", "Must be a boolean.");
}
}
private function validateSingleOption($validator, string $slug, mixed $value, RegistrationFormField $field): void
{
if (!is_string($value) || !in_array($value, $field->options ?? [], true)) {
$validator->errors()->add("values.{$slug}", "Must be one of the defined options.");
}
}
private function validateMultiOption($validator, string $slug, mixed $value, RegistrationFormField $field): void
{
if (!is_array($value)) {
$validator->errors()->add("values.{$slug}", "Must be an array.");
return;
}
$options = $field->options ?? [];
foreach ($value as $item) {
if (!in_array($item, $options, true)) {
$validator->errors()->add("values.{$slug}", "Invalid option: {$item}");
}
}
}
private function validateTagPicker($validator, string $slug, mixed $value, string $orgId): void
{
if (!is_array($value)) {
$validator->errors()->add("values.{$slug}", "Must be an array of tag IDs.");
return;
}
$validTagIds = PersonTag::where('organisation_id', $orgId)
->where('is_active', true)
->pluck('id')
->all();
foreach ($value as $tagId) {
if (!in_array($tagId, $validTagIds, true)) {
$validator->errors()->add("values.{$slug}", "Invalid tag ID: {$tagId}");
}
}
}
}

View File

@@ -1,34 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Http\Resources\Api\V1;
use App\Enums\RegistrationFieldType;
use App\Models\PersonTag;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
final class PersonFieldValueResource extends JsonResource
{
public function toArray(Request $request): array
{
$field = $this->registrationFormField;
return [
'field_slug' => $field?->slug,
'field_label' => $field?->label,
'field_type' => $field?->field_type?->value,
'value' => $this->value,
'selected_options' => $this->selected_options,
'tag_names' => $this->when(
$field?->field_type === RegistrationFieldType::TAG_PICKER && !empty($this->selected_options),
function () {
return PersonTag::whereIn('id', $this->selected_options ?? [])
->pluck('name')
->all();
}
),
];
}
}

View File

@@ -64,8 +64,6 @@ final class PersonResource extends JsonResource
'added_by_user_id' => $this->pivot->added_by_user_id,
]
),
'field_values' => PersonFieldValueResource::collection($this->whenLoaded('fieldValues')),
'section_preferences' => PersonSectionPreferenceResource::collection($this->whenLoaded('sectionPreferences')),
'tags' => $this->when(
$this->user_id && $this->relationLoaded('user'),
function () {

View File

@@ -1,33 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Http\Resources\Api\V1;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
final class PersonSectionPreferenceResource extends JsonResource
{
public function toArray(Request $request): array
{
$section = $this->whenLoaded('festivalSection');
return [
'festival_section_id' => $this->festival_section_id,
'priority' => $this->priority,
'section_name' => $this->when(
$this->relationLoaded('festivalSection'),
fn () => $this->festivalSection?->name
),
'section_icon' => $this->when(
$this->relationLoaded('festivalSection'),
fn () => $this->festivalSection?->icon
),
'section_category' => $this->when(
$this->relationLoaded('festivalSection'),
fn () => $this->festivalSection?->category
),
];
}
}

View File

@@ -1,36 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Http\Resources\Api\V1;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
final class RegistrationFieldTemplateResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'organisation_id' => $this->organisation_id,
'label' => $this->label,
'slug' => $this->slug,
'field_type' => $this->field_type->value,
'options' => $this->options,
'normalized_options' => $this->normalized_options,
'tag_categories' => $this->tag_categories,
'is_required' => $this->is_required,
'is_filterable' => $this->is_filterable,
'is_portal_visible' => $this->is_portal_visible,
'is_admin_only' => $this->is_admin_only,
'help_text' => $this->help_text,
'sort_order' => $this->sort_order,
'display_width' => $this->display_width->value,
'is_system' => $this->is_system,
'is_active' => $this->is_active,
'created_at' => $this->created_at->toIso8601String(),
'updated_at' => $this->updated_at->toIso8601String(),
];
}
}

View File

@@ -1,49 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Http\Resources\Api\V1;
use App\Enums\RegistrationFieldType;
use App\Models\PersonTag;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
final class RegistrationFormFieldResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'event_id' => $this->event_id,
'label' => $this->label,
'slug' => $this->slug,
'field_type' => $this->field_type->value,
'options' => $this->options,
'normalized_options' => $this->normalized_options,
'tag_categories' => $this->tag_categories,
'is_required' => $this->is_required,
'is_portal_visible' => $this->is_portal_visible,
'is_admin_only' => $this->is_admin_only,
'is_filterable' => $this->is_filterable,
'help_text' => $this->help_text,
'sort_order' => $this->sort_order,
'display_width' => $this->display_width->value,
'created_at' => $this->created_at->toIso8601String(),
'updated_at' => $this->updated_at->toIso8601String(),
'available_tags' => $this->when(
$this->field_type === RegistrationFieldType::TAG_PICKER,
function () {
$query = PersonTag::where('organisation_id', $this->event->organisation_id)
->where('is_active', true);
if (!empty($this->tag_categories)) {
$query->whereIn('category', $this->tag_categories);
}
return PersonTagResource::collection($query->orderBy('category')->orderBy('sort_order')->get());
}
),
];
}
}

View File

@@ -85,11 +85,6 @@ final class Organisation extends Model
return $this->hasMany(PersonTag::class);
}
public function registrationFieldTemplates(): HasMany
{
return $this->hasMany(RegistrationFieldTemplate::class);
}
public function emailSettings(): HasOne
{
return $this->hasOne(OrganisationEmailSettings::class);

View File

@@ -105,11 +105,6 @@ final class Person extends Model
return $this->hasMany(VolunteerAvailability::class);
}
public function fieldValues(): HasMany
{
return $this->hasMany(PersonFieldValue::class);
}
public function formSubmissions(): MorphMany
{
return $this->morphMany(\App\Models\FormBuilder\FormSubmission::class, 'subject');

View File

@@ -1,37 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
final class PersonFieldValue extends Model
{
public $timestamps = false;
protected $fillable = [
'person_id',
'registration_form_field_id',
'value',
'selected_options',
];
protected function casts(): array
{
return [
'selected_options' => 'array',
];
}
public function person(): BelongsTo
{
return $this->belongsTo(Person::class);
}
public function registrationFormField(): BelongsTo
{
return $this->belongsTo(RegistrationFormField::class);
}
}

View File

@@ -1,99 +0,0 @@
<?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');
}
}

View File

@@ -1,104 +0,0 @@
<?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;
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_categories',
'is_required',
'is_portal_visible',
'is_admin_only',
'is_filterable',
'help_text',
'sort_order',
'display_width',
];
protected function casts(): array
{
return [
'field_type' => RegistrationFieldType::class,
'options' => 'array',
'tag_categories' => 'array',
'is_required' => 'boolean',
'is_portal_visible' => 'boolean',
'is_admin_only' => 'boolean',
'is_filterable' => 'boolean',
'sort_order' => 'integer',
'display_width' => FieldDisplayWidth::class,
];
}
public function event(): BelongsTo
{
return $this->belongsTo(Event::class);
}
public function personFieldValues(): HasMany
{
return $this->hasMany(PersonFieldValue::class, 'registration_form_field_id');
}
/** @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 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);
}
}

View File

@@ -1,53 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Policies;
use App\Models\Organisation;
use App\Models\RegistrationFieldTemplate;
use App\Models\User;
final class RegistrationFieldTemplatePolicy
{
public function viewAny(User $user, Organisation $organisation): bool
{
return $user->hasRole('super_admin')
|| $organisation->users()->where('user_id', $user->id)->exists();
}
public function create(User $user, Organisation $organisation): bool
{
return $this->canManageOrganisation($user, $organisation);
}
public function update(User $user, RegistrationFieldTemplate $template, Organisation $organisation): bool
{
if ($template->organisation_id !== $organisation->id) {
return false;
}
return $this->canManageOrganisation($user, $organisation);
}
public function delete(User $user, RegistrationFieldTemplate $template, Organisation $organisation): bool
{
if ($template->organisation_id !== $organisation->id) {
return false;
}
return $this->canManageOrganisation($user, $organisation);
}
private function canManageOrganisation(User $user, Organisation $organisation): bool
{
if ($user->hasRole('super_admin')) {
return true;
}
return $organisation->users()
->where('user_id', $user->id)
->wherePivot('role', 'org_admin')
->exists();
}
}

View File

@@ -1,84 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Policies;
use App\Models\Event;
use App\Models\RegistrationFormField;
use App\Models\User;
final class RegistrationFormFieldPolicy
{
public function viewAny(User $user, Event $event): bool
{
return $this->belongsToOrganisation($user, $event);
}
public function view(User $user, RegistrationFormField $field, Event $event): bool
{
if ($field->event_id !== $event->id) {
return false;
}
return $this->belongsToOrganisation($user, $event);
}
public function create(User $user, Event $event): bool
{
return $this->canManageEvent($user, $event);
}
public function update(User $user, RegistrationFormField $field, Event $event): bool
{
if ($field->event_id !== $event->id) {
return false;
}
return $this->canManageEvent($user, $event);
}
public function delete(User $user, RegistrationFormField $field, Event $event): bool
{
if ($field->event_id !== $event->id) {
return false;
}
return $this->canManageEvent($user, $event);
}
public function reorder(User $user, Event $event): bool
{
return $this->canManageEvent($user, $event);
}
private function belongsToOrganisation(User $user, Event $event): bool
{
if ($user->hasRole('super_admin')) {
return true;
}
return $event->organisation->users()->where('user_id', $user->id)->exists();
}
private function canManageEvent(User $user, Event $event): bool
{
if ($user->hasRole('super_admin')) {
return true;
}
$isOrgAdmin = $event->organisation->users()
->where('user_id', $user->id)
->wherePivot('role', 'org_admin')
->exists();
if ($isOrgAdmin) {
return true;
}
return $event->users()
->where('user_id', $user->id)
->wherePivot('role', 'event_manager')
->exists();
}
}

View File

@@ -19,12 +19,9 @@ use App\Models\Organisation;
use App\Models\OrganisationEmailSettings;
use App\Models\OrganisationEmailTemplate;
use App\Models\Person;
use App\Models\PersonFieldValue;
use App\Models\PersonIdentityMatch;
use App\Models\PersonSectionPreference;
use App\Models\PersonTag;
use App\Models\RegistrationFieldTemplate;
use App\Models\RegistrationFormField;
use App\Models\Shift;
use App\Models\ShiftAssignment;
use App\Models\ShiftWaitlist;
@@ -92,12 +89,9 @@ class AppServiceProvider extends ServiceProvider
'mfa_email_code' => MfaEmailCode::class,
'organisation_email_settings' => OrganisationEmailSettings::class,
'organisation_email_template' => OrganisationEmailTemplate::class,
'person_field_value' => PersonFieldValue::class,
'person_identity_match' => PersonIdentityMatch::class,
'person_section_preference' => PersonSectionPreference::class,
'person_tag' => PersonTag::class,
'registration_field_template' => RegistrationFieldTemplate::class,
'registration_form_field' => RegistrationFormField::class,
'shift' => Shift::class,
'shift_assignment' => ShiftAssignment::class,
'shift_waitlist' => ShiftWaitlist::class,

View File

@@ -357,9 +357,6 @@ final class PersonIdentityService
]);
});
// Sync registration tags
$this->syncRegistrationTags($person);
activity('identity')
->causedBy($resolvedBy)
->performedOn($person)
@@ -498,9 +495,6 @@ final class PersonIdentityService
]);
});
// Sync registration tags
$this->syncRegistrationTags($person);
activity('identity')
->causedBy($linkedBy)
->performedOn($person)
@@ -550,23 +544,4 @@ final class PersonIdentityService
return $person->fresh();
}
/**
* Sync registration tags when identity is confirmed.
*/
private function syncRegistrationTags(Person $person): void
{
if ($person->user_id === null) {
return;
}
try {
app(TagSyncService::class)->syncFromRegistration($person);
} catch (\Exception $e) {
Log::warning('Failed to sync registration tags on identity confirm', [
'person_id' => $person->id,
'user_id' => $person->user_id,
'error' => $e->getMessage(),
]);
}
}
}

View File

@@ -1,51 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Services;
use App\Models\Person;
use App\Models\PersonSectionPreference;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
final class PersonSectionPreferenceService
{
public function getPreferences(Person $person): Collection
{
return PersonSectionPreference::where('person_id', $person->id)
->with('festivalSection')
->orderBy('priority')
->get();
}
public function replacePreferences(Person $person, array $preferences): void
{
$old = PersonSectionPreference::where('person_id', $person->id)->get()->toArray();
DB::transaction(function () use ($person, $preferences): void {
PersonSectionPreference::where('person_id', $person->id)->delete();
foreach ($preferences as $pref) {
PersonSectionPreference::create([
'person_id' => $person->id,
'festival_section_id' => $pref['festival_section_id'],
'priority' => $pref['priority'],
]);
}
});
$activityLogger = activity('section_preferences')
->performedOn($person)
->withProperties([
'old' => $old,
'attributes' => $preferences,
]);
if (auth()->user()) {
$activityLogger->causedBy(auth()->user());
}
$activityLogger->log('person.section_preferences.replaced');
}
}

View File

@@ -1,215 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Services;
use App\Enums\FieldDisplayWidth;
use App\Enums\RegistrationFieldType;
use App\Models\Event;
use App\Models\Organisation;
use App\Models\RegistrationFieldTemplate;
use App\Models\RegistrationFormField;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
final class RegistrationFieldTemplateService
{
public function listForOrganisation(Organisation $organisation): Collection
{
return $organisation->registrationFieldTemplates()
->ordered()
->get();
}
public function createTemplate(Organisation $organisation, array $data): RegistrationFieldTemplate
{
$data['slug'] = $this->generateUniqueSlug($organisation, $data['label']);
if (!isset($data['display_width'])) {
$fieldType = RegistrationFieldType::from($data['field_type']);
$data['display_width'] = FieldDisplayWidth::defaultForFieldType($fieldType)->value;
}
$template = $organisation->registrationFieldTemplates()->create($data);
$activityLogger = activity('registration_templates')
->performedOn($template)
->withProperties(['attributes' => $data]);
if (auth()->user()) {
$activityLogger->causedBy(auth()->user());
}
$activityLogger->log('registration_template.created');
return $template;
}
public function updateTemplate(RegistrationFieldTemplate $template, array $data): RegistrationFieldTemplate
{
$old = $template->toArray();
if (isset($data['label']) && $data['label'] !== $template->label) {
$data['slug'] = $this->generateUniqueSlug($template->organisation, $data['label'], $template->id);
}
$template->update($data);
$activityLogger = activity('registration_templates')
->performedOn($template)
->withProperties(['old' => $old, 'attributes' => $data]);
if (auth()->user()) {
$activityLogger->causedBy(auth()->user());
}
$activityLogger->log('registration_template.updated');
return $template->fresh();
}
public function deleteTemplate(RegistrationFieldTemplate $template): void
{
if ($template->is_system) {
$template->update(['is_active' => false]);
$activityLogger = activity('registration_templates')
->performedOn($template);
if (auth()->user()) {
$activityLogger->causedBy(auth()->user());
}
$activityLogger->log('registration_template.deactivated');
return;
}
$activityLogger = activity('registration_templates')
->withProperties(['deleted_template' => $template->toArray()]);
if (auth()->user()) {
$activityLogger->causedBy(auth()->user());
}
$activityLogger->log('registration_template.deleted');
$template->delete();
}
public function createFieldFromTemplate(Event $event, RegistrationFieldTemplate $template): RegistrationFormField
{
$slug = $this->generateUniqueFieldSlug($event, $template->label);
$maxOrder = RegistrationFormField::where('event_id', $event->id)->max('sort_order') ?? -1;
$field = RegistrationFormField::create([
'event_id' => $event->id,
'label' => $template->label,
'slug' => $slug,
'field_type' => $template->field_type,
'options' => $template->options,
'tag_categories' => $template->tag_categories,
'is_required' => $template->is_required,
'is_portal_visible' => $template->is_portal_visible,
'is_admin_only' => $template->is_admin_only,
'is_filterable' => $template->is_filterable,
'help_text' => $template->help_text,
'sort_order' => $maxOrder + 1,
'display_width' => $template->display_width,
]);
$activityLogger = activity('registration_fields')
->performedOn($field)
->withProperties(['from_template_id' => $template->id]);
if (auth()->user()) {
$activityLogger->causedBy(auth()->user());
}
$activityLogger->log('registration_field.created_from_template');
return $field;
}
/**
* Seed system templates for a newly created organisation.
*/
public static function seedSystemTemplates(Organisation $organisation): void
{
$templates = [
['label' => 'Persoonlijke voorkeuren', 'field_type' => 'heading', 'help_text' => 'Vertel ons wat we over jou moeten weten', 'display_width' => 'full', 'sort_order' => 1],
['label' => 'Shirtmaat', 'field_type' => 'select', 'options' => ['XS', 'S', 'M', 'L', 'XL', 'XXL', 'XXXL'], 'is_filterable' => true, 'display_width' => 'half', 'sort_order' => 2],
['label' => 'Dieetwensen', 'field_type' => 'multiselect', 'options' => ['Vegetarisch', 'Veganistisch', 'Halal', 'Glutenvrij', 'Lactosevrij', 'Geen pinda\'s', 'Geen noten'], 'is_filterable' => true, 'display_width' => 'half', 'sort_order' => 3],
['label' => 'Vergoeding', 'field_type' => 'heading', 'help_text' => 'Kies hoe je wilt worden bedankt voor je inzet', 'display_width' => 'full', 'sort_order' => 4],
['label' => 'Vergoedingstype', 'field_type' => 'radio', 'options' => [
['label' => 'Pro Deo', 'description' => 'Je werkt als vrijwilliger zonder financiële vergoeding'],
['label' => 'Entreeticket', 'description' => 'Je ontvangt een gratis festivalticket als dank voor je inzet'],
['label' => 'Vrijwilligersvergoeding', 'description' => 'Je ontvangt een vergoeding conform de vrijwilligersregeling'],
], 'is_required' => true, 'display_width' => 'full', 'sort_order' => 5],
['label' => 'Noodcontact', 'field_type' => 'heading', 'help_text' => 'Wie kunnen we bereiken bij calamiteiten?', 'display_width' => 'full', 'sort_order' => 6],
['label' => 'Noodcontact naam', 'field_type' => 'text', 'display_width' => 'half', 'sort_order' => 7],
['label' => 'Noodcontact telefoon', 'field_type' => 'text', 'display_width' => 'half', 'sort_order' => 8],
['label' => 'Ervaring & vaardigheden', 'field_type' => 'heading', 'help_text' => 'Welke diploma\'s en skills heb je?', 'display_width' => 'full', 'sort_order' => 9],
['label' => 'EHBO / BHV diploma', 'field_type' => 'boolean', 'is_filterable' => true, 'display_width' => 'half', 'sort_order' => 10],
['label' => 'Rijbewijs', 'field_type' => 'boolean', 'is_filterable' => true, 'display_width' => 'half', 'sort_order' => 11],
['label' => 'Eerder vrijwilliger geweest', 'field_type' => 'boolean', 'is_filterable' => true, 'display_width' => 'half', 'sort_order' => 12],
['label' => 'Certificaten & vaardigheden', 'field_type' => 'tag_picker', 'tag_categories' => null, 'is_filterable' => true, 'display_width' => 'full', 'sort_order' => 13],
['label' => 'Aanvullende informatie', 'field_type' => 'heading', 'display_width' => 'full', 'sort_order' => 14],
['label' => 'Toestemming gegevensverwerking', 'field_type' => 'boolean', 'is_required' => true, 'help_text' => 'Ik geef toestemming voor de verwerking van mijn persoonsgegevens ten behoeve van de organisatie van dit evenement, conform de Algemene Verordening Gegevensbescherming (AVG).', 'display_width' => 'full', 'sort_order' => 15],
['label' => 'Opmerkingen', 'field_type' => 'textarea', 'display_width' => 'full', 'sort_order' => 16],
];
foreach ($templates as $data) {
$organisation->registrationFieldTemplates()->create([
...$data,
'slug' => Str::slug($data['label']),
'is_system' => true,
'is_active' => true,
'is_required' => $data['is_required'] ?? false,
'is_filterable' => $data['is_filterable'] ?? false,
'is_portal_visible' => true,
'is_admin_only' => false,
'display_width' => $data['display_width'] ?? 'full',
]);
}
}
private function generateUniqueSlug(Organisation $organisation, string $label, ?string $excludeId = null): string
{
$base = Str::slug($label);
$slug = $base;
$counter = 1;
while (true) {
$query = RegistrationFieldTemplate::where('organisation_id', $organisation->id)
->where('slug', $slug);
if ($excludeId) {
$query->where('id', '!=', $excludeId);
}
if (!$query->exists()) {
return $slug;
}
$counter++;
$slug = "{$base}-{$counter}";
}
}
private function generateUniqueFieldSlug(Event $event, string $label): string
{
$base = Str::slug($label);
$slug = $base;
$counter = 1;
while (RegistrationFormField::where('event_id', $event->id)->where('slug', $slug)->exists()) {
$counter++;
$slug = "{$base}-{$counter}";
}
return $slug;
}
}

View File

@@ -1,225 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Services;
use App\Enums\FieldDisplayWidth;
use App\Enums\RegistrationFieldType;
use App\Models\Event;
use App\Models\Person;
use App\Models\PersonFieldValue;
use App\Models\RegistrationFormField;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
final class RegistrationFormFieldService
{
public function __construct(
private readonly TagSyncService $tagSyncService,
) {}
public function listForEvent(Event $event): Collection
{
return RegistrationFormField::where('event_id', $event->id)
->ordered()
->get();
}
public function createField(Event $event, array $data): RegistrationFormField
{
$data['slug'] = $this->generateUniqueSlug($event, $data['label']);
if (!isset($data['display_width'])) {
$fieldType = RegistrationFieldType::from($data['field_type']);
$data['display_width'] = FieldDisplayWidth::defaultForFieldType($fieldType)->value;
}
$field = RegistrationFormField::create([
'event_id' => $event->id,
...$data,
]);
$activityLogger = activity('registration_fields')
->performedOn($field)
->withProperties(['attributes' => $data]);
if (auth()->user()) {
$activityLogger->causedBy(auth()->user());
}
$activityLogger->log('registration_field.created');
return $field;
}
public function updateField(RegistrationFormField $field, array $data): RegistrationFormField
{
$old = $field->toArray();
if (isset($data['label']) && $data['label'] !== $field->label) {
$data['slug'] = $this->generateUniqueSlug($field->event, $data['label'], $field->id);
}
$field->update($data);
$activityLogger = activity('registration_fields')
->performedOn($field)
->withProperties(['old' => $old, 'attributes' => $data]);
if (auth()->user()) {
$activityLogger->causedBy(auth()->user());
}
$activityLogger->log('registration_field.updated');
return $field->fresh();
}
public function deleteField(RegistrationFormField $field): void
{
$activityLogger = activity('registration_fields')
->withProperties(['deleted_field' => $field->toArray()]);
if (auth()->user()) {
$activityLogger->causedBy(auth()->user());
}
$activityLogger->log('registration_field.deleted');
$field->delete();
}
public function reorderFields(Event $event, array $orderedIds): void
{
DB::transaction(function () use ($event, $orderedIds): void {
foreach ($orderedIds as $index => $id) {
RegistrationFormField::where('id', $id)
->where('event_id', $event->id)
->update(['sort_order' => $index]);
}
});
}
public function upsertPersonValues(Person $person, array $values): void
{
$fields = RegistrationFormField::where('event_id', $person->event_id)
->get()
->keyBy('slug');
DB::transaction(function () use ($person, $values, $fields): void {
foreach ($values as $slug => $rawValue) {
$field = $fields->get($slug);
if ($field === null || $field->field_type->isStructural()) {
continue;
}
$data = ['person_id' => $person->id, 'registration_form_field_id' => $field->id];
if ($field->isMultiValue()) {
$data['value'] = null;
$data['selected_options'] = is_array($rawValue) ? $rawValue : [$rawValue];
} else {
$data['value'] = $rawValue === null ? null : (string) $rawValue;
$data['selected_options'] = null;
}
PersonFieldValue::updateOrCreate(
['person_id' => $person->id, 'registration_form_field_id' => $field->id],
$data,
);
}
});
$activityLogger = activity('registration_values')
->performedOn($person)
->withProperties(['slugs' => array_keys($values)]);
if (auth()->user()) {
$activityLogger->causedBy(auth()->user());
}
$activityLogger->log('person.field_values.upserted');
$this->tagSyncService->syncFromRegistration($person);
}
public function getPersonValues(Person $person): Collection
{
return PersonFieldValue::where('person_id', $person->id)
->with('registrationFormField')
->get();
}
public function importFromEvent(Event $targetEvent, Event $sourceEvent): Collection
{
$sourceFields = RegistrationFormField::where('event_id', $sourceEvent->id)
->ordered()
->get();
$maxOrder = RegistrationFormField::where('event_id', $targetEvent->id)->max('sort_order') ?? -1;
$created = collect();
foreach ($sourceFields as $sourceField) {
$slug = $this->generateUniqueSlug($targetEvent, $sourceField->label);
$field = RegistrationFormField::create([
'event_id' => $targetEvent->id,
'label' => $sourceField->label,
'slug' => $slug,
'field_type' => $sourceField->field_type,
'options' => $sourceField->options,
'tag_categories' => $sourceField->tag_categories,
'is_required' => $sourceField->is_required,
'is_portal_visible' => $sourceField->is_portal_visible,
'is_admin_only' => $sourceField->is_admin_only,
'is_filterable' => $sourceField->is_filterable,
'help_text' => $sourceField->help_text,
'sort_order' => ++$maxOrder,
'display_width' => $sourceField->display_width,
]);
$created->push($field);
}
$activityLogger = activity('registration_fields')
->withProperties([
'source_event_id' => $sourceEvent->id,
'target_event_id' => $targetEvent->id,
'fields_copied' => $created->count(),
]);
if (auth()->user()) {
$activityLogger->causedBy(auth()->user());
}
$activityLogger->log('registration_field.imported_from_event');
return $created;
}
private function generateUniqueSlug(Event $event, string $label, ?string $excludeId = null): string
{
$base = Str::slug($label);
$slug = $base;
$counter = 1;
while (true) {
$query = RegistrationFormField::where('event_id', $event->id)
->where('slug', $slug);
if ($excludeId) {
$query->where('id', '!=', $excludeId);
}
if (!$query->exists()) {
return $slug;
}
$counter++;
$slug = "{$base}-{$counter}";
}
}
}

View File

@@ -1,94 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Services;
use App\Enums\RegistrationFieldType;
use App\Models\Person;
use App\Models\PersonFieldValue;
use App\Models\RegistrationFormField;
use App\Models\UserOrganisationTag;
use Illuminate\Support\Facades\DB;
/**
* Syncs tag_picker registration field values to user_organisation_tags.
*
* Called from:
* - PersonController::approve() when a person is approved
* - PersonIdentityService::confirmMatch() when user_id is linked via identity matching
* - PersonIdentityService::manualLink() when user_id is linked manually
*/
final class TagSyncService
{
public function syncFromRegistration(Person $person): void
{
if ($person->user_id === null) {
return;
}
$organisationId = $person->event?->organisation_id;
if ($organisationId === null) {
return;
}
$tagPickerFields = RegistrationFormField::where('event_id', $person->event_id)
->where('field_type', RegistrationFieldType::TAG_PICKER)
->pluck('id');
if ($tagPickerFields->isEmpty()) {
return;
}
$selectedTagIds = PersonFieldValue::where('person_id', $person->id)
->whereIn('registration_form_field_id', $tagPickerFields)
->whereNotNull('selected_options')
->get()
->flatMap(fn (PersonFieldValue $v) => $v->selected_options ?? [])
->unique()
->values()
->all();
DB::transaction(function () use ($person, $organisationId, $selectedTagIds): void {
$existingSelfReported = UserOrganisationTag::where('user_id', $person->user_id)
->where('organisation_id', $organisationId)
->where('source', 'self_reported')
->pluck('person_tag_id')
->all();
$toAdd = array_diff($selectedTagIds, $existingSelfReported);
$toRemove = array_diff($existingSelfReported, $selectedTagIds);
if (!empty($toRemove)) {
UserOrganisationTag::where('user_id', $person->user_id)
->where('organisation_id', $organisationId)
->where('source', 'self_reported')
->whereIn('person_tag_id', $toRemove)
->delete();
}
foreach ($toAdd as $tagId) {
UserOrganisationTag::create([
'user_id' => $person->user_id,
'organisation_id' => $organisationId,
'person_tag_id' => $tagId,
'source' => 'self_reported',
'assigned_at' => now(),
]);
}
});
$activityLogger = activity('tag_sync')
->performedOn($person)
->withProperties([
'synced_tag_ids' => $selectedTagIds,
'organisation_id' => $organisationId,
]);
if (auth()->user()) {
$activityLogger->causedBy(auth()->user());
}
$activityLogger->log('person.tags.synced_from_registration');
}
}

View File

@@ -1,204 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Services;
use App\Enums\PersonStatus;
use App\Mail\RegistrationConfirmationMail;
use App\Models\CrowdType;
use App\Models\Event;
use App\Models\Person;
use App\Models\User;
use App\Models\VolunteerAvailability;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Mail;
use Illuminate\Validation\ValidationException;
final class VolunteerRegistrationService
{
public function __construct(
private readonly RegistrationFormFieldService $registrationFormFieldService,
private readonly PersonSectionPreferenceService $personSectionPreferenceService,
private readonly TagSyncService $tagSyncService,
) {}
/**
* @param array<string, mixed> $validated
*
* @throws ValidationException
*/
public function register(Event $event, array $validated, ?User $user): Person
{
if ($event->status !== 'registration_open') {
throw ValidationException::withMessages([
'event' => ['This event is not accepting registrations.'],
]);
}
$festivalEvent = $this->resolveFestivalEvent($event);
$email = strtolower($user?->email ?? $validated['email']);
$this->checkDuplicateRegistration($festivalEvent, $email);
$volunteerCrowdType = $this->resolveVolunteerCrowdType($event);
$person = DB::transaction(function () use ($festivalEvent, $validated, $user, $email, $volunteerCrowdType): Person {
$person = Person::updateOrCreate(
[
'event_id' => $festivalEvent->id,
'email' => $email,
],
[
'crowd_type_id' => $volunteerCrowdType->id,
'first_name' => $validated['first_name'] ?? $user->first_name,
'last_name' => $validated['last_name'] ?? $user->last_name,
'phone' => $validated['phone'] ?? null,
'date_of_birth' => $validated['date_of_birth'] ?? null,
'status' => PersonStatus::PENDING,
'registration_source' => 'self',
'custom_fields' => [
'tshirt_size' => $validated['tshirt_size'] ?? null,
'first_aid' => $validated['first_aid'] ?? false,
'allergies' => $validated['allergies'] ?? null,
'driving_licence' => $validated['driving_licence'] ?? false,
'motivation' => $validated['motivation'] ?? null,
'motivation_other' => $validated['motivation_other'] ?? null,
],
]
);
// Link to authenticated user directly (they already have an account)
if ($user) {
$person->user_id = $user->id;
$person->save();
}
$this->syncAvailabilities($person, $festivalEvent, $validated['availabilities'] ?? []);
if (!empty($validated['field_values'])) {
$this->registrationFormFieldService->upsertPersonValues(
$person,
$validated['field_values']
);
}
if (!empty($validated['section_preferences'])) {
$this->personSectionPreferenceService->replacePreferences(
$person,
$validated['section_preferences']
);
}
// Trigger tag sync if user_id is known
if ($person->user_id) {
$this->tagSyncService->syncFromRegistration($person);
}
$source = $user ? 'authenticated_form' : 'public_form';
$activityLogger = activity('volunteer_registration')
->performedOn($person)
->withProperties([
'source' => $source,
'event_id' => $festivalEvent->id,
'person_id' => $person->id,
'email' => $email,
]);
if ($user) {
$activityLogger->causedBy($user);
}
$activityLogger->log('person.registered');
return $person;
});
// Send confirmation email (queued, outside transaction)
Mail::to($person->email)->queue(new RegistrationConfirmationMail($person, $festivalEvent));
return $person;
}
private function resolveFestivalEvent(Event $event): Event
{
if ($event->isSubEvent()) {
return $event->parent;
}
return $event;
}
/**
* @throws ValidationException
*/
private function checkDuplicateRegistration(Event $festivalEvent, string $email): void
{
$existing = Person::where('event_id', $festivalEvent->id)
->where('email', $email)
->first();
if ($existing === null) {
return;
}
if ($existing->status !== PersonStatus::REJECTED->value) {
throw ValidationException::withMessages([
'email' => ['Already registered for this event.'],
]);
}
}
/**
* @throws \RuntimeException
*/
private function resolveVolunteerCrowdType(Event $event): CrowdType
{
$crowdType = CrowdType::where('organisation_id', $event->organisation_id)
->where('system_type', 'VOLUNTEER')
->first();
if ($crowdType === null) {
Log::error('No volunteer crowd type configured', [
'organisation_id' => $event->organisation_id,
'event_id' => $event->id,
]);
abort(500, 'No volunteer crowd type configured for this organisation.');
}
return $crowdType;
}
/**
* @param array<int, array<string, mixed>> $availabilities
*/
private function syncAvailabilities(Person $person, Event $festivalEvent, array $availabilities): void
{
if (empty($availabilities)) {
return;
}
VolunteerAvailability::where('person_id', $person->id)->delete();
$validTimeSlotIds = $festivalEvent->getAllRelevantTimeSlots()
->where('person_type', 'VOLUNTEER')
->pluck('id')
->toArray();
foreach ($availabilities as $availability) {
if (! in_array($availability['time_slot_id'], $validTimeSlotIds, true)) {
continue;
}
VolunteerAvailability::create([
'person_id' => $person->id,
'time_slot_id' => $availability['time_slot_id'],
'preference_level' => $availability['preference_level'] ?? 3,
'submitted_at' => now(),
]);
}
}
}