src/Entity/JournalSlide.php line 74

  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM,
  4.     Doctrine\DBAL\Types\Types,
  5.     Doctrine\Common\Collections\ArrayCollection;
  6. use Symfony\Component\Serializer\Annotation\Groups,
  7.     Symfony\Component\Validator\Constraints as Assert,
  8.     Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  9. use ApiPlatform\Metadata\ApiResource,
  10.     ApiPlatform\Metadata\ApiProperty,
  11.     ApiPlatform\Metadata\Get,
  12.     ApiPlatform\Metadata\GetCollection,
  13.     ApiPlatform\Metadata\Post,
  14.     ApiPlatform\Metadata\Put,
  15.     ApiPlatform\Metadata\Delete,
  16.     ApiPlatform\Metadata\ApiFilter,
  17.     ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
  18. use App\Entity\Trait\IdTrait,
  19.     App\Entity\Trait\UuidTrait,
  20.     App\Entity\Trait\OrdStatTrait,
  21.     App\Entity\Trait\TimestampableTrait,
  22.     App\Entity\Trait\TranslatableTrait,
  23.     App\Entity\Trait\Languages\LanguageableChildTrait,
  24.     App\Entity\Interface\TranslatableInterface,
  25.     App\Entity\Interface\OrdStatableInterface,
  26.     App\Entity\Interface\LanguageableChildInterface,
  27.     App\Entity\Interface\CloneableInterface,
  28.     App\Repository\JournalSlideRepository;
  29. use App\Entity\AbstractThumb,
  30.     App\Filter\IriFilter,
  31.     App\DTO\CloneDTO,
  32.     App\StateProcessor\CloneProcessor,
  33.     App\Security\Voter\CloneVoter,
  34.     App\Lib\Actions,
  35.     App\Util\ClassUtils;
  36. #[ApiResource(
  37.     description'Journal slides',
  38.     normalizationContext: ['groups' => [
  39.         'read',
  40.         'read:' self::class,
  41.         'read:' self::class . 'Translation',
  42.         'read:' AbstractThumb::class
  43.     ]],
  44.     denormalizationContext: ['groups' => ['write']],
  45.     security'is_granted("' Journal::class . '")',
  46.     order: ['ord' => 'desc'],
  47.     operations: [
  48.         new GetCollection(),
  49.         new Post(
  50.             uriTemplate'/journal_slides/clone',
  51.             inputCloneDTO::class,
  52.             processorCloneProcessor::class,
  53.             security'is_granted("' Actions::CLONE .'")',
  54.             securityMessageCloneVoter::MESSAGE
  55.         ),
  56.         new Post(denormalizationContext: ['groups' => ['write',  'post']]),
  57.         new Get(),
  58.         new Put(),
  59.         new Delete(),
  60.     ],
  61.     extraProperties: ['standard_put' => false],
  62. )]
  63. #[ApiFilter(IriFilter::class, properties: ['parent'])]
  64. #[ApiFilter(OrderFilter::class, properties: ['ord'])]
  65. #[UniqueEntity(fields: ['workingTitle''parent'], message'This working title already exists.')]
  66. #[ORM\UniqueConstraint(fields: ['parent''workingTitle'])]
  67. #[ORM\Entity(repositoryClassJournalSlideRepository::class)]
  68. class JournalSlide implements
  69.     TranslatableInterface,
  70.     OrdStatableInterface,
  71.     LanguageableChildInterface,
  72.     CloneableInterface
  73. {
  74.     use IdTrait,
  75.         UuidTrait,
  76.         OrdStatTrait,
  77.         TimestampableTrait,
  78.         TranslatableTrait,
  79.         LanguageableChildTrait;
  80.     #[ApiProperty(description'Parent'readableLinkfalsewritableLinkfalse)]
  81.     #[Groups(['read''post'])]
  82.     #[Assert\NotNull]
  83.     #[ORM\ManyToOne(targetEntityJournal::class, inversedBy'slides')]
  84.     #[ORM\JoinColumn(onDelete'cascade'nullablefalse)]
  85.     private Journal $parent;
  86.     #[ApiProperty(description'Working title')]
  87.     #[Groups(['read''write'])]
  88.     #[Assert\NotBlank]
  89.     #[ORM\Column(typeTypes::STRINGlength511)]
  90.     private string $workingTitle;
  91.     public function __construct(Journal $parentstring $workingTitle)
  92.     {
  93.         $this->setUuid();
  94.         $this->parent $parent;
  95.         $this->workingTitle $workingTitle;
  96.         $this->translations = new ArrayCollection();
  97.         foreach ($this->parent->getLanguages() as $lang) {
  98.             new JournalSlideTranslation($this$lang);
  99.         }
  100.         $this->createdAt = new \DateTimeImmutable();
  101.         $this->updatedAt = new \DateTimeImmutable();
  102.         $parent->addSlide($this);
  103.     }
  104.     public function getParent(): Journal
  105.     {
  106.         return $this->parent;
  107.     }
  108.     public function getWorkingTitle(): string
  109.     {
  110.         return $this->workingTitle;
  111.     }
  112.     public function setWorkingTitle(string $workingTitle): self
  113.     {
  114.         $this->workingTitle $workingTitle;
  115.         return $this;
  116.     }
  117.     public function clone(): self
  118.     {
  119.         $clone = clone $this;
  120.         $clone->id null;
  121.         $clone->setUuid();
  122.         $clone->workingTitle .= ' [KOPIA]';
  123.         $clone->ord 0;
  124.         $clone->stat false;
  125.         ClassUtils::cloneCollection($this$clone'translations');
  126.         $clone->synchronizeTranslations();
  127.         $clone->createdAt = new \DateTimeImmutable();
  128.         $clone->updatedAt = new \DateTimeImmutable();
  129.         return $clone;
  130.     }
  131. }