<?php
namespace App\Domain\Entity;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use App\Application\Controller\Api\Chapter\GetByIdAction;
use App\Application\Controller\Api\Chapter\GetCollectionAction;
use App\Application\Controller\Api\Chapter\GetByPointOfInterestTypeAction;
use App\Domain\Entity\Behavior\Identifiable;
use App\Domain\Entity\Enumeration\PointOfInterestType;
use App\Domain\Entity\Translation\ChapterTranslation;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Gedmo\Timestampable\Traits\Timestampable;
use Symfony\Component\Serializer\Annotation\Groups;
use Locastic\ApiPlatformTranslationBundle\Model\AbstractTranslatable;
use Locastic\ApiPlatformTranslationBundle\Model\TranslationInterface;
/**
* Class Chapter
*
* @package App\Domain\Entity
*/
#[ApiResource(
operations: [
new GetCollection(controller: GetCollectionAction::class),
new GetCollection(
uriTemplate: '/point_of_interest_types/{uuid}/chapters',
controller: GetByPointOfInterestTypeAction::class,
),
new Get(name: 'get_chapter_by_id'),
new Get(
controller: GetByIdAction::class,
uriTemplate: '/chapters/{uuid}/attributes',
),
],
normalizationContext: ['groups' => ['chapter_read']],
denormalizationContext: ['groups' => ['chapter_write']]
)]
class Chapter extends AbstractTranslatable
{
use Identifiable;
use Timestampable;
/**
* @var Collection<int, ChapterAttributes>
*/
private Collection $chapterAttributes;
/**
* @param string $name
* @param int $position
*/
public function __construct(
public string $name,
public int $position,
public PointOfInterestType $pointOfInterestType,
public bool $isService = false,
) {
parent::__construct();
$this->chapterAttributes = new ArrayCollection();
}
public function getCreatedAt()
{
return $this->createdAt;
}
public function getName(): string
{
return $this->name;
}
public function getPosition(): int
{
return $this->position;
}
public function setName(string $name): void
{
$this->name = $name;
}
public function setPosition(int $position): void
{
$this->position = $position;
}
public function isService(): bool
{
return $this->isService;
}
public function setIsService(bool $isService): void
{
$this->isService = $isService;
}
public function getPointOfInterestType(): PointOfInterestType
{
return $this->pointOfInterestType;
}
public function setPointOfInterestType(PointOfInterestType $pointOfInterestType): void
{
$this->pointOfInterestType = $pointOfInterestType;
}
public function createTranslation(): TranslationInterface
{
return new ChapterTranslation();
}
public function getTranslationType($locale = null): ChapterTranslation
{
return $this->getTranslation($locale);
}
/**
* @return Collection<int, ChapterAttributes>
*/
public function getChapterAttributes(): Collection
{
return $this->chapterAttributes;
}
public function setChapterAttributes(Collection $chapterAttributes): void
{
$this->chapterAttributes = $chapterAttributes;
}
public function addChapterAttribute(ChapterAttributes $chapterAttribute): void
{
if (!$this->chapterAttributes->contains($chapterAttribute)) {
$this->chapterAttributes->add($chapterAttribute);
}
}
public function removeChapterAttribute(ChapterAttributes $chapterAttribute): void
{
$this->chapterAttributes->removeElement($chapterAttribute);
}
}