Implement EAV system for dynamic event-specific registration fields with organisation-level templates, person section preferences with priority ranking, and TagSyncService for deferred tag_picker sync. New tables: registration_field_templates, registration_form_fields, person_field_values, person_section_preferences. New columns: persons.remarks, events.registration_show_section_preferences, events.registration_show_availability. 58 tests, 126 assertions — all 432 tests pass (zero regressions). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
79 lines
3.1 KiB
PHP
79 lines
3.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Resources\Api\V1;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
final class PersonResource extends JsonResource
|
|
{
|
|
public function toArray(Request $request): array
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'event_id' => $this->event_id,
|
|
'first_name' => $this->first_name,
|
|
'last_name' => $this->last_name,
|
|
'date_of_birth' => $this->date_of_birth?->toDateString(),
|
|
'full_name' => $this->full_name,
|
|
'email' => $this->email,
|
|
'phone' => $this->phone,
|
|
'status' => $this->status,
|
|
'is_blacklisted' => $this->is_blacklisted,
|
|
'admin_notes' => $this->admin_notes,
|
|
'remarks' => $this->remarks,
|
|
'custom_fields' => $this->custom_fields,
|
|
'created_at' => $this->created_at->toIso8601String(),
|
|
'crowd_type' => new CrowdTypeResource($this->whenLoaded('crowdType')),
|
|
'company' => new CompanyResource($this->whenLoaded('company')),
|
|
'pending_identity_match' => $this->when(
|
|
$this->relationLoaded('pendingIdentityMatch') && $this->pendingIdentityMatch,
|
|
function () {
|
|
$match = $this->pendingIdentityMatch;
|
|
|
|
return [
|
|
'match_id' => $match->id,
|
|
'matched_user' => [
|
|
'id' => $match->matchedUser->id,
|
|
'first_name' => $match->matchedUser->first_name,
|
|
'last_name' => $match->matchedUser->last_name,
|
|
'full_name' => $match->matchedUser->full_name,
|
|
'email' => $match->matchedUser->email,
|
|
],
|
|
'matched_on' => $match->matched_on->value,
|
|
'confidence' => $match->confidence->value,
|
|
];
|
|
}
|
|
),
|
|
'crowd_list_pivot' => $this->when(
|
|
$this->pivot && $this->pivot->added_at,
|
|
fn () => [
|
|
'added_at' => $this->pivot->added_at,
|
|
'added_by_user_id' => $this->pivot->added_by_user_id,
|
|
]
|
|
),
|
|
'field_values' => PersonFieldValueResource::collection($this->whenLoaded('fieldValues')),
|
|
'section_preferences' => PersonSectionPreferenceResource::collection($this->whenLoaded('sectionPreferences')),
|
|
'tags' => $this->when(
|
|
$this->user_id && $this->relationLoaded('user'),
|
|
function () {
|
|
$orgId = $this->event?->organisation_id;
|
|
if (!$orgId || !$this->user) {
|
|
return [];
|
|
}
|
|
|
|
return UserOrganisationTagResource::collection(
|
|
$this->user->organisationTags()
|
|
->where('organisation_id', $orgId)
|
|
->with('personTag')
|
|
->get()
|
|
);
|
|
},
|
|
[]
|
|
),
|
|
];
|
|
}
|
|
}
|