src/Entity/Channel/Organization.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Channel;
  3. use App\Entity\Channel\Certificate\CursusStartCertificate;
  4. use App\Entity\Channel\ProfessionalId\ProfessionalId;
  5. use App\Entity\Common\Address;
  6. use App\Entity\Sync\SyncableInterface;
  7. use App\Enum\Channel\FileOrganizationTagEnum;
  8. use App\Repository\Channel\OrganizationRepository;
  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\Organization\OrganizationInterface;
  14. use Nellapp\Bundle\SDKBundle\Channel\Entity\Organization\OrganizationMethodTrait;
  15. use Nellapp\Bundle\SDKBundle\Entity\Common\Address\AddressInterface;
  16. use Nellapp\Bundle\SDKBundle\Sync\EntityKeys;
  17. use Symfony\Component\Validator\Constraints as Assert;
  18. use Symfony\Component\Serializer\Annotation as Serial;
  19. #[
  20.     ORM\Entity(repositoryClassOrganizationRepository::class),
  21.     ORM\Table('channel_organizations')
  22. ]
  23. class Organization implements \StringableOrganizationInterfaceSyncableInterface
  24. {
  25.     use OrganizationMethodTrait;
  26.     #[ORM\IdORM\GeneratedValueORM\Column(type'integer')]
  27.     #[Serial\Groups(['Manager''Sync'])]
  28.     private ?int $id null;
  29.     #[ORM\ManyToOne(targetEntityChannel::class, inversedBy'organizations')]
  30.     #[ORM\JoinColumn(nullablefalseonDelete'CASCADE')]
  31.     #[IdGroups(['Sync'])]
  32.     private ?Channel $channel null;
  33.     #[ORM\Column(type'string'length63)]
  34.     #[Assert\NotBlank(
  35.         message'channel.organization.name.NotBlank',
  36.     )]
  37.     #[Assert\Length(
  38.         min2,
  39.         max63,
  40.         minMessage'channel.organization.name.Length.min',
  41.         maxMessage'channel.organization.name.Length.max',
  42.     )]
  43.     #[Serial\Groups(['Manager''Sync'])]
  44.     private ?string $name null;
  45.     #[ORM\Column(type'string'length128nullabletrue)]
  46.     #[Serial\Groups(['Manager'])]
  47.     private ?string $legalOfficer null;
  48.     #[ORM\Embedded(class: Address::class)]
  49.     #[Assert\Valid]
  50.     #[Serial\Groups(['Sync'])]
  51.     private ?AddressInterface $address null;
  52.     #[ORM\Column(type'string'length180nullabletrue)]
  53.     #[Assert\Email(message'channel.organization.email.Email'mode'strict')]
  54.     #[Serial\Groups(['Manager'])]
  55.     private ?string $contactEmail null;
  56.     #[ORM\Column(type'string'length20nullabletrue)]
  57.     #[Serial\Groups(['Manager'])]
  58.     private ?string $phoneNumber null;
  59.     #[ORM\OneToMany(mappedBy'organization'targetEntityFileOrganization::class, cascade: ['persist''remove'], orphanRemovaltrue)]
  60.     private ?Collection $files;
  61.     #[ORM\OneToOne(targetEntityProfessionalId::class, cascade: ['persist''remove'], orphanRemovaltrue)]
  62.     #[IdGroups(['Sync'])]
  63.     private ?ProfessionalId $professionalId null;
  64.     #[ORM\Column(type'integer'nullablefalse)]
  65.     private ?int $organizationOrder null;
  66.     #[ORM\OneToOne(mappedBy'organization'targetEntityCursusStartCertificate::class, cascade: ['persist''remove'], orphanRemovaltrue)]
  67.     private ?CursusStartCertificate $certificate null;
  68.     public function __construct()
  69.     {
  70.         $this->files = new ArrayCollection();
  71.         $this->address = new Address();
  72.     }
  73.     public static function getSyncKey(): string
  74.     {
  75.         return EntityKeys::CHANNEL_ORGANIZATION;
  76.     }
  77.     public function getSyncDisplayLabel(): string
  78.     {
  79.         return $this->getName() ?? 'Structure';
  80.     }
  81.     #[Serial\Groups(['Sync'])]
  82.     public function getLogoPath(): ?string
  83.     {
  84.         return $this->getLogoFile()?->getPath();
  85.     }
  86.     public function getId(): ?int
  87.     {
  88.         return $this->id;
  89.     }
  90.     public function getLegalOfficer(): ?string
  91.     {
  92.         return $this->legalOfficer;
  93.     }
  94.     public function setLegalOfficer(?string $legalOfficer): Organization
  95.     {
  96.         $this->legalOfficer $legalOfficer;
  97.         return $this;
  98.     }
  99.     public function getContactEmail(): ?string
  100.     {
  101.         return $this->contactEmail;
  102.     }
  103.     public function setContactEmail(?string $contactEmail): Organization
  104.     {
  105.         $this->contactEmail $contactEmail;
  106.         return $this;
  107.     }
  108.     public function getPhoneNumber(): ?string
  109.     {
  110.         return $this->phoneNumber;
  111.     }
  112.     public function setPhoneNumber(?string $phoneNumber): Organization
  113.     {
  114.         $this->phoneNumber $phoneNumber;
  115.         return $this;
  116.     }
  117.     public function getFiles(): ?Collection
  118.     {
  119.         return $this->files;
  120.     }
  121.     public function addFile(FileOrganization $file): Organization
  122.     {
  123.         if (!$this->files->contains($file)) {
  124.             $file->setOrganization($this);
  125.             $this->files[] = $file;
  126.         }
  127.         return $this;
  128.     }
  129.     public function removeFile(FileOrganization $file): Organization
  130.     {
  131.         if ($this->files->contains($file)) {
  132.             $this->files->removeElement($file);
  133.         }
  134.         return $this;
  135.     }
  136.     public function getFileByTag(string $tag): ?FileOrganization
  137.     {
  138.         foreach ($this->getFiles() as $file) {
  139.             if ($file->getTag() === $tag) {
  140.                 return $file;
  141.             }
  142.         }
  143.         return null;
  144.     }
  145.     public function setFileByTag(FileOrganization $file): void
  146.     {
  147.         // Remove existing file with same tag if exists
  148.         if ($existingFile $this->getFileByTag($file->getTag())) {
  149.             $this->removeFile($existingFile);
  150.         }
  151.         $this->addFile($file);
  152.     }
  153.     public function getLogoFile(): ?FileOrganization
  154.     {
  155.         return $this->getFileByTag(FileOrganizationTagEnum::LOGO);
  156.     }
  157.     public function getSignatureFile(): ?FileOrganization
  158.     {
  159.         return $this->getFileByTag(FileOrganizationTagEnum::SIGNATURE);
  160.     }
  161.     public function getOrganizationOrder(): ?int
  162.     {
  163.         return $this->organizationOrder;
  164.     }
  165.     public function setOrganizationOrder(?int $organizationOrder): Organization
  166.     {
  167.         $this->organizationOrder $organizationOrder;
  168.         return $this;
  169.     }
  170.     public function __toString(): string
  171.     {
  172.         return $this->getName();
  173.     }
  174.     public function getCertificate(): ?CursusStartCertificate
  175.     {
  176.         return $this->certificate;
  177.     }
  178.     public function setCertificate(?CursusStartCertificate $certificate): Organization
  179.     {
  180.         $this->certificate $certificate;
  181.         return $this;
  182.     }
  183.     public function getProfessionalId(): ?ProfessionalId
  184.     {
  185.         return $this->professionalId;
  186.     }
  187.     public function setProfessionalId(?ProfessionalId $professionalId): static
  188.     {
  189.         $this->professionalId $professionalId;
  190.         return $this;
  191.     }
  192. }