src/Domain/Entity/DirectoryDepartment.php line 39

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Domain\Entity;
  4. use ApiPlatform\Metadata\ApiResource;
  5. use ApiPlatform\Metadata\Delete;
  6. use ApiPlatform\Metadata\Get;
  7. use ApiPlatform\Metadata\GetCollection;
  8. use ApiPlatform\Metadata\Post;
  9. use ApiPlatform\Metadata\Put;
  10. use App\Domain\Entity\Behavior\Identifiable;
  11. use App\Domain\Entity\Translation\DirectoryDepartmentTranslation;
  12. use DateTime;
  13. use Doctrine\Common\Collections\ArrayCollection;
  14. use Doctrine\Common\Collections\Collection;
  15. use Gedmo\SoftDeleteable\Traits\SoftDeleteable;
  16. use Gedmo\Timestampable\Traits\Timestampable;
  17. use Locastic\ApiPlatformTranslationBundle\Model\AbstractTranslatable;
  18. use Locastic\ApiPlatformTranslationBundle\Model\TranslationInterface;
  19. #[ApiResource(
  20.     operations: [
  21.         new Delete(security"is_granted('ROLE_ADMIN')"),
  22.         new GetCollection(filters: [
  23.             'directory_department.search_filter',
  24.             'directory_department.query_filter',
  25.             'directory_department.order_filter',
  26.         ]),
  27.         new Get(),
  28.         new Post(normalizationContext: ['groups' => ['translations']], security"is_granted('ROLE_ADMIN')"),
  29.         new Put(normalizationContext: ['groups' => ['translations']], security"is_granted('ROLE_ADMIN')"),
  30.     ],
  31.     normalizationContext: ['groups' => ['directory_department_read']],
  32.     denormalizationContext: ['groups' => ['directory_department_write']],
  33.     filters: ['translation.groups']
  34. )]
  35. class DirectoryDepartment extends AbstractTranslatable
  36. {
  37.     use Identifiable;
  38.     use SoftDeleteable;
  39.     use Timestampable;
  40.     private Collection $offmaps;
  41.     public function __construct(
  42.         public DirectoryCountry $country,
  43.         public Media $photo,
  44.         public ?string $reference null,
  45.         public ?string $sqlStr null,
  46.         public ?string $remoteId null,
  47.         public ?DateTime $zhistUpdate null,
  48.     ) {
  49.         parent::__construct();
  50.         $this->offmaps = new ArrayCollection();
  51.     }
  52.     public function getDescription(): ?string
  53.     {
  54.         return $this->getTranslationType()->getDescription();
  55.     }
  56.     public function getTranslationType(?string $locale null): DirectoryDepartmentTranslation
  57.     {
  58.         return $this->getTranslation($locale);
  59.     }
  60.     public function setDescription(?string $description): void
  61.     {
  62.         $this->getTranslationType()->setDescription($description);
  63.     }
  64.     public function getName(?string $locale null): ?string
  65.     {
  66.         return $this->getTranslationType($locale)->getName();
  67.     }
  68.     public function setName(?string $name): void
  69.     {
  70.         $this->getTranslationType()->setName($name);
  71.     }
  72.     public function createTranslation(): TranslationInterface
  73.     {
  74.         return new DirectoryDepartmentTranslation();
  75.     }
  76.     /**
  77.      * @return Collection
  78.      */
  79.     public function getOffmaps(): Collection
  80.     {
  81.         return $this->offmaps;
  82.     }
  83.     /**
  84.      * @param Collection $offmaps
  85.      */
  86.     public function setOffmaps(Collection $offmaps): void
  87.     {
  88.         $this->offmaps $offmaps;
  89.     }
  90.     public function addOffmap(Offmap $offmap): void
  91.     {
  92.         if ($this->offmaps->contains($offmap)) {
  93.             return;
  94.         }
  95.         $this->offmaps->add($offmap);
  96.     }
  97.     public function removeOffmap(Offmap $offmap): void
  98.     {
  99.         if (!$this->offmaps->contains($offmap)) {
  100.             return;
  101.         }
  102.         $this->offmaps->removeElement($offmap);
  103.     }
  104. }