src/Entity/JournalSlide.php line 74
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM,
Doctrine\DBAL\Types\Types,
Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Serializer\Annotation\Groups,
Symfony\Component\Validator\Constraints as Assert,
Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use ApiPlatform\Metadata\ApiResource,
ApiPlatform\Metadata\ApiProperty,
ApiPlatform\Metadata\Get,
ApiPlatform\Metadata\GetCollection,
ApiPlatform\Metadata\Post,
ApiPlatform\Metadata\Put,
ApiPlatform\Metadata\Delete,
ApiPlatform\Metadata\ApiFilter,
ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
use App\Entity\Trait\IdTrait,
App\Entity\Trait\UuidTrait,
App\Entity\Trait\OrdStatTrait,
App\Entity\Trait\TimestampableTrait,
App\Entity\Trait\TranslatableTrait,
App\Entity\Trait\Languages\LanguageableChildTrait,
App\Entity\Interface\TranslatableInterface,
App\Entity\Interface\OrdStatableInterface,
App\Entity\Interface\LanguageableChildInterface,
App\Entity\Interface\CloneableInterface,
App\Repository\JournalSlideRepository;
use App\Entity\AbstractThumb,
App\Filter\IriFilter,
App\DTO\CloneDTO,
App\StateProcessor\CloneProcessor,
App\Security\Voter\CloneVoter,
App\Lib\Actions,
App\Util\ClassUtils;
#[ApiResource(
description: 'Journal slides',
normalizationContext: ['groups' => [
'read',
'read:' . self::class,
'read:' . self::class . 'Translation',
'read:' . AbstractThumb::class
]],
denormalizationContext: ['groups' => ['write']],
security: 'is_granted("' . Journal::class . '")',
order: ['ord' => 'desc'],
operations: [
new GetCollection(),
new Post(
uriTemplate: '/journal_slides/clone',
input: CloneDTO::class,
processor: CloneProcessor::class,
security: 'is_granted("' . Actions::CLONE .'")',
securityMessage: CloneVoter::MESSAGE
),
new Post(denormalizationContext: ['groups' => ['write', 'post']]),
new Get(),
new Put(),
new Delete(),
],
extraProperties: ['standard_put' => false],
)]
#[ApiFilter(IriFilter::class, properties: ['parent'])]
#[ApiFilter(OrderFilter::class, properties: ['ord'])]
#[UniqueEntity(fields: ['workingTitle', 'parent'], message: 'This working title already exists.')]
#[ORM\UniqueConstraint(fields: ['parent', 'workingTitle'])]
#[ORM\Entity(repositoryClass: JournalSlideRepository::class)]
class JournalSlide implements
TranslatableInterface,
OrdStatableInterface,
LanguageableChildInterface,
CloneableInterface
{
use IdTrait,
UuidTrait,
OrdStatTrait,
TimestampableTrait,
TranslatableTrait,
LanguageableChildTrait;
#[ApiProperty(description: 'Parent', readableLink: false, writableLink: false)]
#[Groups(['read', 'post'])]
#[Assert\NotNull]
#[ORM\ManyToOne(targetEntity: Journal::class, inversedBy: 'slides')]
#[ORM\JoinColumn(onDelete: 'cascade', nullable: false)]
private Journal $parent;
#[ApiProperty(description: 'Working title')]
#[Groups(['read', 'write'])]
#[Assert\NotBlank]
#[ORM\Column(type: Types::STRING, length: 511)]
private string $workingTitle;
public function __construct(Journal $parent, string $workingTitle)
{
$this->setUuid();
$this->parent = $parent;
$this->workingTitle = $workingTitle;
$this->translations = new ArrayCollection();
foreach ($this->parent->getLanguages() as $lang) {
new JournalSlideTranslation($this, $lang);
}
$this->createdAt = new \DateTimeImmutable();
$this->updatedAt = new \DateTimeImmutable();
$parent->addSlide($this);
}
public function getParent(): Journal
{
return $this->parent;
}
public function getWorkingTitle(): string
{
return $this->workingTitle;
}
public function setWorkingTitle(string $workingTitle): self
{
$this->workingTitle = $workingTitle;
return $this;
}
public function clone(): self
{
$clone = clone $this;
$clone->id = null;
$clone->setUuid();
$clone->workingTitle .= ' [KOPIA]';
$clone->ord = 0;
$clone->stat = false;
ClassUtils::cloneCollection($this, $clone, 'translations');
$clone->synchronizeTranslations();
$clone->createdAt = new \DateTimeImmutable();
$clone->updatedAt = new \DateTimeImmutable();
return $clone;
}
}