src/Domain/Entity/Chapter.php line 48

Open in your IDE?
  1. <?php
  2. namespace App\Domain\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use ApiPlatform\Metadata\Get;
  5. use ApiPlatform\Metadata\GetCollection;
  6. use App\Application\Controller\Api\Chapter\GetByIdAction;
  7. use App\Application\Controller\Api\Chapter\GetCollectionAction;
  8. use App\Application\Controller\Api\Chapter\GetByPointOfInterestTypeAction;
  9. use App\Application\Controller\Api\Chapter\GetChaptersForFiltersAction;
  10. use App\Domain\Entity\Behavior\Identifiable;
  11. use App\Domain\Entity\Enumeration\PointOfInterestType;
  12. use App\Domain\Entity\Translation\ChapterTranslation;
  13. use Doctrine\Common\Collections\ArrayCollection;
  14. use Doctrine\Common\Collections\Collection;
  15. use Gedmo\Timestampable\Traits\Timestampable;
  16. use Symfony\Component\Serializer\Annotation\Groups;
  17. use Locastic\ApiPlatformTranslationBundle\Model\AbstractTranslatable;
  18. use Locastic\ApiPlatformTranslationBundle\Model\TranslationInterface;
  19. /**
  20.  * Class Chapter
  21.  *
  22.  * @package App\Domain\Entity
  23.  */
  24. #[ApiResource(
  25.     operations: [
  26.         new GetCollection(controllerGetCollectionAction::class),
  27.         new GetCollection(
  28.             uriTemplate'/point_of_interest_types/{uuid}/chapters',
  29.             controllerGetByPointOfInterestTypeAction::class,
  30.         ),
  31.         new GetCollection(
  32.             uriTemplate'/chapters/for_filters',
  33.             controllerGetChaptersForFiltersAction::class,
  34.             name'get_chapters_for_filters',
  35.         ),
  36.         new Get(name'get_chapter_by_id'),
  37.         new Get(
  38.             controllerGetByIdAction::class,
  39.             uriTemplate'/chapters/{uuid}/attributes',
  40.         ),
  41.     ],
  42.     normalizationContext: ['groups' => ['chapter_read']],
  43.     denormalizationContext: ['groups' => ['chapter_write']]
  44. )]
  45. class Chapter extends AbstractTranslatable
  46. {
  47.     use Identifiable;
  48.     use Timestampable;
  49.     /**
  50.      * @var Collection<int, ChapterAttributes>
  51.      */
  52.     private Collection $chapterAttributes;
  53.     /**
  54.      * @param string      $name
  55.      * @param int         $position
  56.      */
  57.     public function __construct(
  58.         public string $name,
  59.         public int $position,
  60.         public ?PointOfInterestType $pointOfInterestType,
  61.         public bool $isService false,
  62.         public bool $isFilter false,
  63.     ) {
  64.         parent::__construct();
  65.         $this->chapterAttributes = new ArrayCollection();
  66.     }
  67.     public function getCreatedAt()
  68.     {
  69.         return $this->createdAt;
  70.     }
  71.     public function getName(): string
  72.     {
  73.         return $this->name;
  74.     }
  75.     public function getPosition(): int
  76.     {
  77.         return $this->position;
  78.     }
  79.     public function setName(string $name): void
  80.     {
  81.         $this->name $name;
  82.     }
  83.     public function setPosition(int $position): void
  84.     {
  85.         $this->position $position;
  86.     }
  87.     public function isService(): bool
  88.     {
  89.         return $this->isService;
  90.     }
  91.     public function setIsService(bool $isService): void
  92.     {
  93.         $this->isService $isService;
  94.     }
  95.     public function isFilter(): bool
  96.     {
  97.         return $this->isFilter;
  98.     }
  99.     public function setIsFilter(bool $isFilter): void
  100.     {
  101.         $this->isFilter $isFilter;
  102.     }
  103.     public function getPointOfInterestType(): ?PointOfInterestType
  104.     {
  105.         return $this->pointOfInterestType;
  106.     }
  107.     public function setPointOfInterestType(?PointOfInterestType $pointOfInterestType): void
  108.     {
  109.         $this->pointOfInterestType $pointOfInterestType;
  110.     }
  111.     public function createTranslation(): TranslationInterface
  112.     {
  113.         return new ChapterTranslation();
  114.     }
  115.     public function getTranslationType($locale null): ChapterTranslation
  116.     {
  117.         return $this->getTranslation($locale);
  118.     }
  119.     /**
  120.      * @return Collection<int, ChapterAttributes>
  121.      */
  122.     public function getChapterAttributes(): Collection
  123.     {
  124.         return $this->chapterAttributes;
  125.     }
  126.     public function setChapterAttributes(Collection $chapterAttributes): void
  127.     {
  128.         $this->chapterAttributes $chapterAttributes;
  129.     }
  130.     public function addChapterAttribute(ChapterAttributes $chapterAttribute): void
  131.     {
  132.         if (!$this->chapterAttributes->contains($chapterAttribute)) {
  133.             $this->chapterAttributes->add($chapterAttribute);
  134.         }
  135.     }
  136.     public function removeChapterAttribute(ChapterAttributes $chapterAttribute): void
  137.     {
  138.         $this->chapterAttributes->removeElement($chapterAttribute);
  139.     }
  140. }