src/Entity/Common/Contact.php line 37

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Common;
  3. use App\Entity\Account\User;
  4. use App\Entity\Sync\SyncableInterface;
  5. use App\Repository\Common\ContactRepository;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use DrosalysWeb\ObjectExtensions\Blame\Model\BlameInterface;
  8. use DrosalysWeb\ObjectExtensions\Blame\Model\BlameTrait;
  9. use DrosalysWeb\ObjectExtensions\Timestamp\Model\TimestampInterface;
  10. use DrosalysWeb\ObjectExtensions\Timestamp\Model\TimestampTrait;
  11. use Nellapp\Bundle\SDKBundle\Channel\Entity\Contact\ContactInterface;
  12. use Nellapp\Bundle\SDKBundle\Channel\Entity\Contact\ContactMethodTrait;
  13. use Nellapp\Bundle\SDKBundle\Entity\Common\Address\Address;
  14. use Nellapp\Bundle\SDKBundle\Entity\Common\Address\AddressInterface;
  15. use Nellapp\Bundle\SDKBundle\Sync\EntityKeys;
  16. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  17. use Symfony\Component\Serializer\Annotation as Serial;
  18. use Symfony\Component\Uid\Uuid;
  19. use Symfony\Component\Validator\Constraints as Assert;
  20. #[UniqueEntity(
  21.     fields: ['email'],
  22.     message'contact.email.UniqueEntity',
  23.     errorPath'email',
  24.     groups: ['check_unique'],
  25. )]
  26. #[
  27.     ORM\Entity(repositoryClassContactRepository::class),
  28.     ORM\UniqueConstraint(fields: ['email']),
  29.     ORM\Table(name'contacts'),
  30.     ORM\Index(fields: ['email'], flags: ['fulltext']),
  31.     ORM\Index(fields: ['firstName'], flags: ['fulltext']),
  32.     ORM\Index(fields: ['lastName'], flags: ['fulltext']),
  33. ]
  34. class Contact implements TimestampInterfaceBlameInterfaceContactInterfaceSyncableInterface
  35. {
  36.     use TimestampTrait;
  37.     use BlameTrait;
  38.     use ContactMethodTrait;
  39.     #[
  40.         ORM\Id,
  41.         ORM\GeneratedValue(strategy'NONE'),
  42.         ORM\Column(type'string'length36)
  43.     ]
  44.     #[Serial\Groups(['Manager''Sync'])]
  45.     private ?string $id null;
  46.     #[ORM\Column(type'string'length180uniquetrue)]
  47.     #[Serial\Groups(['Manager''Sync'])]
  48.     #[
  49.         Assert\NotBlank(message'contact.email.NotBlank'),
  50.         Assert\Email(message'contact.email.Email'mode'strict'),
  51.         Assert\Length(
  52.             min6,
  53.             max64,
  54.             minMessage'contact.email.Length.min',
  55.             maxMessage'contact.email.Length.max',
  56.         )
  57.     ]
  58.     private ?string $email null;
  59.     #[ORM\Column(type'string'nullabletrue)]
  60.     #[Serial\Groups(['Manager''Sync'])]
  61.     #[
  62.         Assert\Length(
  63.             min2,
  64.             max255,
  65.             minMessage'contact.firstName.Length.min',
  66.             maxMessage'contact.firstName.Length.max',
  67.         )
  68.     ]
  69.     private ?string $firstName null;
  70.     #[ORM\Column(type'string'nullabletrue)]
  71.     #[Serial\Groups(['Manager''Sync'])]
  72.     #[
  73.         Assert\Length(
  74.             min2,
  75.             max255,
  76.             minMessage'contact.lastName.Length.min',
  77.             maxMessage'contact.lastName.Length.max',
  78.         )
  79.     ]
  80.     private ?string $lastName null;
  81.     #[ORM\Column(type'string'length20nullabletrue)]
  82.     #[Serial\Groups(['Manager''Sync'])]
  83.     #[
  84.         Assert\Length(
  85.             min8,
  86.             max20,
  87.             minMessage'contact.phoneNumber.Length.min',
  88.             maxMessage'contact.phoneNumber.Length.max',
  89.         )
  90.     ]
  91.     private ?string $phoneNumber null;
  92.     #[ORM\Embedded(class: Address::class)]
  93.     #[Assert\Valid()]
  94.     #[Serial\Groups(['Sync'])]
  95.     private ?AddressInterface $address null;
  96.     #[ORM\OneToOne(mappedBy'contact'targetEntityUser::class, fetch'LAZY')]
  97.     private ?User $user null;
  98.     public function __construct()
  99.     {
  100.         $this->initContactMethod();
  101.     }
  102.     protected function initContactMethod(): void
  103.     {
  104.         $this->id Uuid::v4()->toRfc4122();
  105.         $this->address = new Address();
  106.     }
  107.     public static function getSyncKey(): string
  108.     {
  109.         return EntityKeys::CONTACT;
  110.     }
  111.     public function getSyncDisplayLabel(): string
  112.     {
  113.         return 'Contact ' $this->__toString();
  114.     }
  115.     public function getFullName(): string
  116.     {
  117.         return trim(($this->getFirstName() ?: '') . ' ' . ($this->getLastName() ?: ''));
  118.     }
  119.     #[Serial\Groups(['Manager'])]
  120.     public function getFullNameWithEmail(): string
  121.     {
  122.         return trim(($this->getFullName() ?: '') . ' (' $this->getEmail() . ')');
  123.     }
  124.     public function getUser(): ?User
  125.     {
  126.         return $this->user;
  127.     }
  128. }