src/Entity/AffiliationTranslation.php line 31
<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM,
Doctrine\DBAL\Types\Types;
use Symfony\Component\Serializer\Annotation\Groups;
use ApiPlatform\Metadata\ApiProperty,
ApiPlatform\Metadata\ApiResource,
ApiPlatform\Metadata\Get;
use App\Entity\Trait\IdTrait,
App\Entity\Trait\UuidTrait,
App\Entity\Trait\TimestampableTrait,
App\Entity\Trait\TranslationTrait,
App\Entity\Trait\Media\ImageThumbableTrait,
App\Entity\Trait\SlugTrait,
App\Entity\Interface\TranslationInterface,
App\Entity\Interface\ThumbableInterface,
App\Enum\Language,
App\Repository\AffiliationTranslationRepository;
#[ApiResource(
security: 'is_granted("' . Affiliation::class . '")',
operations: [ new Get() ],
extraProperties: ['standard_put' => false],
)]
#[ORM\Entity(repositoryClass: AffiliationTranslationRepository::class)]
class AffiliationTranslation implements TranslationInterface, ThumbableInterface
{
use IdTrait,
UuidTrait,
TimestampableTrait,
TranslationTrait,
SlugTrait,
ImageThumbableTrait;
#[ApiProperty(description: 'Title')]
#[Groups(['read', 'write'])]
#[ORM\Column(type: Types::STRING, length: 1023, nullable: true)]
private ?string $title = null;
#[ApiProperty(description: 'Text')]
#[Groups(['read:' . self::class, 'write'])]
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $text = null;
#[ApiProperty(description: 'Alt')]
#[Groups(['read:' . self::class, 'write'])]
#[ORM\Column(type: Types::STRING, length: 1023, nullable: true)]
private ?string $alt = null;
public function __construct(Affiliation $parent, Language $lang)
{
$this->setUuid();
$this->parent = $parent;
$this->lang = $lang;
$this->thumbs = new ArrayCollection();
$this->createdAt = new \DateTimeImmutable();
$this->updatedAt = new \DateTimeImmutable();
$parent->addTranslation($this);
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(?string $title): self
{
$this->title = $title;
/** @var Affiliation */
$parent = $this->parent;
if ($this->lang === $parent->getNativeLanguage()) {
$parent->setNativeTitle($title);
}
return $this;
}
public function getText(): ?string
{
return $this->text;
}
public function setText(?string $text): self
{
$this->text = $text;
return $this;
}
public function getAlt(): ?string
{
return $this->alt;
}
public function setAlt(?string $alt): self
{
$this->alt = $alt;
return $this;
}
#[Groups(['read'])]
public function getFullAffiliationTitle(): ?string
{
return $this->getParentAffiliationTitle($this->getParent(), $this->lang) . $this->title;
}
private function getParentAffiliationTitle(Affiliation $affiliation, Language $lang): ?string
{
if (! $affiliation->getParent()) {
return null;
}
/** @var AffiliationTranslation */
$langTranslation = $affiliation->getTranslations()[$lang->value];
return $this->getParentAffiliationTitle($affiliation->getParent(), $lang)
. $langTranslation?->getTitle()
. ' - ';
}
}