wip: improved validation and feedback

This commit is contained in:
Björn Fromme
2025-10-23 08:50:45 +02:00
parent 9c716477aa
commit 60176d19f4
8 changed files with 36 additions and 176 deletions
+1 -1
View File
@@ -196,7 +196,7 @@ class BookingDto
}
}
#[Assert\Callback(groups: ['booking_create_step_2', 'booking_edit'])]
#[Assert\Callback(groups: ['booking_create', 'booking_edit'])]
public function validateEmailUniqueness(ExecutionContextInterface $context): void
{
// Build map of email addresses to participant indices (adults only)
+23 -14
View File
@@ -10,8 +10,8 @@ use App\BusProNet\Model\Service;
use App\Validator\Constraints as AppAssert;
use Symfony\Component\Validator\Constraints as Assert;
#[AppAssert\Participant(groups: ['booking_edit', 'booking_create_step_2'])]
#[AppAssert\ApplicantAddress(groups: ['booking_create_step_2'])]
#[AppAssert\Participant(groups: ['booking_edit', 'booking_create'])]
#[AppAssert\ApplicantAddress(groups: ['booking_create'])]
class ParticipantDto
{
/**
@@ -41,10 +41,10 @@ class ParticipantDto
public ?string $status = null;
public bool $mutable = false;
#[Assert\NotBlank(message: 'Bitte angeben', groups: ['booking_edit', 'booking_create_step_2'])]
#[Assert\NotBlank(message: 'Bitte angeben', groups: ['booking_edit', 'booking_create'])]
public ?string $firstName = null;
#[Assert\NotBlank(message: 'Bitte angeben', groups: ['booking_edit', 'booking_create_step_2'])]
#[Assert\NotBlank(message: 'Bitte angeben', groups: ['booking_edit', 'booking_create'])]
public ?string $lastName = null;
public ?string $title = null;
public ?string $gender = null;
@@ -54,20 +54,20 @@ class ParticipantDto
public ?string $shoeSize = null;
public ?string $weight = null;
#[Assert\NotNull(message: 'Bitte angeben', groups: ['booking_edit', 'booking_create_step_2'])]
#[Assert\NotNull(message: 'Bitte angeben', groups: ['booking_edit', 'booking_create'])]
public ?\DateTimeImmutable $dateOfBirth = null;
#[Assert\NotBlank(message: 'Bitte angeben', groups: ['booking_edit', 'booking_create_step_2'])]
#[Assert\Email(message: 'Bitte eine gültige E-Mail Adresse angeben', mode: 'strict', groups: ['booking_edit', 'booking_create_step_2'])]
#[Assert\NotBlank(message: 'Bitte angeben', groups: ['booking_edit', 'booking_create'])]
#[Assert\Email(message: 'Bitte eine gültige E-Mail Adresse angeben', mode: 'strict', groups: ['booking_edit', 'booking_create'])]
public ?string $email = null;
public ?string $mobile = null;
#[Assert\Valid(groups: ['booking_edit', 'booking_create_step_2'])]
#[Assert\Valid(groups: ['booking_edit', 'booking_create'])]
#[Assert\NotNull(message: 'Bitte Adresse angeben', groups: ['applicant_address'])]
public ?Address $address = null;
#[Assert\NotNull(message: 'Bitte ein Zimmer auswählen', groups: ['booking_create_step_2'])]
#[Assert\NotNull(message: 'Bitte ein Zimmer auswählen', groups: ['booking_create'])]
public ?int $assignedRoomId = null;
public ?string $remarksRoom = null;
@@ -75,7 +75,7 @@ class ParticipantDto
public array $courses = [];
public array $additionalServices = [];
#[Assert\NotNull(message: 'Bitte auswählen', groups: ['booking_edit', 'booking_create_step_2'])]
#[Assert\NotNull(message: 'Bitte auswählen', groups: ['booking_edit', 'booking_create'])]
public ?Service $skiPass = null;
public array $board = [];
@@ -214,12 +214,21 @@ class ParticipantDto
/**
* Adds a notification message for user feedback.
*
* @param string $type The notification type (info, warning, success)
* @param string $message The notification message
* Uses an optional ID to prevent duplicate notifications. If no ID is provided,
* generates one from the type and message combination. Duplicate IDs will
* overwrite previous notifications, ensuring each unique notification appears once.
*
* @param string $type The notification type (info, warning, success)
* @param string $message The notification message
* @param string|null $id Optional unique identifier (auto-generated if null)
*/
public function addNotification(string $type, string $message): void
public function addNotification(string $type, string $message, ?string $id = null): void
{
$this->notifications[] = [
// Generate ID from type and message if not provided
$notificationId = $id ?? md5($type.'_'.$message);
// Use ID as key to automatically prevent duplicates
$this->notifications[$notificationId] = [
'type' => $type,
'message' => $message,
];