diff --git a/src/Entity/Embeddable/Address.php b/src/Entity/Embeddable/Address.php index 6a3f21f..4193bd4 100644 --- a/src/Entity/Embeddable/Address.php +++ b/src/Entity/Embeddable/Address.php @@ -2,13 +2,12 @@ namespace App\Entity\Embeddable; -use App\Validator\Constraints as AppAssert; use App\BusProNet\Model\ProfileResponse; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; +use Symfony\Component\Validator\Context\ExecutionContextInterface; #[ORM\Embeddable] -#[AppAssert\Address(message: 'Bitte vervollständige deine Anschrift', groups: ['profile_preflight'])] class Address { #[ORM\Column(type: 'string', nullable: true)] @@ -27,6 +26,32 @@ class Address #[Assert\NotBlank(message: 'Bitte gib deinen Land an', groups: ['profile'])] protected ?string $country = null; + #[Assert\Callback(groups: ['profile_preflight'])] + public function preflightCheck(ExecutionContextInterface $executionContext): void + { + $missing = []; + + if (empty($this->getStreet())) { + $missing[] = 'Straße'; + } + if (empty($this->getCity())) { + $missing[] = 'Ort'; + } + if (empty($this->getPostCode())) { + $missing[] = 'PLZ'; + } + if (empty($this->getCountry())) { + $missing[] = 'Land'; + } + + if (0 < count($missing)) { + $executionContext + ->buildViolation(sprintf('Bitte vervollständige deine Anschrift (%s).', implode(', ', $missing))) + ->addViolation() + ; + } + } + public function toPayload(): array { return [ diff --git a/src/Entity/Embeddable/BankAccount.php b/src/Entity/Embeddable/BankAccount.php index 2f51d89..be2478e 100644 --- a/src/Entity/Embeddable/BankAccount.php +++ b/src/Entity/Embeddable/BankAccount.php @@ -2,12 +2,11 @@ namespace App\Entity\Embeddable; -use App\Validator\Constraints as AppAssert; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; +use Symfony\Component\Validator\Context\ExecutionContextInterface; #[ORM\Embeddable] -#[AppAssert\BankAccount(message: 'Bitte vervollständige deine Bankverbindung', groups: ['profile_preflight'])] class BankAccount { #[ORM\Column(nullable: true)] @@ -27,6 +26,33 @@ class BankAccount #[Assert\NotBlank(message: 'Bitte gib den Kontoinhaber an', groups: ['profile'])] private ?string $holder = null; + #[Assert\Callback(groups: ['profile_preflight'])] + public function preflightCheck(ExecutionContextInterface $executionContext): void + { + $missing = []; + + if (empty($this->getIban())) { + $missing[] = 'IBAN'; + } + if (empty($this->getBic())) { + $missing[] = 'BIC'; + } + if (empty($this->getBank())) { + $missing[] = 'Name der Bank'; + } + if (empty($this->getHolder())) { + $missing[] = 'Kontoinhaber'; + } + + if (0 < count($missing)) { + $executionContext + ->buildViolation(sprintf('Bitte vervollständige deine Bankverbindung (%s)', implode(', ', $missing))) + ->addViolation() + ; + } + + } + public function getIban(bool $obfuscated = false): ?string { if (false === $obfuscated) { diff --git a/src/Entity/Embeddable/Communication.php b/src/Entity/Embeddable/Communication.php index 292d4a7..0d5aa5c 100644 --- a/src/Entity/Embeddable/Communication.php +++ b/src/Entity/Embeddable/Communication.php @@ -2,13 +2,12 @@ namespace App\Entity\Embeddable; -use App\Validator\Constraints as AppAssert; use App\BusProNet\Model\ProfileResponse; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; +use Symfony\Component\Validator\Context\ExecutionContextInterface; #[ORM\Embeddable] -#[AppAssert\Communication(message: 'Bitte vervollständige deine Kontaktdaten', groups: ['profile_preflight'])] class Communication { #[ORM\Column(type: 'string', nullable: true)] @@ -23,6 +22,26 @@ class Communication #[Assert\NotBlank(message: 'Bitte gib deine E-Mail-Adresse an', groups: ['profile'])] protected ?string $email = null; + #[Assert\Callback(groups: ['profile_preflight'])] + public function preflightCheck(ExecutionContextInterface $executionContext): void + { + $missing = []; + + if (empty($this->getEmail())) { + $missing[] = 'E-Mail'; + } + if (empty($this->getMobile())) { + $missing[] = 'Mobilnummer'; + } + + if (0 < count($missing)) { + $executionContext + ->buildViolation(sprintf('Bitte vervollständige deine Kontaktdaten (%s)', implode(', ', $missing))) + ->addViolation() + ; + } + } + public function toPayload(): array { return [ diff --git a/src/Validator/Constraints/Address.php b/src/Validator/Constraints/Address.php deleted file mode 100644 index 7b173a0..0000000 --- a/src/Validator/Constraints/Address.php +++ /dev/null @@ -1,23 +0,0 @@ -message = $message ?? $this->message; - } - - public function getTargets(): string - { - return Constraint::CLASS_CONSTRAINT; - } -} \ No newline at end of file diff --git a/src/Validator/Constraints/AddressValidator.php b/src/Validator/Constraints/AddressValidator.php deleted file mode 100644 index 1a2f19d..0000000 --- a/src/Validator/Constraints/AddressValidator.php +++ /dev/null @@ -1,35 +0,0 @@ -getStreet() - || null === $value->getCity() - || null === $value->getPostCode() - || null === $value->getCountry() - ; - - if ($isIncomplete) { - $this->context - ->buildViolation($constraint->message) - ->addViolation() - ; - } - } -} \ No newline at end of file diff --git a/src/Validator/Constraints/BankAccount.php b/src/Validator/Constraints/BankAccount.php deleted file mode 100644 index 50c2e53..0000000 --- a/src/Validator/Constraints/BankAccount.php +++ /dev/null @@ -1,23 +0,0 @@ -message = $message ?? $this->message; - } - - public function getTargets(): string - { - return Constraint::CLASS_CONSTRAINT; - } -} \ No newline at end of file diff --git a/src/Validator/Constraints/BankAccountValidator.php b/src/Validator/Constraints/BankAccountValidator.php deleted file mode 100644 index c584c8c..0000000 --- a/src/Validator/Constraints/BankAccountValidator.php +++ /dev/null @@ -1,35 +0,0 @@ -getIban() - || null === $value->getBic() - || null === $value->getBank() - || null === $value->getHolder() - ; - - if ($isIncomplete) { - $this->context - ->buildViolation($constraint->message) - ->addViolation() - ; - } - } -} \ No newline at end of file diff --git a/src/Validator/Constraints/Communication.php b/src/Validator/Constraints/Communication.php deleted file mode 100644 index 174a8d6..0000000 --- a/src/Validator/Constraints/Communication.php +++ /dev/null @@ -1,23 +0,0 @@ -message = $message ?? $this->message; - } - - public function getTargets(): string - { - return Constraint::CLASS_CONSTRAINT; - } -} \ No newline at end of file diff --git a/src/Validator/Constraints/CommunicationValidator.php b/src/Validator/Constraints/CommunicationValidator.php deleted file mode 100644 index b33b322..0000000 --- a/src/Validator/Constraints/CommunicationValidator.php +++ /dev/null @@ -1,31 +0,0 @@ -getEmail() || null === $value->getMobile(); - - if ($isIncomplete) { - $this->context - ->buildViolation($constraint->message) - ->addViolation() - ; - } - } -} \ No newline at end of file diff --git a/templates/teamer/profile.html.twig b/templates/teamer/profile.html.twig index 95690b4..49a9691 100644 --- a/templates/teamer/profile.html.twig +++ b/templates/teamer/profile.html.twig @@ -73,7 +73,6 @@ Anschrift
- {{ form_errors(form.address) }} {{ form_row(form.address.street) }} {{ form_row(form.address.postCode) }} {{ form_row(form.address.city) }} @@ -83,7 +82,6 @@ Kontakt
- {{ form_errors(form.communication) }} {{ form_row(form.communication.email) }} {{ form_row(form.communication.phone) }} {{ form_row(form.communication.mobile) }} @@ -95,7 +93,6 @@ Bankverbindung
- {{ form_errors(form.bankAccount) }} {{ form_row(form.bankAccount.iban) }} {{ form_row(form.bankAccount.bic) }} {{ form_row(form.bankAccount.bank) }}