> */ public static function canonicalFields(): array { return [ ['type' => FormFieldType::HEADING, 'slug' => 'persoonlijke-voorkeuren', 'label' => 'Persoonlijke voorkeuren', 'help_text' => 'Vertel ons wat we over jou moeten weten', 'display_width' => 'full'], ['type' => FormFieldType::SELECT, 'slug' => 'shirtmaat', 'label' => 'Shirtmaat', 'options' => ['XS', 'S', 'M', 'L', 'XL', 'XXL', 'XXXL'], 'is_filterable' => true, 'display_width' => 'half'], ['type' => FormFieldType::MULTISELECT, 'slug' => 'dieetwensen', 'label' => 'Dieetwensen', 'options' => ['Vegetarisch', 'Veganistisch', 'Halal', 'Glutenvrij', 'Lactosevrij', "Geen pinda's", 'Geen noten'], 'is_filterable' => true, 'display_width' => 'half'], ['type' => FormFieldType::HEADING, 'slug' => 'vergoeding', 'label' => 'Vergoeding', 'help_text' => 'Kies hoe je wilt worden bedankt voor je inzet', 'display_width' => 'full'], ['type' => FormFieldType::RADIO, 'slug' => 'vergoedingstype', 'label' => 'Vergoedingstype', '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'], ['type' => FormFieldType::HEADING, 'slug' => 'noodcontact', 'label' => 'Noodcontact', 'help_text' => 'Wie kunnen we bereiken bij calamiteiten?', 'display_width' => 'full'], ['type' => FormFieldType::TEXT, 'slug' => 'noodcontact-naam', 'label' => 'Noodcontact naam', 'is_pii' => true, 'display_width' => 'half'], ['type' => FormFieldType::TEXT, 'slug' => 'noodcontact-telefoon', 'label' => 'Noodcontact telefoon', 'is_pii' => true, 'display_width' => 'half'], ['type' => FormFieldType::HEADING, 'slug' => 'ervaring-vaardigheden', 'label' => 'Ervaring & vaardigheden', 'help_text' => "Welke diploma's en skills heb je?", 'display_width' => 'full'], ['type' => FormFieldType::BOOLEAN, 'slug' => 'ehbo-bhv-diploma', 'label' => 'EHBO / BHV diploma', 'is_filterable' => true, 'display_width' => 'half'], ['type' => FormFieldType::BOOLEAN, 'slug' => 'rijbewijs', 'label' => 'Rijbewijs', 'is_filterable' => true, 'display_width' => 'half'], ['type' => FormFieldType::BOOLEAN, 'slug' => 'eerder-vrijwilliger-geweest', 'label' => 'Eerder vrijwilliger geweest', 'is_filterable' => true, 'display_width' => 'half'], ['type' => FormFieldType::TAG_PICKER, 'slug' => 'certificaten-vaardigheden', 'label' => 'Certificaten & vaardigheden', 'is_filterable' => true, 'display_width' => 'full'], ['type' => FormFieldType::HEADING, 'slug' => 'aanvullende-informatie', 'label' => 'Aanvullende informatie', 'display_width' => 'full'], ['type' => FormFieldType::BOOLEAN, 'slug' => 'toestemming-gegevensverwerking', 'label' => 'Toestemming gegevensverwerking', '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).', 'is_required' => true, 'display_width' => 'full'], ['type' => FormFieldType::TEXTAREA, 'slug' => 'opmerkingen', 'label' => 'Opmerkingen', 'display_width' => 'full'], ]; } public static function seedSystemTemplates(Organisation $org): int { $count = 0; foreach (self::canonicalFields() as $sortOrder => $field) { $snapshot = [ 'schema_version' => 1, 'snapshot_created_at' => now()->toIso8601String(), 'schema' => [ 'name' => $field['label'].' (template)', 'slug' => $field['slug'], 'purpose' => FormPurpose::EVENT_REGISTRATION->value, 'description' => null, 'locale' => 'nl', 'freeze_on_submit' => false, 'section_level_submit' => false, 'settings' => [], ], 'sections' => [], 'fields' => [[ 'id' => (string) Str::ulid(), 'slug' => $field['slug'], 'field_type' => $field['type']->value, 'label' => $field['label'], 'help_text' => $field['help_text'] ?? null, 'section_slug' => null, 'options' => $field['options'] ?? null, 'validation_rules' => null, 'is_required' => $field['is_required'] ?? false, 'is_filterable' => $field['is_filterable'] ?? false, 'is_pii' => $field['is_pii'] ?? false, 'binding' => null, 'conditional_logic' => null, 'translations' => null, 'value_storage_hint' => $field['type']->recommendedValueStorageHint()->value, 'sort_order' => $sortOrder + 1, ]], ]; FormTemplate::create([ 'organisation_id' => $org->id, 'name' => $field['label'], 'slug' => $field['slug'], 'purpose' => FormPurpose::EVENT_REGISTRATION, 'description' => null, 'schema_snapshot' => $snapshot, 'is_active' => true, ])->forceFill(['is_system' => true])->save(); $count++; } return $count; } /** * Create one FormSchema (event_registration) for this event with the * canonical 16-field set. */ public static function seedEventSchema(Event $event): FormSchema { $schema = FormSchema::create([ 'organisation_id' => $event->organisation_id, 'owner_type' => 'event', 'owner_id' => $event->id, 'name' => $event->name.' — registratie', 'slug' => Str::slug($event->slug.'-registratie'), 'purpose' => FormPurpose::EVENT_REGISTRATION, 'description' => "Registratieformulier voor {$event->name}.", 'is_published' => in_array( $event->status, ['registration_open', 'buildup', 'showday', 'teardown', 'closed'], true ), 'submission_mode' => FormSubmissionMode::DRAFT_SINGLE, 'locale' => 'nl', 'snapshot_mode' => FormSchemaSnapshotMode::NEVER, 'freeze_on_submit' => false, 'section_level_submit' => false, 'auto_save_enabled' => false, ]); foreach (self::canonicalFields() as $sortOrder => $field) { FormField::create([ 'form_schema_id' => $schema->id, 'field_type' => $field['type']->value, 'slug' => $field['slug'], 'label' => $field['label'], 'help_text' => $field['help_text'] ?? null, 'options' => $field['options'] ?? null, 'is_required' => $field['is_required'] ?? false, 'is_filterable' => $field['is_filterable'] ?? false, 'is_portal_visible' => true, 'is_admin_only' => false, 'is_pii' => $field['is_pii'] ?? false, 'display_width' => $field['display_width'] ?? 'full', 'value_storage_hint' => $field['type']->recommendedValueStorageHint(), 'sort_order' => $sortOrder + 1, ]); } return $schema; } /** * For each person with status ∈ applied/approved/no_show on this event, * create one FormSubmission with a realistic handful of FormValues. * Status follows the same rule as MigrateLegacyFormsData. */ public static function seedSubmissionsForEvent(Event $event, FormSchema $schema): int { $fields = $schema->fields()->get()->keyBy('slug'); $persons = Person::where('event_id', $event->id) ->whereIn('status', ['applied', 'approved', 'no_show']) ->get(); $count = 0; foreach ($persons as $person) { $isSubmittedStatus = in_array($person->status, ['applied', 'approved', 'no_show'], true); $status = $isSubmittedStatus ? FormSubmissionStatus::SUBMITTED : FormSubmissionStatus::DRAFT; $submission = FormSubmission::create([ 'form_schema_id' => $schema->id, 'subject_type' => 'person', 'subject_id' => $person->id, 'submitted_by_user_id' => $person->user_id, 'status' => $status, 'is_test' => false, 'submitted_in_locale' => 'nl', 'submitted_at' => $status === FormSubmissionStatus::SUBMITTED ? now()->subDays(rand(1, 30)) : null, 'schema_version_at_submit' => $status === FormSubmissionStatus::SUBMITTED ? 1 : null, ]); $seed = crc32((string) $person->id); $sizes = ['XS', 'S', 'M', 'L', 'XL', 'XXL']; self::createValueIfField($fields, 'shirtmaat', ['value' => $sizes[$seed % 6]], $submission); self::createValueIfField($fields, 'dieetwensen', ($seed % 3 === 0) ? ['Vegetarisch'] : [], $submission); self::createValueIfField($fields, 'rijbewijs', ['value' => ($seed % 2) === 0], $submission); self::createValueIfField($fields, 'ehbo-bhv-diploma', ['value' => ($seed % 4) === 0], $submission); self::createValueIfField($fields, 'noodcontact-naam', ['value' => 'Partner / Familielid'], $submission); self::createValueIfField($fields, 'toestemming-gegevensverwerking', ['value' => true], $submission); $count++; } return $count; } /** * @param \Illuminate\Support\Collection $fields * @param mixed $value */ private static function createValueIfField($fields, string $slug, $value, FormSubmission $submission): void { $field = $fields->get($slug); if ($field === null) { return; } FormValue::create([ 'form_submission_id' => $submission->id, 'form_field_id' => $field->id, 'value' => $value, ]); } }