Phase 4 of S1.
Models (app/Models/FormBuilder/): FormSchema, FormSchemaSection, FormField,
FormSubmission, FormValue, FormValueOption, FormTemplate, FormFieldLibrary,
FormSchemaWebhook, FormWebhookDelivery, FormSubmissionSectionStatus,
FormSubmissionDelegation. Plus UserProfile at app/Models/ (user-universal).
OrganisationScope applied on: FormSchema, FormTemplate, FormFieldLibrary.
FormSchemaWebhook documents inherited-scope discipline (OrganisationScope's
strategies — organisation_id/event_id/festival_section_id — don't cover
form_schema_id; direct queries would leak across orgs, so must go via
$schema->webhooks()).
User::profile()/getOrCreateProfile(), Event::formSchemas() (morphMany),
Person::formSubmissions() (morphMany).
Morph map enforced in AppServiceProvider with 28 keys covering every model
that appears as activitylog subject/causer. Also updated
OrganisationDashboardService (and its test) to query activitylog via
getMorphClass() instead of FQCN.
Activity log strategy: nuanced explicit calls (logSchemaChange on FormSchema,
logFieldChange on FormField) — no LogsActivity trait. Suppression for bulk
fixtures via App\Support\ActivityLog::suppressed(fn() => ...) which flips
config('activitylog.enabled') around a callback. Both our explicit calls
and spatie's trait on Organisation respect the flag via ActivityLogger::log().
FormValueObserver (app/Observers/FormBuilder/) populates value_indexed/
value_number/value_date/value_bool on save per field.value_storage_hint,
rebuilds form_value_options pivot on multi-value filterable fields, cleans
up on delete. Memoised field cache avoids N+1. Registered in AppServiceProvider.
9 lightweight event classes (app/Events/FormBuilder/) as SerializesModels
containers — submission lifecycle signatures lock in for S2 services, no
listeners yet.
Factories for all models with Dutch fake data (fake('nl_NL')). FormSchema
factory uses defaultSubmissionMode(); FormField factory uses
recommendedValueStorageHint().
Tests: 9 new observer tests (all pass); full suite 910/910 (up from 901).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
73 lines
2.2 KiB
PHP
73 lines
2.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Database\Factories\FormBuilder;
|
|
|
|
use App\Enums\FormBuilder\FormPurpose;
|
|
use App\Enums\FormBuilder\FormSchemaSnapshotMode;
|
|
use App\Enums\FormBuilder\FormSubmissionMode;
|
|
use App\Models\FormBuilder\FormSchema;
|
|
use App\Models\Organisation;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
use Illuminate\Support\Str;
|
|
|
|
/** @extends Factory<FormSchema> */
|
|
final class FormSchemaFactory extends Factory
|
|
{
|
|
protected $model = FormSchema::class;
|
|
|
|
/** @return array<string, mixed> */
|
|
public function definition(): array
|
|
{
|
|
$purpose = fake()->randomElement([
|
|
FormPurpose::EVENT_REGISTRATION,
|
|
FormPurpose::FEEDBACK,
|
|
FormPurpose::INCIDENT_REPORT,
|
|
FormPurpose::USER_PROFILE,
|
|
]);
|
|
$name = 'Formulier '.fake('nl_NL')->words(2, true);
|
|
|
|
return [
|
|
'organisation_id' => Organisation::factory(),
|
|
'owner_type' => null,
|
|
'owner_id' => null,
|
|
'name' => $name,
|
|
'slug' => Str::slug($name).'-'.Str::lower(Str::random(4)),
|
|
'purpose' => $purpose,
|
|
'custom_purpose_slug' => null,
|
|
'description' => fake('nl_NL')->sentence(),
|
|
'is_published' => false,
|
|
'submission_mode' => $purpose->defaultSubmissionMode(),
|
|
'locale' => 'nl',
|
|
'snapshot_mode' => FormSchemaSnapshotMode::NEVER,
|
|
'freeze_on_submit' => false,
|
|
'section_level_submit' => false,
|
|
'auto_save_enabled' => false,
|
|
];
|
|
}
|
|
|
|
public function custom(string $slug): static
|
|
{
|
|
return $this->state(fn () => [
|
|
'purpose' => FormPurpose::CUSTOM,
|
|
'submission_mode' => FormSubmissionMode::SINGLE,
|
|
'custom_purpose_slug' => $slug,
|
|
]);
|
|
}
|
|
|
|
public function published(): static
|
|
{
|
|
return $this->state(fn () => ['is_published' => true]);
|
|
}
|
|
|
|
public function forPurpose(FormPurpose $purpose): static
|
|
{
|
|
return $this->state(fn () => [
|
|
'purpose' => $purpose,
|
|
'submission_mode' => $purpose->defaultSubmissionMode(),
|
|
'custom_purpose_slug' => $purpose === FormPurpose::CUSTOM ? 'custom-'.Str::lower(Str::random(6)) : null,
|
|
]);
|
|
}
|
|
}
|