S2a: purge legacy Form Builder PHP code and routes
This commit is contained in:
@@ -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)],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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.'
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -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'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -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'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -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'))],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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'))],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user