feat: move prepopulation guards into participant service
This commit is contained in:
@@ -1,71 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Form\Service;
|
||||
|
||||
use App\BusProNet\Model\Address;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Model\ParticipantDto;
|
||||
use Carbon\CarbonImmutable;
|
||||
|
||||
/**
|
||||
* Fills participant forms with generated dummy data for testing and demo workflows.
|
||||
*
|
||||
* When a special token is entered in the lastName field during booking creation,
|
||||
* this service detects it and fills contact data fields with generated values
|
||||
* based on the participant number and current time. Only active in create mode.
|
||||
*/
|
||||
class DummyDataFillService
|
||||
{
|
||||
public const TOKEN = '#KUN#';
|
||||
|
||||
/**
|
||||
* Checks if the participant's lastName matches the fill token.
|
||||
*
|
||||
* Only matches in create mode to prevent accidental triggering during
|
||||
* editing of existing bookings.
|
||||
*
|
||||
* @param ParticipantDto $participant The participant to check
|
||||
* @param string $mode The booking mode (create or edit)
|
||||
*
|
||||
* @return bool True if the token matches and mode is create
|
||||
*/
|
||||
public function isTokenMatch(ParticipantDto $participant, string $mode): bool
|
||||
{
|
||||
if (BookingDto::MODE_CREATE !== $mode) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return self::TOKEN === $participant->lastName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fills the participant DTO with generated dummy personal data.
|
||||
*
|
||||
* Generates firstName, lastName, email, mobile, date of birth and address
|
||||
* values based on the participant number (1-based). The lastName includes
|
||||
* the current time for easy identification of test bookings.
|
||||
*
|
||||
* @param ParticipantDto $participant The participant DTO to fill
|
||||
* @param int $participantIndex The zero-based participant index
|
||||
*/
|
||||
public function fill(ParticipantDto $participant, int $participantIndex): void
|
||||
{
|
||||
$participantNumber = $participantIndex + 1;
|
||||
$now = CarbonImmutable::now();
|
||||
|
||||
$participant->firstName = sprintf('Vorname %d', $participantNumber);
|
||||
$participant->lastName = sprintf('Muster %d %s', $participantNumber, $now->format('H:i'));
|
||||
$participant->mobile = '0171/111111';
|
||||
$participant->email = sprintf('teilnehmer.in%[email protected]', $participantNumber);
|
||||
$participant->dateOfBirth = $now->subYears(20)->toImmutable();
|
||||
|
||||
$address = new Address();
|
||||
$address->street = 'Musterstr. 123';
|
||||
$address->postCode = '99999';
|
||||
$address->city = 'MusterOrt';
|
||||
$address->country = 'Deutschland';
|
||||
$participant->address = $address;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user