src/Entity/Channel/CompanyContact.php line 23

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\Validator\Constraints\UniqueEntity;
  13. use Symfony\Component\Serializer\Annotation as Serial;
  14. use Symfony\Component\Validator\Constraints as Assert;
  15. #[
  16.     ORM\Entity(repositoryClassCompanyContactRepository::class),
  17.     ORM\Table(name'channel_company_contacts'),
  18.     UniqueEntity(fields: ['channelContact''company'], message'channel.company_contact.UniqueEntity')
  19. ]
  20. class CompanyContact implements CompanyContactInterfaceSyncableInterface
  21. {
  22.     use CompanyContactMethodTrait;
  23.     #[
  24.         ORM\Id,
  25.         ORM\GeneratedValue(strategy'NONE'),
  26.         ORM\Column(type'string'length36)
  27.     ]
  28.     #[Serial\Groups(['Sync''Manager'])]
  29.     private ?string $id null;
  30.     #[ORM\Column(type'json')]
  31.     #[Serial\Groups(['Sync'])]
  32.     private array $behaviors = [];
  33.     #[ORM\ManyToOne(targetEntityCompany::class, inversedBy'companyContacts')]
  34.     #[ORM\JoinColumn(nullablefalseonDelete'CASCADE')]
  35.     #[IdGroups(['Sync'])]
  36.     private Company $company;
  37.     #[ORM\ManyToOne(targetEntityChannelContact::class, cascade: ['persist'], inversedBy'companyContacts')]
  38.     #[ORM\JoinColumn(nullablefalseonDelete'CASCADE')]
  39.     #[
  40.         Assert\NotBlank(),
  41.         Assert\Valid(),
  42.     ]
  43.     #[IdGroups(['Sync'])]
  44.     private ChannelContact $channelContact;
  45.     public function __construct()
  46.     {
  47.         $this->initCompanyContactMethod();
  48.     }
  49.     public static function getSyncKey(): string
  50.     {
  51.         return EntityKeys::CHANNEL_COMPANY_CONTACT;
  52.     }
  53.     public function getSyncDisplayLabel(): string
  54.     {
  55.         return 'Contact entreprise : ' . ($this->getChannelContact()?->getContact()?->__toString() ?? 'N/A');
  56.     }
  57.     public function toggleRepresentative(): static
  58.     {
  59.         if ($this->isRepresentative()) {
  60.             $this->setRepresentative(false);
  61.             return $this;
  62.         }
  63.         $this->setRepresentative(true);
  64.         return $this;
  65.     }
  66.     public function setRepresentative(bool $representative): static
  67.     {
  68.         if ($representative) {
  69.             $this->setBehaviors(array_merge($this->getBehaviors(), [CompanyContactBehaviorEnum::REPRESENTATIVE]));
  70.             return $this;
  71.         }
  72.         $this->setBehaviors(array_filter($this->behaviors, function (string $behavior): bool {
  73.             return $behavior !== CompanyContactBehaviorEnum::REPRESENTATIVE;
  74.         }));
  75.         return $this;
  76.     }
  77. }