src/Entity/DomainTranslation.php line 27

  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM,
  4.     Doctrine\DBAL\Types\Types;
  5. use Symfony\Component\Serializer\Annotation\Groups;
  6. use ApiPlatform\Metadata\ApiProperty,
  7.     ApiPlatform\Metadata\ApiResource,
  8.     ApiPlatform\Metadata\Get;
  9. use App\Entity\Trait\IdTrait,
  10.     App\Entity\Trait\UuidTrait,
  11.     App\Entity\Trait\TimestampableTrait,
  12.     App\Entity\Trait\TranslationTrait,
  13.     App\Entity\Interface\TranslationInterface,
  14.     App\Enum\Language,
  15.     App\Repository\DomainTranslationRepository;
  16. #[ApiResource(
  17.     security'is_granted("' Domain::class . '")',
  18.     operations: [ new Get() ],
  19.     extraProperties: ['standard_put' => false],
  20. )]
  21. #[ORM\Entity(repositoryClassDomainTranslationRepository::class)]
  22. class DomainTranslation implements TranslationInterface
  23. {
  24.     use IdTrait,
  25.         UuidTrait,
  26.         TimestampableTrait,
  27.         TranslationTrait;
  28.     #[ApiProperty(description'Title')]
  29.     #[Groups(['read''write'])]
  30.     #[ORM\Column(typeTypes::STRINGlength1023nullabletrue)]
  31.     private ?string $title null;
  32.     public function __construct(Domain $parentLanguage $lang)
  33.     {
  34.         $this->setUuid();
  35.         $this->parent $parent;
  36.         $this->lang $lang;
  37.         $this->createdAt = new \DateTimeImmutable();
  38.         $this->updatedAt = new \DateTimeImmutable();
  39.         $parent->addTranslation($this);
  40.     }
  41.     public function getTitle(): ?string
  42.     {
  43.         return $this->title;
  44.     }
  45.     public function setTitle(?string $title): self
  46.     {
  47.         $this->title $title;
  48.         return $this;
  49.     }
  50.     #[Groups(['read'])]
  51.     public function getFullDomainTitle(): ?string
  52.     {
  53.         return $this->getParentDomainTitle($this->getParent(), $this->lang) . $this->title;
  54.     }
  55.     private function getParentDomainTitle(Domain $domainLanguage $lang): ?string
  56.     {
  57.         if (! $domain->getParent()) {
  58.             return null;
  59.         }
  60.         /** @var DomainTranslation */
  61.         $langTranslation $domain->getTranslations()[$lang->value];
  62.         return $this->getParentDomainTitle($domain->getParent(), $lang)
  63.             . $langTranslation->getTitle()
  64.             . ' - ';
  65.     }
  66. }