diff --git a/api/app/Console/Commands/SeedArtistAdvanceDefaultCommand.php b/api/app/Console/Commands/SeedArtistAdvanceDefaultCommand.php new file mode 100644 index 00000000..d7e2cb60 --- /dev/null +++ b/api/app/Console/Commands/SeedArtistAdvanceDefaultCommand.php @@ -0,0 +1,51 @@ +argument('organisation'); + + $query = Organisation::query(); + if (is_string($organisationId) && $organisationId !== '') { + $query->whereKey($organisationId); + } + + $organisations = $query->get(); + if ($organisations->isEmpty()) { + $this->error('No organisations matched the supplied filter.'); + + return self::FAILURE; + } + + foreach ($organisations as $organisation) { + ArtistAdvanceDefault::seedFor($organisation); + $this->line(sprintf(' ✓ %s (%s)', $organisation->name, $organisation->id)); + } + + $this->info(sprintf('Seeded artist_advance defaults for %d organisation(s).', $organisations->count())); + + return self::SUCCESS; + } +} diff --git a/api/app/FormBuilder/Defaults/ArtistAdvanceDefault.php b/api/app/FormBuilder/Defaults/ArtistAdvanceDefault.php new file mode 100644 index 00000000..5cf6c769 --- /dev/null +++ b/api/app/FormBuilder/Defaults/ArtistAdvanceDefault.php @@ -0,0 +1,181 @@ +withoutGlobalScope(OrganisationScope::class) + ->where('organisation_id', $organisation->id) + ->where('purpose', FormPurpose::ARTIST_ADVANCE->value) + ->first(); + + if ($existing instanceof FormSchema) { + return $existing; + } + + return DB::transaction(static function () use ($organisation): FormSchema { + $schema = FormSchema::create([ + 'organisation_id' => $organisation->id, + 'owner_type' => 'organisation', + 'owner_id' => $organisation->id, + 'name' => 'Artiest advance', + 'slug' => 'artiest-advance', + 'purpose' => FormPurpose::ARTIST_ADVANCE->value, + 'description' => 'Standaard advance-formulier voor artiesten. Pas de secties en velden aan via de FormBuilder.', + 'is_published' => true, + 'submission_mode' => FormSubmissionMode::DRAFT_SINGLE->value, + 'locale' => 'nl', + 'snapshot_mode' => FormSchemaSnapshotMode::ON_SUBMIT->value, + 'freeze_on_submit' => false, + 'section_level_submit' => true, + 'auto_save_enabled' => true, + 'version' => 1, + ]); + + foreach (self::sectionDefinitions() as $sortOrder => $def) { + $section = FormSchemaSection::create([ + 'form_schema_id' => $schema->id, + 'slug' => $def['slug'], + 'name' => $def['name'], + 'sort_order' => $sortOrder + 1, + 'submit_independent' => true, + 'required_for_schema_submit' => true, + ]); + + foreach ($def['fields'] as $fieldOrder => $field) { + FormField::create([ + 'form_schema_id' => $schema->id, + 'form_schema_section_id' => $section->id, + 'field_type' => $field['type']->value, + 'slug' => $field['slug'], + 'label' => $field['label'], + 'help_text' => $field['help_text'] ?? null, + 'is_required' => $field['is_required'] ?? false, + '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())->value, + 'sort_order' => $fieldOrder + 1, + ]); + } + } + + return $schema->refresh(); + }); + } + + /** + * @return array + * }> + */ + private static function sectionDefinitions(): array + { + return [ + [ + 'slug' => 'general-info', + 'name' => 'Algemeen', + 'advance_type' => AdvanceSectionType::Custom, + 'fields' => [ + ['type' => FormFieldType::DATETIME, 'slug' => 'arrival-datetime', 'label' => 'Aankomsttijd', 'is_required' => true, 'display_width' => 'half'], + ['type' => FormFieldType::DATETIME, 'slug' => 'departure-datetime', 'label' => 'Vertrektijd', 'is_required' => true, 'display_width' => 'half'], + ['type' => FormFieldType::TEXTAREA, 'slug' => 'general-notes', 'label' => 'Opmerkingen'], + ], + ], + [ + 'slug' => 'contacts', + 'name' => 'Contactpersonen', + 'advance_type' => AdvanceSectionType::Contacts, + 'fields' => [ + ['type' => FormFieldType::TEXT, 'slug' => 'tour-manager-name', 'label' => 'Tour manager', 'is_required' => true, 'is_pii' => true, 'display_width' => 'full'], + ['type' => FormFieldType::EMAIL, 'slug' => 'tour-manager-email', 'label' => 'E-mail tour manager', 'is_required' => true, 'is_pii' => true, 'display_width' => 'half'], + ['type' => FormFieldType::PHONE, 'slug' => 'tour-manager-phone', 'label' => 'Telefoon tour manager', 'is_pii' => true, 'display_width' => 'half'], + ['type' => FormFieldType::TABLE_ROWS, 'slug' => 'additional-contacts', 'label' => 'Aanvullende contactpersonen', 'is_pii' => true], + ], + ], + [ + 'slug' => 'production', + 'name' => 'Productie', + 'advance_type' => AdvanceSectionType::Production, + 'fields' => [ + ['type' => FormFieldType::FILE_UPLOAD, 'slug' => 'stage-plot', 'label' => 'Stage plot'], + ['type' => FormFieldType::TEXTAREA, 'slug' => 'monitor-needs', 'label' => 'Monitorwensen'], + ['type' => FormFieldType::TEXTAREA, 'slug' => 'special-equipment', 'label' => 'Specifieke apparatuur'], + ], + ], + [ + 'slug' => 'technical-rider', + 'name' => 'Technische rider', + 'advance_type' => AdvanceSectionType::Production, + 'fields' => [ + ['type' => FormFieldType::FILE_UPLOAD, 'slug' => 'input-list', 'label' => 'Input list'], + ['type' => FormFieldType::TEXTAREA, 'slug' => 'microphone-preferences', 'label' => 'Microfoonvoorkeuren'], + ['type' => FormFieldType::TEXTAREA, 'slug' => 'backline-requirements', 'label' => 'Backline'], + ], + ], + [ + 'slug' => 'hospitality', + 'name' => 'Hospitality', + 'advance_type' => AdvanceSectionType::Custom, + 'fields' => [ + ['type' => FormFieldType::TEXTAREA, 'slug' => 'dressing-room-requirements', 'label' => 'Kleedkamer'], + ['type' => FormFieldType::TEXTAREA, 'slug' => 'food-preferences', 'label' => 'Cateringvoorkeuren'], + ['type' => FormFieldType::TEXTAREA, 'slug' => 'drinks', 'label' => 'Drankvoorkeuren'], + ['type' => FormFieldType::TEXT, 'slug' => 'allergies', 'label' => 'Allergieën', 'is_pii' => true], + ], + ], + ]; + } +} diff --git a/api/app/Observers/OrganisationObserver.php b/api/app/Observers/OrganisationObserver.php new file mode 100644 index 00000000..0c0de7cf --- /dev/null +++ b/api/app/Observers/OrganisationObserver.php @@ -0,0 +1,27 @@ +