src/Entity/Channel/Company.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Channel;
  3. use App\Entity\Crm\Opportunity\Opportunity;
  4. use App\Entity\Crm\Target\TargetableInterface;
  5. use App\Enum\TargetTypeEnum;
  6. use App\Enum\Serialization\CompanySerializationGroups;
  7. use App\Enum\Serialization\ReverseSyncSerializationGroups;
  8. use App\Repository\Channel\CompanyRepository;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use Drosalys\Bundle\ApiBundle\Serializer\Attributes\IdGroups;
  13. use Nellapp\Bundle\SDKBundle\Channel\Entity\Company\CompanyInterface;
  14. use Nellapp\Bundle\SDKBundle\Channel\Entity\Company\CompanyMethodTrait;
  15. use Nellapp\Bundle\SDKBundle\Entity\Common\Address\Address;
  16. use Nellapp\Bundle\SDKBundle\Enum\Company\IndustryEnum;
  17. use Nellapp\Bundle\SDKBundle\ReverseSync\Entity\ReverseSyncableInterface;
  18. use Nellapp\Bundle\SDKBundle\ReverseSync\EntityKeys;
  19. use Symfony\Component\Serializer\Annotation as Serial;
  20. use Symfony\Component\Validator\Constraints as Assert;
  21. #[
  22.     ORM\Entity(repositoryClassCompanyRepository::class),
  23.     ORM\Table(name'channel_company'),
  24. ]
  25. class Company implements CompanyInterfaceTargetableInterfaceReverseSyncableInterface
  26. {
  27.     use CompanyMethodTrait;
  28.     #[
  29.         ORM\Id,
  30.         ORM\GeneratedValue(strategy'NONE'),
  31.         ORM\Column(type'string'length36)
  32.     ]
  33.     #[Serial\Groups([
  34.         CompanySerializationGroups::COLLECTION,
  35.         CompanySerializationGroups::DETAIL,
  36.         ReverseSyncSerializationGroups::REVERSE_SYNC,
  37.     ])]
  38.     private ?string $id null;
  39.     #[ORM\Column(type'string')]
  40.     #[Serial\Groups([
  41.         CompanySerializationGroups::COLLECTION,
  42.         CompanySerializationGroups::DETAIL,
  43.         CompanySerializationGroups::CREATE,
  44.         ReverseSyncSerializationGroups::REVERSE_SYNC,
  45.     ])]
  46.     #[
  47.         Assert\NotBlank,
  48.         Assert\Length(
  49.             min2,
  50.             max255,
  51.         ),
  52.     ]
  53.     private ?string $name null;
  54.     #[ORM\Column(type'string'nullabletrue)]
  55.     #[
  56.         Assert\NotBlank(message'user.entity.email.NotBlank'),
  57.         Assert\Email(message'user.entity.email.Email'mode'strict'),
  58.         Assert\Length(
  59.             min6,
  60.             max64,
  61.         )
  62.     ]
  63.     #[Serial\Groups([
  64.         CompanySerializationGroups::CREATE,
  65.         ReverseSyncSerializationGroups::REVERSE_SYNC,
  66.     ])]
  67.     private ?string $email null;
  68.     #[ORM\Column(type'string'length14nullabletrue)]
  69.     #[Serial\Groups([
  70.         CompanySerializationGroups::COLLECTION,
  71.         CompanySerializationGroups::DETAIL,
  72.         CompanySerializationGroups::CREATE,
  73.         ReverseSyncSerializationGroups::REVERSE_SYNC,
  74.     ])]
  75.     #[
  76.         Assert\Length(
  77.             min9,
  78.             max14,
  79.         ),
  80.         Assert\Luhn(
  81.             message'channel.professional_id.french.siret.luhn'
  82.         ),
  83.     ]
  84.     private ?string $siret null;
  85.     #[ORM\Column(type'string'length32nullabletrue)]
  86.     #[
  87.         Assert\Choice(callback: [IndustryEnum::class, 'getChoices']),
  88.     ]
  89.     #[Serial\Groups([
  90.         CompanySerializationGroups::COLLECTION,
  91.         CompanySerializationGroups::DETAIL,
  92.         CompanySerializationGroups::CREATE,
  93.         ReverseSyncSerializationGroups::REVERSE_SYNC,
  94.     ])]
  95.     private ?string $industry null;
  96.     #[ORM\Column(type'string'nullabletrue)]
  97.     #[Serial\Groups([
  98.         CompanySerializationGroups::COLLECTION,
  99.         CompanySerializationGroups::DETAIL,
  100.         CompanySerializationGroups::CREATE,
  101.         ReverseSyncSerializationGroups::REVERSE_SYNC,
  102.     ])]
  103.     #[
  104.         Assert\Length(
  105.             min8,
  106.             max20,
  107.         )
  108.     ]
  109.     private ?string $phoneNumber null;
  110.     #[ORM\Column(type'integer'nullabletrue)]
  111.     #[Assert\GreaterThanOrEqual(value0)]
  112.     #[Serial\Groups([
  113.         CompanySerializationGroups::COLLECTION,
  114.         CompanySerializationGroups::DETAIL,
  115.         CompanySerializationGroups::CREATE,
  116.         ReverseSyncSerializationGroups::REVERSE_SYNC,
  117.     ])]
  118.     private ?int $countEmployees null;
  119.     #[ORM\Embedded(class: Address::class)]
  120.     private ?Address $address null;
  121.     #[ORM\ManyToOne(targetEntityChannel::class)]
  122.     #[ORM\JoinColumn(nullablefalseonDelete"CASCADE")]
  123.     #[IdGroups([ReverseSyncSerializationGroups::REVERSE_SYNC])]
  124.     private ?Channel $channel null;
  125.     #[ORM\OneToMany(mappedBy'targetCompany'targetEntityOpportunity::class)]
  126.     private Collection $opportunities;
  127.     #[ORM\OneToMany(mappedBy'company'targetEntityCompanyContact::class, cascade: ['persist''remove'], orphanRemovaltrue)]
  128.     #[Assert\Valid()]
  129.     private Collection $companyContacts;
  130.     public function __construct()
  131.     {
  132.         $this->initCompanyMethod();
  133.         $this->opportunities = new ArrayCollection();
  134.     }
  135.     public function __toString(): string
  136.     {
  137.         return $this->getDisplayName();
  138.     }
  139.     public static function getReverseSyncKey(): string
  140.     {
  141.         return EntityKeys::COMPANY;
  142.     }
  143.     public function getDisplayName(): string
  144.     {
  145.         return $this->name ?? '';
  146.     }
  147.     public function getOpportunityTargetType(): string
  148.     {
  149.         return TargetTypeEnum::COMPANY;
  150.     }
  151.     #[Serial\Groups([
  152.         CompanySerializationGroups::COLLECTION,
  153.         CompanySerializationGroups::DETAIL,
  154.     ])]
  155.     public function getFullAddress(): ?string
  156.     {
  157.         return $this->address?->toMultiLine();
  158.     }
  159.     public function getPostCodeAndCity(): string
  160.     {
  161.         return $this->address?->getPostCodeAndCity() ?? '';
  162.     }
  163.     /**
  164.      * @return Collection<int, Opportunity>
  165.      */
  166.     public function getOpportunities(): Collection
  167.     {
  168.         return $this->opportunities;
  169.     }
  170.     public function addOpportunity(Opportunity $opportunity): static
  171.     {
  172.         if (!$this->opportunities->contains($opportunity)) {
  173.             $this->opportunities->add($opportunity);
  174.             $opportunity->setTargetCompany($this);
  175.         }
  176.         return $this;
  177.     }
  178.     public function removeOpportunity(Opportunity $opportunity): static
  179.     {
  180.         if ($this->opportunities->removeElement($opportunity)) {
  181.             // set the owning side to null (unless already changed)
  182.             if ($opportunity->getTargetCompany() === $this) {
  183.                 $opportunity->setTargetCompany(null);
  184.             }
  185.         }
  186.         return $this;
  187.     }
  188. }