- Seed AVAILABILITY_PICKER and SECTION_PRIORITY demo fields in the
event_registration showcase, and augment seedEchtFeesten with a
parent-level VOLUNTEER time slot pair + a standard registration-
visible section whose name duplicates a child section so the
PublicFormController dedup path is exercised end-to-end.
- Validate SECTION_PRIORITY value shape in FormValueService: arrays of
{ section_id, priority } with unique section_ids + priorities in 1..5,
max 5 entries, and section_ids scoped to the schema's event tree
(parent + children). Error envelope is the standard VALIDATION_FAILED
FieldValidationException shape so the portal renders errors next to
the field.
- Enrich admin-facing FormSubmissionResource with a nested identity_match
block mirroring the PublicFormSubmissionResource contract (status only;
leaves room for future matched_user_id / confidence).
- Lock in the FORM-05 stub contract with 6 tests against the existing
TriggerPersonIdentityMatchOnFormSubmit listener (no new listener was
needed — the current one already writes 'pending' for public
event_registration submissions per ARCH §31.1).
- 24 new backend assertions across seeder, shape validation, listener
state matrix, and resource serialisation.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
93 lines
4.0 KiB
PHP
93 lines
4.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Resources\FormBuilder;
|
|
|
|
use App\Models\FormBuilder\FormSubmission;
|
|
use App\Services\FormBuilder\FieldAccessService;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
/**
|
|
* @mixin FormSubmission
|
|
*/
|
|
final class FormSubmissionResource extends JsonResource
|
|
{
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(Request $request): array
|
|
{
|
|
$this->resource->loadMissing(['values.field', 'sectionStatuses', 'delegations']);
|
|
|
|
$fieldAccess = app(FieldAccessService::class);
|
|
$fields = $this->values->map(fn ($v) => $v->field)->filter();
|
|
$visibleFieldIds = $fieldAccess
|
|
->filterVisibleFields($request->user(), $fields, $this->resource)
|
|
->pluck('id')
|
|
->all();
|
|
|
|
$values = [];
|
|
foreach ($this->values as $value) {
|
|
if ($value->field === null) {
|
|
continue;
|
|
}
|
|
if (! in_array($value->field->id, $visibleFieldIds, true)) {
|
|
continue;
|
|
}
|
|
$values[$value->field->slug] = [
|
|
'value' => $value->value,
|
|
'value_anonymised' => (bool) $value->value_anonymised,
|
|
];
|
|
}
|
|
|
|
return [
|
|
'id' => $this->id,
|
|
'form_schema_id' => $this->form_schema_id,
|
|
'subject_type' => $this->subject_type,
|
|
'subject_id' => $this->subject_id,
|
|
'submitted_by_user_id' => $this->submitted_by_user_id,
|
|
'public_submitter_name' => $this->public_submitter_name,
|
|
'public_submitter_email' => $this->public_submitter_email,
|
|
'status' => $this->status instanceof \BackedEnum ? $this->status->value : $this->status,
|
|
'review_status' => $this->review_status instanceof \BackedEnum ? $this->review_status->value : $this->review_status,
|
|
'review_info' => $this->when($this->reviewed_at !== null, fn () => [
|
|
'reviewed_by_user_id' => $this->reviewed_by_user_id,
|
|
'reviewed_at' => optional($this->reviewed_at)->toIso8601String(),
|
|
'notes' => $this->review_notes,
|
|
]),
|
|
'submitted_at' => optional($this->submitted_at)->toIso8601String(),
|
|
'schema_version_at_submit' => $this->schema_version_at_submit,
|
|
'submitted_in_locale' => $this->submitted_in_locale,
|
|
'opened_at' => optional($this->opened_at)->toIso8601String(),
|
|
'first_interacted_at' => optional($this->first_interacted_at)->toIso8601String(),
|
|
'submission_duration_seconds' => $this->submission_duration_seconds,
|
|
'is_test' => (bool) $this->is_test,
|
|
'identity_match' => $this->identity_match_status !== null && $this->identity_match_status !== ''
|
|
? ['status' => $this->identity_match_status instanceof \BackedEnum
|
|
? $this->identity_match_status->value
|
|
: (string) $this->identity_match_status]
|
|
: null,
|
|
'values' => $values,
|
|
'section_statuses' => $this->sectionStatuses->map(fn ($s) => [
|
|
'form_schema_section_id' => $s->form_schema_section_id,
|
|
'status' => $s->status,
|
|
'submitted_at' => optional($s->submitted_at)->toIso8601String(),
|
|
'reviewed_at' => optional($s->reviewed_at)->toIso8601String(),
|
|
])->all(),
|
|
'delegations' => $this->delegations
|
|
->filter(fn ($d) => $d->revoked_at === null)
|
|
->map(fn ($d) => [
|
|
'id' => $d->id,
|
|
'delegated_to_user_id' => $d->delegated_to_user_id,
|
|
'delegated_by_user_id' => $d->delegated_by_user_id,
|
|
'granted_at' => optional($d->granted_at)->toIso8601String(),
|
|
'message' => $d->message,
|
|
])->values()->all(),
|
|
'created_at' => optional($this->created_at)->toIso8601String(),
|
|
'updated_at' => optional($this->updated_at)->toIso8601String(),
|
|
];
|
|
}
|
|
}
|