src/Entity/UseCaseTopic.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 UseCaseTopic
{
final public const RESOURCE_KEY = 'use_case_topics';
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: Types::INTEGER)]
private ?int $id = null;
#[ORM\OneToMany(mappedBy: 'useCaseTopic', targetEntity: UseCase::class)]
private ?Collection $useCases;
#[ORM\Column(type: Types::STRING, length: 255, nullable: false)]
private ?string $color = null;
/**
* @var Collection<string, UseCaseTopicTranslation>
*/
#[ORM\OneToMany(mappedBy: 'useCaseTopic', targetEntity: UseCaseTopicTranslation::class, cascade: ['persist'], indexBy: 'locale')]
private Collection $translations;
private string $locale;
public function __construct()
{
$this->useCases = new ArrayCollection();
$this->translations = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
$translation = $this->getTranslation($this->locale);
if (!$translation instanceof UseCaseTopicTranslation) {
return null;
}
return $translation->getTitle();
}
public function setTitle(string $title): void
{
$translation = $this->getTranslation($this->locale);
if (!$translation instanceof UseCaseTopicTranslation) {
$translation = $this->createTranslation($this->locale);
}
$translation->setTitle($title);
}
public function getDescription(): ?string
{
$translation = $this->getTranslation($this->locale);
if (!$translation instanceof UseCaseTopicTranslation) {
return null;
}
return $translation->getDescription();
}
public function setDescription(string $description): void
{
$translation = $this->getTranslation($this->locale);
if (!$translation instanceof UseCaseTopicTranslation) {
$translation = $this->createTranslation($this->locale);
}
$translation->setDescription($description);
}
public function addUseCase(UseCase $useCase): static
{
if(!$this->useCases->contains($useCase)) {
$this->useCases[] = $useCase;
}
return $this;
}
public function removeUseCase(UseCase $useCase): static
{
if($this->useCases->contains($useCase)) {
$this->useCases->removeElement($useCase);
}
return $this;
}
public function getUseCases(): Collection
{
return $this->useCases;
}
public function getColor(): ?string
{
return $this->color;
}
public function setColor(?string $color): void
{
$this->color = $color;
}
public function getLocale(): string
{
return $this->locale;
}
public function setLocale(string $locale): self
{
$this->locale = $locale;
return $this;
}
/**
* @return UseCaseTopicTranslation[]
*/
public function getTranslations(): array
{
return $this->translations->toArray();
}
protected function getTranslation(string $locale): ?UseCaseTopicTranslation
{
if (!$this->translations->containsKey($locale)) {
return null;
}
return $this->translations->get($locale);
}
protected function createTranslation(string $locale): UseCaseTopicTranslation
{
$translation = new UseCaseTopicTranslation($this, $locale);
$this->translations->set($locale, $translation);
return $translation;
}
}