src/Entity/Channel/CompanyContact.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Channel;
  3. use App\Entity\Common\Contact;
  4. use App\Entity\Sync\SyncableInterface;
  5. use App\Repository\Channel\CompanyContactRepository;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Drosalys\Bundle\ApiBundle\Serializer\Attributes\IdGroups;
  8. use Nellapp\Bundle\SDKBundle\Channel\Entity\CompanyContact\CompanyContactInterface;
  9. use Nellapp\Bundle\SDKBundle\Channel\Entity\CompanyContact\CompanyContactMethodTrait;
  10. use Nellapp\Bundle\SDKBundle\Enum\CompanyContact\CompanyContactBehaviorEnum;
  11. use Nellapp\Bundle\SDKBundle\Sync\EntityKeys;
  12. use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
  13. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  14. use Symfony\Component\Serializer\Annotation as Serial;
  15. use Symfony\Component\Validator\Constraints as Assert;
  16. #[
  17.     ORM\Entity(repositoryClassCompanyContactRepository::class),
  18.     ORM\Table(name'channel_company_contacts'),
  19.     UniqueEntity(fields: ['channelContact''company'], message'channel.company_contact.UniqueEntity')
  20. ]
  21. class CompanyContact implements CompanyContactInterfaceSyncableInterface
  22. {
  23.     use CompanyContactMethodTrait;
  24.     #[
  25.         ORM\Id,
  26.         ORM\GeneratedValue(strategy'NONE'),
  27.         ORM\Column(type'string'length36)
  28.     ]
  29.     #[Serial\Groups(['Sync''Manager'])]
  30.     private ?string $id null;
  31.     #[ORM\Column(type'json')]
  32.     #[Serial\Groups(['Sync'])]
  33.     private array $behaviors = [];
  34.     #[ORM\ManyToOne(targetEntityCompany::class, inversedBy'companyContacts')]
  35.     #[ORM\JoinColumn(nullablefalseonDelete'CASCADE')]
  36.     #[IdGroups(['Sync'])]
  37.     private Company $company;
  38.     #[ORM\ManyToOne(targetEntityChannelContact::class, cascade: ['persist'], inversedBy'companyContacts')]
  39.     #[ORM\JoinColumn(nullablefalseonDelete'CASCADE')]
  40.     #[
  41.         Assert\NotBlank(),
  42.         Assert\Valid(),
  43.     ]
  44.     #[IdGroups(['Sync'])]
  45.     private ChannelContact $channelContact;
  46.     public function __construct()
  47.     {
  48.         $this->initCompanyContactMethod();
  49.     }
  50.     public static function getSyncKey(): string
  51.     {
  52.         return EntityKeys::CHANNEL_COMPANY_CONTACT;
  53.     }
  54.     public function getSyncDisplayLabel(): string
  55.     {
  56.         return 'Contact entreprise : ' $this->getContact()->__toString();
  57.     }
  58.     public function toggleRepresentative(): static
  59.     {
  60.         if ($this->isRepresentative()) {
  61.             $this->setRepresentative(false);
  62.             return $this;
  63.         }
  64.         $this->setRepresentative(true);
  65.         return $this;
  66.     }
  67.     public function setRepresentative(bool $representative): static
  68.     {
  69.         if ($representative) {
  70.             $this->setBehaviors(array_merge($this->getBehaviors(), [CompanyContactBehaviorEnum::REPRESENTATIVE]));
  71.             return $this;
  72.         }
  73.         $this->setBehaviors(array_filter($this->behaviors, function (string $behavior): bool {
  74.             return $behavior !== CompanyContactBehaviorEnum::REPRESENTATIVE;
  75.         }));
  76.         return $this;
  77.     }
  78. }