src/Entity/Channel/Company.php line 32

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Channel;
  3. use App\Entity\ChannelUserData\AdminChannelUserData;
  4. use App\Entity\ChannelUserData\Cursus\Internship;
  5. use App\Entity\Common\Address;
  6. use App\Entity\Common\Contact;
  7. use App\Entity\Sync\SyncableInterface;
  8. use App\Enum\FrenchProfessionalLegalFormEnum;
  9. use App\Repository\Channel\CompanyRepository;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Doctrine\Common\Collections\Collection;
  12. use Doctrine\ORM\Mapping as ORM;
  13. use Drosalys\Bundle\ApiBundle\Serializer\Attributes\IdGroups;
  14. use DrosalysWeb\ObjectExtensions\Blame\Model\BlameInterface;
  15. use DrosalysWeb\ObjectExtensions\Blame\Model\BlameTrait;
  16. use DrosalysWeb\ObjectExtensions\Timestamp\Model\TimestampInterface;
  17. use DrosalysWeb\ObjectExtensions\Timestamp\Model\TimestampTrait;
  18. use Nellapp\Bundle\SDKBundle\Channel\Entity\Company\CompanyInterface;
  19. use Nellapp\Bundle\SDKBundle\Channel\Entity\Company\CompanyMethodTrait;
  20. use Nellapp\Bundle\SDKBundle\Entity\Common\Address\AddressInterface;
  21. use Nellapp\Bundle\SDKBundle\Enum\Company\IndustryEnum;
  22. use Nellapp\Bundle\SDKBundle\Sync\EntityKeys;
  23. use Symfony\Component\Serializer\Annotation as Serial;
  24. use Symfony\Component\Validator\Constraints as Assert;
  25. #[
  26.     ORM\Entity(repositoryClassCompanyRepository::class),
  27.     ORM\Table(name'channel_company'),
  28. ]
  29. class Company implements TimestampInterfaceBlameInterfaceCompanyInterfaceSyncableInterface
  30. {
  31.     use TimestampTrait;
  32.     use BlameTrait;
  33.     use CompanyMethodTrait;
  34.     #[
  35.         ORM\Id,
  36.         ORM\GeneratedValue(strategy'NONE'),
  37.         ORM\Column(type'string'length36)
  38.     ]
  39.     #[Serial\Groups(['Manager''Sync'])]
  40.     private ?string $id null;
  41.     #[ORM\Column(type'string')]
  42.     #[
  43.         Assert\NotBlank,
  44.         Assert\Length(
  45.             min2,
  46.             max255,
  47.         ),
  48.     ]
  49.     #[Serial\Groups(['Manager''Sync'])]
  50.     private ?string $name null;
  51.     #[ORM\Column(type'string'length14nullabletrue)]
  52.     #[
  53.         Assert\Length(
  54.             min9,
  55.             max14,
  56.             minMessage'channel.professional_id.french.siret.Length.min',
  57.             maxMessage'channel.professional_id.french.siret.Length.max',
  58.         ),
  59.         Assert\Luhn(
  60.             message'channel.professional_id.french.siret.luhn'
  61.         ),
  62.     ]
  63.     #[Serial\Groups(['Sync'])]
  64.     private ?string $siret null;
  65.     #[ORM\Column(type'string'length20nullabletrue)]
  66.     #[Assert\Choice(callback: [FrenchProfessionalLegalFormEnum::class, 'getChoices'])]
  67.     #[Serial\Groups(['Sync'])]
  68.     private ?string $legalForm null;
  69.     #[ORM\Column(type'string'length32nullabletrue)]
  70.     #[
  71.         Assert\Choice(callback: [IndustryEnum::class, 'getChoices']),
  72.     ]
  73.     #[Serial\Groups(['Sync'])]
  74.     private ?string $industry null;
  75.     #[ORM\Column(type'string'nullabletrue)]
  76.     #[
  77.         Assert\NotBlank(message'user.entity.email.NotBlank'),
  78.         Assert\Email(message'user.entity.email.Email'mode'strict'),
  79.         Assert\Length(
  80.             min6,
  81.             max64,
  82.             minMessage'user.entity.email.Length.min',
  83.             maxMessage'user.entity.email.Length.max',
  84.         )
  85.     ]
  86.     #[Serial\Groups(['Sync'])]
  87.     private ?string $email null;
  88.     #[ORM\Column(type'string'nullabletrue)]
  89.     #[
  90.         Assert\Length(
  91.             min8,
  92.             max20,
  93.             minMessage'user.entity.phone.Length.min',
  94.             maxMessage'user.entity.phone.Length.max',
  95.         )
  96.     ]
  97.     #[Serial\Groups(['Sync'])]
  98.     private ?string $phoneNumber null;
  99.     #[ORM\Column(type'string'nullabletrue)]
  100.     #[
  101.         Assert\Length(max255)
  102.     ]
  103.     private ?string $website null;
  104.     #[ORM\Column(type'integer'nullabletrue)]
  105.     #[Assert\GreaterThanOrEqual(value0)]
  106.     #[Serial\Groups(['Sync'])]
  107.     private ?int $countEmployees null;
  108.     #[ORM\Embedded(class: Address::class)]
  109.     #[Assert\Valid()]
  110.     #[Serial\Groups(['Sync'])]
  111.     private ?AddressInterface $address null;
  112.     #[ORM\ManyToOne(targetEntityChannel::class)]
  113.     #[ORM\JoinColumn(nullablefalseonDelete'CASCADE')]
  114.     #[IdGroups(['Sync'])]
  115.     private ?Channel $channel null;
  116.     #[ORM\OneToMany(mappedBy'company'targetEntityInternship::class)]
  117.     private Collection $internships;
  118.     #[ORM\OneToMany(mappedBy'company'targetEntityCompanyChannelUserData::class, cascade: ['persist''remove'], orphanRemovaltrue)]
  119.     private Collection $companyChannelUserDatas;
  120.     #[ORM\OneToMany(mappedBy'company'targetEntityCompanyContact::class, cascade: ['persist''remove'], orphanRemovaltrue)]
  121.     #[IdGroups(['Sync'])]
  122.     private Collection $companyContacts;
  123.     public function __construct()
  124.     {
  125.         $this->initCompanyMethod();
  126.         $this->internships = new ArrayCollection();
  127.         $this->companyChannelUserDatas = new ArrayCollection();
  128.     }
  129.     public static function getSyncKey(): string
  130.     {
  131.         return EntityKeys::CHANNEL_COMPANY;
  132.     }
  133.     public function getSyncDisplayLabel(): string
  134.     {
  135.         return $this->__toString();
  136.     }
  137.     public function __toString(): string
  138.     {
  139.         return $this->getNameWithCity() ?? '';
  140.     }
  141.     public function getNameWithAddress(): ?string
  142.     {
  143.         return $this->getName() . ', ' $this->getAddress();
  144.     }
  145.     #[Serial\Groups(['Manager'])]
  146.     public function getNameWithCity(): ?string
  147.     {
  148.         return $this->getName() . ' (' $this->getAddress()?->getPostCode() . ' - ' $this->getAddress()?->getCity() . ')';
  149.     }
  150.     public function getEmail(): ?string
  151.     {
  152.         return $this->email;
  153.     }
  154.     public function setEmail(?string $email): static
  155.     {
  156.         $this->email $email;
  157.         return $this;
  158.     }
  159.     public function getAddress(): ?AddressInterface
  160.     {
  161.         return $this->address ?? $this->address = new Address();
  162.     }
  163.     /**
  164.      * @return Collection<int, Internship>
  165.      */
  166.     public function getInternships(): Collection
  167.     {
  168.         return $this->internships;
  169.     }
  170.     public function addInternship(Internship $internship): static
  171.     {
  172.         if (!$this->getInternships()->contains($internship)) {
  173.             $this->internships->add($internship);
  174.         }
  175.         return $this;
  176.     }
  177.     public function removeInternship(Internship $internship): static
  178.     {
  179.         if ($this->getInternships()->contains($internship)) {
  180.             $this->internships->removeElement($internship);
  181.         }
  182.         return $this;
  183.     }
  184.     public function getCompanyChannelUserDataFor(AdminChannelUserData $adminChannelUserData): ?CompanyChannelUserData
  185.     {
  186.         foreach ($this->getCompanyChannelUserDatas() as $companyChannelUserData) {
  187.             if ($companyChannelUserData->getChannelUserData() === $adminChannelUserData) {
  188.                 return $companyChannelUserData;
  189.             }
  190.         }
  191.         return null;
  192.     }
  193.     /**
  194.      * @return Collection<int, CompanyChannelUserData>
  195.      */
  196.     public function getCompanyChannelUserDatas(): Collection
  197.     {
  198.         return $this->companyChannelUserDatas;
  199.     }
  200.     public function addChannelUserData(AdminChannelUserData $adminChannelUserData, ?string $job null): self
  201.     {
  202.         if (!$companyChannelUserData $this->getCompanyChannelUserDataFor($adminChannelUserData)) {
  203.             $companyChannelUserData = new CompanyChannelUserData();
  204.             $companyChannelUserData->setCompany($this);
  205.             $companyChannelUserData->setChannelUserData($adminChannelUserData);
  206.             $this->companyChannelUserDatas->add($companyChannelUserData);
  207.             $adminChannelUserData->addCompany($this);
  208.         }
  209.         $companyChannelUserData->setJob($job);
  210.         return $this;
  211.     }
  212.     public function removeChannelUserData(AdminChannelUserData $adminChannelUserData): self
  213.     {
  214.         if (!$companyChannelUserData $this->getCompanyChannelUserDataFor($adminChannelUserData)) {
  215.             return $this;
  216.         }
  217.         if ($this->companyChannelUserDatas->contains($companyChannelUserData)) {
  218.             $this->companyChannelUserDatas->removeElement($companyChannelUserData);
  219.             $adminChannelUserData->removeCompany($this);
  220.         }
  221.         return $this;
  222.     }
  223.     public function getCompanyChannelContactFor(ChannelContact $channelContact): ?CompanyContact
  224.     {
  225.         foreach ($this->getCompanyContacts() as $companyContact) {
  226.             if ($companyContact->getChannelContact() === $channelContact) {
  227.                 return $companyContact;
  228.             }
  229.         }
  230.         return null;
  231.     }
  232.     public function getCompanyChannelContactForContact(Contact $contact): ?CompanyContact
  233.     {
  234.         foreach ($this->getCompanyContacts() as $companyContact) {
  235.             if ($companyContact->getChannelContact()?->getContact() === $contact) {
  236.                 return $companyContact;
  237.             }
  238.         }
  239.         return null;
  240.     }
  241.     public function addChannelContact(ChannelContact $channelContact, ?string $behavior null): self
  242.     {
  243.         if (!$companyContact $this->getCompanyChannelContactFor($channelContact)) {
  244.             $companyContact = new CompanyContact();
  245.             $companyContact->setCompany($this);
  246.             $companyContact->setChannelContact($channelContact);
  247.             $this->addCompanyContact($companyContact);
  248.         }
  249.         if ($behavior) {
  250.             $companyContact->addBehavior($behavior);
  251.         }
  252.         return $this;
  253.     }
  254.     public function getContacts(): Collection
  255.     {
  256.         return $this->getCompanyContacts()
  257.             ->map(function (CompanyContact $companyContact) {
  258.                 return $companyContact->getChannelContact()->getContact();
  259.             });
  260.     }
  261.     public function getLegalForm(): ?string
  262.     {
  263.         return $this->legalForm;
  264.     }
  265.     public function setLegalForm(?string $legalForm): Company
  266.     {
  267.         $this->legalForm $legalForm;
  268.         return $this;
  269.     }
  270.     public function getWebsite(): ?string
  271.     {
  272.         return $this->website;
  273.     }
  274.     public function setWebsite(?string $website): Company
  275.     {
  276.         $this->website $website;
  277.         return $this;
  278.     }
  279. }