src/Entity/JournalIssueTranslation.php line 38

  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Trait\JournalUniqueSlugTrait;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\ORM\Mapping as ORM,
  6.     Doctrine\DBAL\Types\Types;
  7. use Symfony\Component\Serializer\Annotation\Groups;
  8. use ApiPlatform\Metadata\ApiProperty,
  9.     ApiPlatform\Metadata\ApiResource,
  10.     ApiPlatform\Metadata\Get;
  11. use App\Entity\Interface\TranslationInterface,
  12.     App\Entity\Interface\ThumbableInterface,
  13.     App\Entity\Trait\IdTrait,
  14.     App\Entity\Trait\UuidTrait,
  15.     App\Entity\Trait\TimestampableTrait,
  16.     App\Entity\Trait\TranslationTrait,
  17.     App\Entity\Trait\SlugTrait,
  18.     App\Entity\Trait\Media\ThumbableTrait,
  19.     App\Entity\Trait\Media\SetMediaTrait,
  20.     App\Entity\Trait\Media\SetImageThumbableTrait;
  21. use App\Enum\Language,
  22.     App\Attribute\Sanitizeable,
  23.     App\Repository\JournalIssueTranslationRepository;
  24. use App\Validator\Constraints as CustomAssert;
  25. #[ApiResource(
  26.     security'is_granted("' Journal::class . '")',
  27.     operations: [ new Get() ],
  28.     extraProperties: ['standard_put' => false],
  29. )]
  30. #[ORM\Entity(repositoryClassJournalIssueTranslationRepository::class)]
  31. class JournalIssueTranslation implements TranslationInterfaceThumbableInterface
  32. {
  33.     use IdTrait,
  34.         UuidTrait,
  35.         TimestampableTrait,
  36.         TranslationTrait,
  37.         JournalUniqueSlugTrait,
  38.         ThumbableTrait,
  39.         SetImageThumbableTrait,
  40.         SetMediaTrait;
  41.     #[ApiProperty(description'Title')]
  42.     #[Groups(['read''write'])]
  43.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  44.     private ?string $title null;
  45.     #[ApiProperty(description'Subtitle')]
  46.     #[Groups(['read:' self::class, 'write'])]
  47.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  48.     private ?string $subtitle null;
  49.     #[ApiProperty(description'Cover'writableLinkfalse)]
  50.     #[Groups(['read:' self::class, 'write'])]
  51.     #[CustomAssert\ValidMediaMimeType(types: ['image/*'])]
  52.     #[ORM\ManyToOne(targetEntityMedia::class, cascade: ['persist''remove'])]
  53.     #[ORM\JoinColumn(onDelete'set null')]
  54.     private ?Media $cover null;
  55.     #[ApiProperty(description'Cover alt')]
  56.     #[Groups(['read:' self::class, 'write'])]
  57.     #[Sanitizeable]
  58.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  59.     private ?string $coverAlt null;
  60.     #[ApiProperty(description'Funding description')]
  61.     #[Groups(['read:' self::class, 'write'])]
  62.     #[Sanitizeable]
  63.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  64.     private ?string $fundingDescription null;
  65.     #[ApiProperty(description'Copyrights')]
  66.     #[Groups(['read:' self::class, 'write'])]
  67.     #[Sanitizeable]
  68.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  69.     private ?string $copyrights null;
  70.     #[ApiProperty(description'Description')]
  71.     #[Groups(['read:' self::class, 'write'])]
  72.     #[Sanitizeable]
  73.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  74.     private ?string $description null;
  75.     #[ApiProperty(description'Additional info')]
  76.     #[Groups(['read:' self::class, 'write'])]
  77.     #[Sanitizeable]
  78.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  79.     private ?string $additionalInfo null;
  80.     #[ApiProperty(description'Indexed content')]
  81.     #[Groups(['read:' self::class, 'write'])]
  82.     #[Sanitizeable]
  83.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  84.     private ?string $indexedContent null;
  85.     #[ApiProperty(description'Meta title')]
  86.     #[Groups(['read:' self::class, 'write'])]
  87.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  88.     private ?string $metaTitle null;
  89.     #[ApiProperty(description'Meta description')]
  90.     #[Groups(['read:' self::class, 'write'])]
  91.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  92.     private ?string $metaDescription null;
  93.     #[ApiProperty(description'Meta keywords')]
  94.     #[Groups(['read:' self::class, 'write'])]
  95.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  96.     private ?string $metaKeywords null;
  97.     public function __construct(JournalIssue $parentLanguage $lang)
  98.     {
  99.         $this->setUuid();
  100.         $this->parent $parent;
  101.         $this->lang $lang;
  102.         $this->uniqueKey sprintf('%s_%s'$parent->getParent()->getId(), $lang->value);
  103.         $this->thumbs = new ArrayCollection();
  104.         $this->createdAt = new \DateTimeImmutable();
  105.         $this->updatedAt = new \DateTimeImmutable();
  106.         $parent->addTranslation($this);
  107.     }
  108.     public function getTitle(): ?string
  109.     {
  110.         return $this->title;
  111.     }
  112.     public function setTitle(?string $title): self
  113.     {
  114.         $this->title $title;
  115.         return $this;
  116.     }
  117.     #[Groups(['read'])]
  118.     public function getFullTitle(): ?string
  119.     {
  120.         /** @var JournalIssue $parent */
  121.         $parent $this->parent;
  122.         $title $parent->getVolume()
  123.             ? sprintf(
  124.                 "%s - %s",
  125.                 $parent->getVolume()->readTranslation($this->lang'title'),
  126.                 $this->title
  127.             ) : $this->title;
  128.         return sprintf(
  129.             "%s - %s",
  130.             $parent->getParent()->readTranslation($this->lang'title'),
  131.             $title
  132.         );
  133.     }
  134.     public function getSubtitle(): ?string
  135.     {
  136.         return $this->subtitle;
  137.     }
  138.     public function setSubtitle(?string $subtitle): self
  139.     {
  140.         $this->subtitle $subtitle;
  141.         return $this;
  142.     }
  143.     public function getCover(): ?Media
  144.     {
  145.         return $this->cover;
  146.     }
  147.     public function setCover(?Media $cover): self
  148.     {
  149.         return $this->setImageThumbable('cover'$cover);
  150.     }
  151.     public function getCoverAlt(): ?string
  152.     {
  153.         return $this->coverAlt;
  154.     }
  155.     public function setCoverAlt(?string $coverAlt): self
  156.     {
  157.         $this->coverAlt $coverAlt;
  158.         return $this;
  159.     }
  160.     public function getFundingDescription(): ?string
  161.     {
  162.         return $this->fundingDescription;
  163.     }
  164.     public function setFundingDescription(?string $fundingDescription): self
  165.     {
  166.         $this->fundingDescription $fundingDescription;
  167.         return $this;
  168.     }
  169.     public function getCopyrights(): ?string
  170.     {
  171.         return $this->copyrights;
  172.     }
  173.     public function setCopyrights(?string $copyrights): self
  174.     {
  175.         $this->copyrights $copyrights;
  176.         return $this;
  177.     }
  178.     public function getDescription(): ?string
  179.     {
  180.         return $this->description;
  181.     }
  182.     public function setDescription(?string $description): self
  183.     {
  184.         $this->description $description;
  185.         return $this;
  186.     }
  187.     public function getAdditionalInfo(): ?string
  188.     {
  189.         return $this->additionalInfo;
  190.     }
  191.     public function setAdditionalInfo(?string $additionalInfo): self
  192.     {
  193.         $this->additionalInfo $additionalInfo;
  194.         return $this;
  195.     }
  196.     public function setIndexedContent(?string $indexedContent): self
  197.     {
  198.         $this->indexedContent $indexedContent;
  199.         return $this;
  200.     }
  201.     public function getIndexedContent(): ?string
  202.     {
  203.         return $this->indexedContent;
  204.     }
  205.     public function getMetaTitle(): ?string
  206.     {
  207.         return $this->metaTitle;
  208.     }
  209.     public function setMetaTitle(?string $metaTitle): self
  210.     {
  211.         $this->metaTitle $metaTitle;
  212.         return $this;
  213.     }
  214.     public function getMetaDescription(): ?string
  215.     {
  216.         return $this->metaDescription;
  217.     }
  218.     public function setMetaDescription(?string $metaDescription): self
  219.     {
  220.         $this->metaDescription $metaDescription;
  221.         return $this;
  222.     }
  223.     public function getMetaKeywords(): ?string
  224.     {
  225.         return $this->metaKeywords;
  226.     }
  227.     public function setMetaKeywords(?string $metaKeywords): self
  228.     {
  229.         $this->metaKeywords $metaKeywords;
  230.         return $this;
  231.     }
  232.     public function clone(JournalIssue $parent): self
  233.     {
  234.         $clone = clone $this;
  235.         $clone->id null;
  236.         $clone->setUuid();
  237.         if ($clone->cover) {
  238.             $clone->cover $this->cover->clone();
  239.             $clone->cover->setRelated(self::class . ':' $clone->uuid->toString());
  240.         }
  241.         $clone->parent $parent;
  242.         $clone->parent->addTranslation($clone);
  243.         $clone->createdAt = new \DateTimeImmutable();
  244.         $clone->updatedAt = new \DateTimeImmutable();
  245.         return $clone;
  246.     }
  247. }