src/Domain/Entity/Chapter.php line 42

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