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'nullabletrue)]
  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(exactly10exactMessage'adviser.entity.phone.Length.message')
  91.     ]
  92.     #[Serial\Groups(['Sync'])]
  93.     private ?string $phoneNumber null;
  94.     #[ORM\Column(type'string'nullabletrue)]
  95.     #[
  96.         Assert\Length(max255)
  97.     ]
  98.     private ?string $website null;
  99.     #[ORM\Column(type'integer'nullabletrue)]
  100.     #[Assert\GreaterThanOrEqual(value0)]
  101.     #[Serial\Groups(['Sync'])]
  102.     private ?int $countEmployees null;
  103.     #[ORM\Embedded(class: Address::class)]
  104.     #[Assert\Valid()]
  105.     #[Serial\Groups(['Sync'])]
  106.     private ?AddressInterface $address null;
  107.     #[ORM\ManyToOne(targetEntityChannel::class)]
  108.     #[ORM\JoinColumn(nullablefalseonDelete'CASCADE')]
  109.     #[IdGroups(['Sync'])]
  110.     private ?Channel $channel null;
  111.     #[ORM\OneToMany(mappedBy'company'targetEntityInternship::class)]
  112.     private Collection $internships;
  113.     #[ORM\OneToMany(mappedBy'company'targetEntityCompanyChannelUserData::class, cascade: ['persist''remove'], orphanRemovaltrue)]
  114.     private Collection $companyChannelUserDatas;
  115.     #[ORM\OneToMany(mappedBy'company'targetEntityCompanyContact::class, cascade: ['persist''remove'], orphanRemovaltrue)]
  116.     #[IdGroups(['Sync'])]
  117.     private Collection $companyContacts;
  118.     public function __construct()
  119.     {
  120.         $this->initCompanyMethod();
  121.         $this->internships = new ArrayCollection();
  122.         $this->companyChannelUserDatas = new ArrayCollection();
  123.     }
  124.     public static function getSyncKey(): string
  125.     {
  126.         return EntityKeys::CHANNEL_COMPANY;
  127.     }
  128.     public function getSyncDisplayLabel(): string
  129.     {
  130.         return $this->__toString();
  131.     }
  132.     public function __toString(): string
  133.     {
  134.         return $this->getNameWithCity() ?? '';
  135.     }
  136.     public function getNameWithAddress(): ?string
  137.     {
  138.         return $this->getName() . ', ' $this->getAddress();
  139.     }
  140.     #[Serial\Groups(['Manager'])]
  141.     public function getNameWithCity(): ?string
  142.     {
  143.         return $this->getName() . ' (' $this->getAddress()?->getPostCode() . ' - ' $this->getAddress()?->getCity() . ')';
  144.     }
  145.     public function getEmail(): ?string
  146.     {
  147.         return $this->email;
  148.     }
  149.     public function setEmail(?string $email): static
  150.     {
  151.         $this->email $email;
  152.         return $this;
  153.     }
  154.     public function getAddress(): ?AddressInterface
  155.     {
  156.         return $this->address ?? $this->address = new Address();
  157.     }
  158.     /**
  159.      * @return Collection<int, Internship>
  160.      */
  161.     public function getInternships(): Collection
  162.     {
  163.         return $this->internships;
  164.     }
  165.     public function addInternship(Internship $internship): static
  166.     {
  167.         if (!$this->getInternships()->contains($internship)) {
  168.             $this->internships->add($internship);
  169.         }
  170.         return $this;
  171.     }
  172.     public function removeInternship(Internship $internship): static
  173.     {
  174.         if ($this->getInternships()->contains($internship)) {
  175.             $this->internships->removeElement($internship);
  176.         }
  177.         return $this;
  178.     }
  179.     public function getCompanyChannelUserDataFor(AdminChannelUserData $adminChannelUserData): ?CompanyChannelUserData
  180.     {
  181.         foreach ($this->getCompanyChannelUserDatas() as $companyChannelUserData) {
  182.             if ($companyChannelUserData->getChannelUserData() === $adminChannelUserData) {
  183.                 return $companyChannelUserData;
  184.             }
  185.         }
  186.         return null;
  187.     }
  188.     /**
  189.      * @return Collection<int, CompanyChannelUserData>
  190.      */
  191.     public function getCompanyChannelUserDatas(): Collection
  192.     {
  193.         return $this->companyChannelUserDatas;
  194.     }
  195.     public function addChannelUserData(AdminChannelUserData $adminChannelUserData, ?string $job null): self
  196.     {
  197.         if (!$companyChannelUserData $this->getCompanyChannelUserDataFor($adminChannelUserData)) {
  198.             $companyChannelUserData = new CompanyChannelUserData();
  199.             $companyChannelUserData->setCompany($this);
  200.             $companyChannelUserData->setChannelUserData($adminChannelUserData);
  201.             $this->companyChannelUserDatas->add($companyChannelUserData);
  202.             $adminChannelUserData->addCompany($this);
  203.         }
  204.         $companyChannelUserData->setJob($job);
  205.         return $this;
  206.     }
  207.     public function removeChannelUserData(AdminChannelUserData $adminChannelUserData): self
  208.     {
  209.         if (!$companyChannelUserData $this->getCompanyChannelUserDataFor($adminChannelUserData)) {
  210.             return $this;
  211.         }
  212.         if ($this->companyChannelUserDatas->contains($companyChannelUserData)) {
  213.             $this->companyChannelUserDatas->removeElement($companyChannelUserData);
  214.             $adminChannelUserData->removeCompany($this);
  215.         }
  216.         return $this;
  217.     }
  218.     public function getCompanyChannelContactFor(ChannelContact $channelContact): ?CompanyContact
  219.     {
  220.         foreach ($this->getCompanyContacts() as $companyContact) {
  221.             if ($companyContact->getChannelContact() === $channelContact) {
  222.                 return $companyContact;
  223.             }
  224.         }
  225.         return null;
  226.     }
  227.     public function getCompanyChannelContactForContact(Contact $contact): ?CompanyContact
  228.     {
  229.         foreach ($this->getCompanyContacts() as $companyContact) {
  230.             if ($companyContact->getChannelContact()?->getContact() === $contact) {
  231.                 return $companyContact;
  232.             }
  233.         }
  234.         return null;
  235.     }
  236.     public function addChannelContact(ChannelContact $channelContact, ?string $behavior null): self
  237.     {
  238.         if (!$companyContact $this->getCompanyChannelContactFor($channelContact)) {
  239.             $companyContact = new CompanyContact();
  240.             $companyContact->setCompany($this);
  241.             $companyContact->setChannelContact($channelContact);
  242.             $this->addCompanyContact($companyContact);
  243.         }
  244.         if ($behavior) {
  245.             $companyContact->addBehavior($behavior);
  246.         }
  247.         return $this;
  248.     }
  249.     public function getContacts(): Collection
  250.     {
  251.         return $this->getCompanyContacts()
  252.             ->map(function (CompanyContact $companyContact) {
  253.                 return $companyContact->getChannelContact()->getContact();
  254.             });
  255.     }
  256.     public function getLegalForm(): ?string
  257.     {
  258.         return $this->legalForm;
  259.     }
  260.     public function setLegalForm(?string $legalForm): Company
  261.     {
  262.         $this->legalForm $legalForm;
  263.         return $this;
  264.     }
  265.     public function getIndustry(): ?string
  266.     {
  267.         return $this->industry;
  268.     }
  269.     public function setIndustry(?string $industry): Company
  270.     {
  271.         $this->industry $industry;
  272.         return $this;
  273.     }
  274.     public function getCountEmployees(): ?int
  275.     {
  276.         return $this->countEmployees;
  277.     }
  278.     public function setCountEmployees(?int $countEmployees): Company
  279.     {
  280.         $this->countEmployees $countEmployees;
  281.         return $this;
  282.     }
  283.     public function getWebsite(): ?string
  284.     {
  285.         return $this->website;
  286.     }
  287.     public function setWebsite(?string $website): Company
  288.     {
  289.         $this->website $website;
  290.         return $this;
  291.     }
  292. }