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.     // TODO: move Timestamp and Blame to ChannelContact
  37.     use TimestampTrait;
  38.     use BlameTrait;
  39.     use ContactMethodTrait;
  40.     #[
  41.         ORM\Id,
  42.         ORM\GeneratedValue(strategy'NONE'),
  43.         ORM\Column(type'string'length36)
  44.     ]
  45.     #[Serial\Groups(['Manager''Sync'])]
  46.     private ?string $id null;
  47.     #[ORM\Column(type'string'length180uniquetrue)]
  48.     #[Serial\Groups(['Manager''Sync'])]
  49.     #[
  50.         Assert\NotBlank(message'contact.email.NotBlank'),
  51.         Assert\Email(message'contact.email.Email'mode'strict'),
  52.         Assert\Length(
  53.             min6,
  54.             max64,
  55.             minMessage'contact.email.Length.min',
  56.             maxMessage'contact.email.Length.max',
  57.         )
  58.     ]
  59.     private ?string $email null;
  60.     #[ORM\Column(type'string'nullabletrue)]
  61.     #[Serial\Groups(['Manager''Sync'])]
  62.     #[
  63.         Assert\NotBlank(message'contact.firstName.NotBlank'),
  64.         Assert\Length(
  65.             min2,
  66.             max255,
  67.             minMessage'contact.firstName.Length.min',
  68.             maxMessage'contact.firstName.Length.max',
  69.         )
  70.     ]
  71.     private ?string $firstName null;
  72.     #[ORM\Column(type'string'nullabletrue)]
  73.     #[Serial\Groups(['Manager''Sync'])]
  74.     #[
  75.         Assert\NotBlank(message'contact.lastName.NotBlank'),
  76.         Assert\Length(
  77.             min2,
  78.             max255,
  79.             minMessage'contact.lastName.Length.min',
  80.             maxMessage'contact.lastName.Length.max',
  81.         )
  82.     ]
  83.     private ?string $lastName null;
  84.     #[ORM\Column(type'string'length20nullabletrue)]
  85.     #[Serial\Groups(['Manager''Sync'])]
  86.     #[
  87.         Assert\Length(
  88.             min8,
  89.             max20,
  90.             minMessage'contact.phoneNumber.Length.min',
  91.             maxMessage'contact.phoneNumber.Length.max',
  92.         )
  93.     ]
  94.     private ?string $phoneNumber null;
  95.     #[ORM\Embedded(class: Address::class)]
  96.     #[Assert\Valid()]
  97.     #[Serial\Groups(['Sync'])]
  98.     private ?AddressInterface $address null;
  99.     #[ORM\OneToOne(mappedBy'contact'targetEntityUser::class, fetch'LAZY')]
  100.     private ?User $user null;
  101.     public function __construct()
  102.     {
  103.         $this->initContactMethod();
  104.     }
  105.     public static function getSyncKey(): string
  106.     {
  107.         return EntityKeys::CONTACT;
  108.     }
  109.     public function getSyncDisplayLabel(): string
  110.     {
  111.         return 'Contact ' $this->__toString();
  112.     }
  113.     public function getFullName(): string
  114.     {
  115.         return trim(($this->getFirstName() ?: '') . ' ' . ($this->getLastName() ?: ''));
  116.     }
  117.     #[Serial\Groups(['Manager'])]
  118.     public function getFullNameWithEmail(): string
  119.     {
  120.         return trim(($this->getFullName() ?: '') . ' (' $this->getEmail() . ')');
  121.     }
  122.     public function getUser(): ?User
  123.     {
  124.         return $this->user;
  125.     }
  126. }