<?php
declare(strict_types=1);
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as Serializer;
/**
* @ORM\Entity(repositoryClass=FaqCategoriesRepository::class)
*/
class FaqCategories
{
const RESOURCE_KEY = 'faqcategories';
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @var Collection<string, FaqCategoriesTranslation>
*
* @ORM\OneToMany(targetEntity="App\Entity\FaqCategoriesTranslation", mappedBy="FaqCategories", cascade={"ALL"}, indexBy="locale")
*
* @Serializer\Exclude
*/
private $translations;
/**
* @var string
*/
private $locale="en";
public function __construct()
{
$this->translations = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
/**
* @Serializer\VirtualProperty(name="title")
*/
public function getTitle(): ?string
{
$translation = $this->getTranslation($this->locale);
if (!$translation) {
return null;
}
return $translation->getTitle();
}
public function setTitle(?string $title): self
{
$translation = $this->getTranslation($this->locale);
if (!$translation) {
$translation = $this->createTranslation($this->locale);
}
$translation->setTitle($title);
return $this;
}
/**
* @Serializer\VirtualProperty(name="description")
*/
public function getDescription(): ?string
{
$translation = $this->getTranslation($this->locale);
if (!$translation) {
return null;
}
return $translation->getDescription();
}
public function setDescription(?string $description): self
{
$translation = $this->getTranslation($this->locale);
if (!$translation) {
$translation = $this->createTranslation($this->locale);
}
$translation->setDescription($description);
return $this;
}
public function getLocale(): string
{
return $this->locale;
}
public function setLocale(?string $locale): self
{
$this->locale = $locale;
return $this;
}
/**
* @return FaqCategoriesTranslation[]
*/
public function getTranslations(): array
{
return $this->translations->toArray();
}
protected function getTranslation(string $locale): ?FaqCategoriesTranslation
{
if (!$this->translations->containsKey($locale)) {
return null;
}
return $this->translations->get($locale);
}
protected function createTranslation(string $locale): FaqCategoriesTranslation
{
$translation = new FaqCategoriesTranslation($this, $locale);
$this->translations->set($locale, $translation);
return $translation;
}
public function __toString()
{
$translation = $this->getTranslation($this->locale);
if (!$translation) {
return null;
}
return $translation->getTitle();
}
}