src/Entity/AffiliationTranslation.php line 31

  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\ORM\Mapping as ORM,
  5.     Doctrine\DBAL\Types\Types;
  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\Media\ImageThumbableTrait,
  15.     App\Entity\Trait\SlugTrait,
  16.     App\Entity\Interface\TranslationInterface,
  17.     App\Entity\Interface\ThumbableInterface,
  18.     App\Enum\Language,
  19.     App\Repository\AffiliationTranslationRepository;
  20. #[ApiResource(
  21.     security'is_granted("' Affiliation::class . '")',
  22.     operations: [ new Get() ],
  23.     extraProperties: ['standard_put' => false],
  24. )]
  25. #[ORM\Entity(repositoryClassAffiliationTranslationRepository::class)]
  26. class AffiliationTranslation implements TranslationInterfaceThumbableInterface
  27. {
  28.     use IdTrait,
  29.         UuidTrait,
  30.         TimestampableTrait,
  31.         TranslationTrait,
  32.         SlugTrait,
  33.         ImageThumbableTrait;
  34.     #[ApiProperty(description'Title')]
  35.     #[Groups(['read''write'])]
  36.     #[ORM\Column(typeTypes::STRINGlength1023nullabletrue)]
  37.     private ?string $title null;
  38.     #[ApiProperty(description'Text')]
  39.     #[Groups(['read:' self::class, 'write'])]
  40.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  41.     private ?string $text null;
  42.     #[ApiProperty(description'Alt')]
  43.     #[Groups(['read:' self::class, 'write'])]
  44.     #[ORM\Column(typeTypes::STRINGlength1023nullabletrue)]
  45.     private ?string $alt null;
  46.     public function __construct(Affiliation $parentLanguage $lang)
  47.     {
  48.         $this->setUuid();
  49.         $this->parent $parent;
  50.         $this->lang $lang;
  51.         $this->thumbs = new ArrayCollection();
  52.         $this->createdAt = new \DateTimeImmutable();
  53.         $this->updatedAt = new \DateTimeImmutable();
  54.         $parent->addTranslation($this);
  55.     }
  56.     public function getTitle(): ?string
  57.     {
  58.         return $this->title;
  59.     }
  60.     public function setTitle(?string $title): self
  61.     {
  62.         $this->title $title;
  63.         /** @var Affiliation */
  64.         $parent $this->parent;
  65.         if ($this->lang === $parent->getNativeLanguage()) {
  66.             $parent->setNativeTitle($title);
  67.         }
  68.         return $this;
  69.     }
  70.     public function getText(): ?string
  71.     {
  72.         return $this->text;
  73.     }
  74.     public function setText(?string $text): self
  75.     {
  76.         $this->text $text;
  77.         return $this;
  78.     }
  79.     public function getAlt(): ?string
  80.     {
  81.         return $this->alt;
  82.     }
  83.     public function setAlt(?string $alt): self
  84.     {
  85.         $this->alt $alt;
  86.         return $this;
  87.     }
  88.     #[Groups(['read'])]
  89.     public function getFullAffiliationTitle(): ?string
  90.     {
  91.         return $this->getParentAffiliationTitle($this->getParent(), $this->lang) . $this->title;
  92.     }
  93.     private function getParentAffiliationTitle(Affiliation $affiliationLanguage $lang): ?string
  94.     {
  95.         if (! $affiliation->getParent()) {
  96.             return null;
  97.         }
  98.         /** @var AffiliationTranslation */
  99.         $langTranslation $affiliation->getTranslations()[$lang->value];
  100.         return $this->getParentAffiliationTitle($affiliation->getParent(), $lang)
  101.             . $langTranslation?->getTitle()
  102.             . ' - ';
  103.     }
  104. }