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