src/Entity/JournalNewsTranslation.php line 34

  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Trait\JournalUniqueSlugTrait;
  4. use Doctrine\ORM\Mapping as ORM,
  5.     Doctrine\DBAL\Types\Types,
  6.     Doctrine\Common\Collections\ArrayCollection;
  7. use Symfony\Component\Serializer\Annotation\Groups;
  8. use ApiPlatform\Metadata\ApiProperty,
  9.     ApiPlatform\Metadata\ApiResource,
  10.     ApiPlatform\Metadata\Get;
  11. use App\Entity\Trait\IdTrait,
  12.     App\Entity\Trait\UuidTrait,
  13.     App\Entity\Trait\TimestampableTrait,
  14.     App\Entity\Trait\TranslationTrait,
  15.     App\Entity\Trait\Media\ImageThumbableTrait,
  16.     App\Entity\Trait\SlugTrait,
  17.     App\Entity\Interface\TranslationInterface,
  18.     App\Entity\Interface\ThumbableInterface,
  19.     App\Repository\JournalNewsTranslationRepository;
  20. use App\Util\ClassUtils,
  21.     App\Enum\Language;
  22. #[ApiResource(
  23.     security'is_granted("' Journal::class . '")',
  24.     operations: [ new Get() ],
  25.     extraProperties: ['standard_put' => false],
  26. )]
  27. #[ORM\Entity(repositoryClassJournalNewsTranslationRepository::class)]
  28. class JournalNewsTranslation implements TranslationInterfaceThumbableInterface
  29. {
  30.     use IdTrait,
  31.         UuidTrait,
  32.         TimestampableTrait,
  33.         TranslationTrait,
  34.         ImageThumbableTrait,
  35.         JournalUniqueSlugTrait;
  36.     #[ApiProperty(description'Title')]
  37.     #[Groups(['read''write'])]
  38.     #[ORM\Column(typeTypes::STRINGlength511nullabletrue)]
  39.     private ?string $title null;
  40.     #[ApiProperty(description'Subtitle')]
  41.     #[Groups(['read:' self::class, 'write'])]
  42.     #[ORM\Column(typeTypes::STRINGlength511nullabletrue)]
  43.     private ?string $subtitle null;
  44.     #[ApiProperty(description'Short lead')]
  45.     #[Groups(['read:' self::class, 'write'])]
  46.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  47.     private ?string $shortLead null;
  48.     #[ApiProperty(description'Alt')]
  49.     #[Groups(['read:' self::class, 'write'])]
  50.     #[ORM\Column(typeTypes::STRINGlength511nullabletrue)]
  51.     private ?string $alt null;
  52.     public function __construct(JournalNews $parentLanguage $lang)
  53.     {
  54.         $this->setUuid();
  55.         $this->parent $parent;
  56.         $this->lang $lang;
  57.         $this->uniqueKey sprintf('%s_%s'$parent->getParent()->getId(), $lang->value);
  58.         $this->thumbs = new ArrayCollection();
  59.         $this->createdAt = new \DateTimeImmutable();
  60.         $this->updatedAt = new \DateTimeImmutable();
  61.         $parent->addTranslation($this);
  62.     }
  63.     public function getTitle(): ?string
  64.     {
  65.         return $this->title;
  66.     }
  67.     public function setTitle(?string $title): self
  68.     {
  69.         $this->title $title;
  70.         return $this;
  71.     }
  72.     public function getSubtitle(): ?string
  73.     {
  74.         return $this->subtitle;
  75.     }
  76.     public function setSubtitle(?string $subtitle): self
  77.     {
  78.         $this->subtitle $subtitle;
  79.         return $this;
  80.     }
  81.     public function getShortLead(): ?string
  82.     {
  83.         return $this->shortLead;
  84.     }
  85.     public function setShortLead(?string $shortLead): self
  86.     {
  87.         $this->shortLead $shortLead;
  88.         return $this;
  89.     }
  90.     public function getAlt(): ?string
  91.     {
  92.         return $this->alt;
  93.     }
  94.     public function setAlt(?string $alt): self
  95.     {
  96.         $this->alt $alt;
  97.         return $this;
  98.     }
  99.     public function clone(JournalNews $parent): self
  100.     {
  101.         $clone = clone $this;
  102.         $clone->id null;
  103.         $clone->setUuid();
  104.         if ($clone->media) {
  105.             $clone->media $this->media->clone();
  106.             $clone->media->setRelated(self::class . ':' $clone->uuid->toString());
  107.         }
  108.         $clone->slug null;
  109.         $clone->parent $parent;
  110.         $clone->parent->addTranslation($clone);
  111.         ClassUtils::cloneCollection($this$clone'thumbs');
  112.         $clone->createdAt = new \DateTimeImmutable();
  113.         $clone->updatedAt = new \DateTimeImmutable();
  114.         return $clone;
  115.     }
  116. }