src/Entity/JournalPageTranslation.php line 32

  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM,
  4.     Doctrine\DBAL\Types\Types;
  5. use Gedmo\Mapping\Annotation as Gedmo;
  6. use Symfony\Component\Serializer\Annotation\Groups;
  7. use ApiPlatform\Metadata\ApiProperty,
  8.     ApiPlatform\Metadata\ApiResource,
  9.     ApiPlatform\Metadata\Get;
  10. use App\Entity\Trait\IdTrait,
  11.     App\Entity\Trait\UuidTrait,
  12.     App\Entity\Trait\TimestampableTrait,
  13.     App\Entity\Trait\TranslationTrait,
  14.     App\Entity\Trait\SEOTrait,
  15.     App\Entity\Interface\TranslationInterface,
  16.     App\Repository\JournalPageTranslationRepository;
  17. use App\Attribute\Sanitizeable,
  18.     App\Enum\Language;
  19. #[ApiResource(
  20.     security'is_granted("' Journal::class . '")',
  21.     operations: [ new Get() ],
  22.     extraProperties: ['standard_put' => false],
  23. )]
  24. #[ORM\Entity(repositoryClassJournalPageTranslationRepository::class)]
  25. class JournalPageTranslation implements TranslationInterface
  26. {
  27.     use IdTrait,
  28.         UuidTrait,
  29.         TimestampableTrait,
  30.         TranslationTrait,
  31.         SEOTrait;
  32.     #[ApiProperty(description'Title')]
  33.     #[Groups(['read''write'])]
  34.     #[ORM\Column(typeTypes::STRINGlength511nullabletrue)]
  35.     private ?string $title null;
  36.     #[ApiProperty(description'Description')]
  37.     #[Groups(['read:' self::class, 'write'])]
  38.     #[Sanitizeable]
  39.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  40.     private ?string $description null;
  41.     // in old ejournals sometimes there was description despite linking content from other field,
  42.     // this content was no displayed but still existed in database, maybe if they unlink field?
  43.     #[ApiProperty(description'Old description besides linked text')]
  44.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  45.     private ?string $ignoredDescription null;
  46.     #[ApiProperty(description'Slug')]
  47.     #[Groups(['read:' self::class, 'write'])]
  48.     #[Gedmo\Slug(separator'-'style'default'updatabletruefields: ['title'], uniquefalse)]
  49.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  50.     private ?string $slug null;
  51.     public function __construct(JournalPage $parentLanguage $lang)
  52.     {
  53.         $this->setUuid();
  54.         $this->parent $parent;
  55.         $this->lang $lang;
  56.         $this->createdAt = new \DateTimeImmutable();
  57.         $this->updatedAt = new \DateTimeImmutable();
  58.         $parent->addTranslation($this);
  59.     }
  60.     public function getTitle(): ?string
  61.     {
  62.         return $this->title;
  63.     }
  64.     public function setTitle(?string $title): self
  65.     {
  66.         $this->title $title;
  67.         if (empty($this->metaTitle)) {
  68.             $this->metaTitle $title;
  69.         }
  70.         return $this;
  71.     }
  72.     public function getDescription(): ?string
  73.     {
  74.         return $this->description;
  75.     }
  76.     public function setDescription(?string $description): self
  77.     {
  78.         $this->description $description;
  79.         return $this;
  80.     }
  81.     public function setIgnoredDescription(?string $ignoredDescription): self
  82.     {
  83.         $this->ignoredDescription $ignoredDescription;
  84.         return $this;
  85.     }
  86.     public function getSlug(): ?string
  87.     {
  88.         return $this->slug;
  89.     }
  90.     public function setSlug(?string $slug): self
  91.     {
  92.         $this->slug $slug;
  93.         return $this;
  94.     }
  95.     public function clone(JournalPage $parent): self
  96.     {
  97.         $clone = clone $this;
  98.         $clone->id null;
  99.         $clone->setUuid();
  100.         $clone->slug null;
  101.         $clone->parent $parent;
  102.         $clone->parent->addTranslation($clone);
  103.         $clone->createdAt = new \DateTimeImmutable();
  104.         $clone->updatedAt = new \DateTimeImmutable();
  105.         return $clone;
  106.     }
  107. }