wip: major refactoring
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Form\Service;
|
||||
|
||||
use App\Form\Model\BookingDtoInterface;
|
||||
use App\Form\Service\Abstract\AbstractParticipantFieldHandler;
|
||||
|
||||
/**
|
||||
* Handles processing of the assignedRoomId field for booking participants.
|
||||
*
|
||||
* This handler manages room assignments for participants in the booking creation
|
||||
* process. It processes the assignedRoomId field from form submissions and updates
|
||||
* the participant DTO with the selected room. The handler properly handles empty
|
||||
* selections (converting them to null) and validates numeric room IDs.
|
||||
*
|
||||
* Field Processing:
|
||||
* - Extracts room ID from submitted form data
|
||||
* - Converts empty strings to null (unselected choice)
|
||||
* - Normalizes string values to integers
|
||||
* - Updates the participant's assignedRoomId property
|
||||
*
|
||||
* Dependencies: None (this is a base field that other handlers may depend on)
|
||||
*/
|
||||
class ParticipantAssignedRoomFieldHandler extends AbstractParticipantFieldHandler
|
||||
{
|
||||
/**
|
||||
* Returns the form field name this handler processes.
|
||||
*
|
||||
* This handler is responsible for the 'assignedRoomId' field, which contains
|
||||
* the selected room ID for each participant in the booking form.
|
||||
*
|
||||
* @return string The field name 'assignedRoomId'
|
||||
*/
|
||||
public function getFieldName(): string
|
||||
{
|
||||
return 'assignedRoomId';
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the assignedRoomId field for a specific participant.
|
||||
*
|
||||
* This method extracts the room assignment from the submitted form data and
|
||||
* updates the corresponding participant in the booking DTO. It handles the
|
||||
* common form processing pattern where empty selections are submitted as
|
||||
* empty strings but should be stored as null values.
|
||||
*
|
||||
* Processing steps:
|
||||
* 1. Safely retrieves the participant object from the DTO
|
||||
* 2. Extracts the assignedRoomId value from submitted data
|
||||
* 3. Normalizes the value (empty string → null, numeric string → integer)
|
||||
* 4. Updates the participant's assignedRoomId property
|
||||
*
|
||||
* @param array<string, mixed> $submittedData The submitted participant form data
|
||||
* @param BookingDtoInterface $bookingDto The booking DTO to update (create or edit)
|
||||
* @param int $participantIndex The index of the participant being processed
|
||||
*/
|
||||
public function processField(array $submittedData, BookingDtoInterface $bookingDto, int $participantIndex): void
|
||||
{
|
||||
// Safely get the participant object, returning early if not found
|
||||
$participant = $this->getParticipant($bookingDto, $participantIndex);
|
||||
|
||||
if (null === $participant) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Extract the room ID from form data (defaults to null if not present)
|
||||
$roomId = $this->getFieldValue($submittedData, $this->getFieldName());
|
||||
|
||||
// Convert form string to integer, handling empty selections as null
|
||||
$participant->assignedRoomId = $this->normalizeIntValue($roomId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user