src/Entity/UseCase.php line 15
<?php
declare(strict_types=1);
namespace App\Entity;
use App\Repository\NewsRepository;
use App\Repository\UseCaseTopicRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: UseCaseTopicRepository::class)]
class UseCase
{
final public const RESOURCE_KEY = 'use_cases';
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: Types::INTEGER)]
private ?int $id = null;
#[ORM\ManyToOne(targetEntity: UseCaseTopic::class, inversedBy: 'useCases')]
#[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
private ?UseCaseTopic $useCaseTopic = null;
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
private ?string $image = null;
/**
* @var Collection<string, UseCaseTranslation>
*/
#[ORM\OneToMany(mappedBy: 'useCase', targetEntity: UseCaseTranslation::class, cascade: ['persist'], indexBy: 'locale')]
private Collection $translations;
private string $locale;
public function __construct()
{
$this->translations = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function setUseCaseTopic(?UseCaseTopic $topic): void
{
$this->useCaseTopic = $topic;
}
public function getUseCaseTopic(): ?UseCaseTopic
{
return $this->useCaseTopic;
}
public function getTitle(): ?string
{
$translation = $this->getTranslation($this->locale);
if (!$translation instanceof UseCaseTranslation) {
return null;
}
return $translation->getTitle();
}
public function setTitle(string $title): void
{
$translation = $this->getTranslation($this->locale);
if (!$translation instanceof UseCaseTranslation) {
$translation = $this->createTranslation($this->locale);
}
$translation->setTitle($title);
}
public function getTitleMobile(): ?string
{
$translation = $this->getTranslation($this->locale);
if (!$translation instanceof UseCaseTranslation) {
return null;
}
return $translation->getTitleMobile();
}
public function setTitleMobile(string $title): void
{
$translation = $this->getTranslation($this->locale);
if (!$translation instanceof UseCaseTranslation) {
$translation = $this->createTranslation($this->locale);
}
$translation->setTitleMobile($title);
}
public function getDescription(): ?string
{
$translation = $this->getTranslation($this->locale);
if (!$translation instanceof UseCaseTranslation) {
return null;
}
return $translation->getDescription();
}
public function setDescription(string $description): void
{
$translation = $this->getTranslation($this->locale);
if (!$translation instanceof UseCaseTranslation) {
$translation = $this->createTranslation($this->locale);
}
$translation->setDescription($description);
}
public function getImage(): ?string
{
return $this->image;
}
public function setImage(string $image): void
{
$this->image = $image;
}
public function getTags(): ?array
{
$translation = $this->getTranslation($this->locale);
if (!$translation instanceof UseCaseTranslation) {
return null;
}
return $translation->getTags();
}
public function setTags(array $tags): void
{
$translation = $this->getTranslation($this->locale);
if (!$translation instanceof UseCaseTranslation) {
$translation = $this->createTranslation($this->locale);
}
$translation->setTags($tags);
}
public function getLocale(): string
{
return $this->locale;
}
public function setLocale(string $locale): self
{
$this->locale = $locale;
return $this;
}
/**
* @return UseCaseTranslation[]
*/
public function getTranslations(): array
{
return $this->translations->toArray();
}
protected function getTranslation(string $locale): ?UseCaseTranslation
{
if (!$this->translations->containsKey($locale)) {
return null;
}
return $this->translations->get($locale);
}
protected function createTranslation(string $locale): UseCaseTranslation
{
$translation = new UseCaseTranslation($this, $locale);
$this->translations->set($locale, $translation);
return $translation;
}
}