feat: unique email addresses of participants unless child, cleanup
addresses #869axbn21
This commit is contained in:
@@ -195,4 +195,44 @@ class BookingDto
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
|
||||
#[Assert\Callback(groups: ['booking_create_step_2', 'booking_edit'])]
|
||||
public function validateEmailUniqueness(ExecutionContextInterface $context): void
|
||||
{
|
||||
// Build map of email addresses to participant indices (adults only)
|
||||
$emailMap = [];
|
||||
|
||||
foreach ($this->participants as $index => $participant) {
|
||||
// Skip children (they can share email addresses)
|
||||
if (true === $participant->isChild()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip null or empty emails (handled by other validators)
|
||||
if (null === $participant->email || '' === trim($participant->email)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Normalize email for case-insensitive comparison
|
||||
$normalizedEmail = strtolower(trim($participant->email));
|
||||
|
||||
// Add participant index to the email map
|
||||
if (false === isset($emailMap[$normalizedEmail])) {
|
||||
$emailMap[$normalizedEmail] = [];
|
||||
}
|
||||
$emailMap[$normalizedEmail][] = $index;
|
||||
}
|
||||
|
||||
// Add validation errors for duplicate emails
|
||||
foreach ($emailMap as $email => $indices) {
|
||||
// Only add violations if email is used by multiple adult participants
|
||||
if (1 < count($indices)) {
|
||||
foreach ($indices as $index) {
|
||||
$context->buildViolation('Diese E-Mail Adresse wird bereits von einem anderen erwachsenen Teilnehmer verwendet')
|
||||
->atPath(sprintf('participants[%d].email', $index))
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user