104 lines
2.6 KiB
PHP
104 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Entity\Embeddable;
|
|
|
|
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]
|
|
class Communication
|
|
{
|
|
#[ORM\Column(type: 'string', nullable: true)]
|
|
protected ?string $phone = null;
|
|
|
|
#[ORM\Column(type: 'string', nullable: true)]
|
|
#[Assert\NotBlank(message: 'Bitte gib deine Mobilnummer an', groups: ['profile'])]
|
|
protected ?string $mobile = null;
|
|
|
|
#[ORM\Column(type: 'string', nullable: true)]
|
|
#[Assert\Email(mode: 'strict', message: 'Bitte gib eine gültige E-Mail-Adresse an', groups: ['profile'])]
|
|
#[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 [
|
|
'email' => $this->getEmail(),
|
|
'telefonmobil' => $this->getMobile(),
|
|
'telefonprivat' => $this->getPhone(),
|
|
];
|
|
}
|
|
|
|
public static function fromApiResponse(ProfileResponse $profileResponse): static
|
|
{
|
|
$communication = $profileResponse->getCommunication();
|
|
|
|
$instance = new static();
|
|
$instance
|
|
->setPhone($communication->getPhone())
|
|
->setMobile($communication->getMobile())
|
|
->setEmail($communication->getEmail())
|
|
;
|
|
|
|
return $instance;
|
|
}
|
|
|
|
public function getPhone(): ?string
|
|
{
|
|
return $this->phone;
|
|
}
|
|
|
|
public function setPhone(?string $phone): static
|
|
{
|
|
$this->phone = $phone;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getMobile(): ?string
|
|
{
|
|
return $this->mobile;
|
|
}
|
|
|
|
public function setMobile(?string $mobile): static
|
|
{
|
|
$this->mobile = $mobile;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getEmail(): ?string
|
|
{
|
|
return $this->email;
|
|
}
|
|
|
|
public function setEmail(?string $email): static
|
|
{
|
|
$this->email = $email;
|
|
|
|
return $this;
|
|
}
|
|
}
|