src/Entity/UseCase.php line 15

  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity;
  4. use App\Repository\NewsRepository;
  5. use App\Repository\UseCaseTopicRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\DBAL\Types\Types;
  9. use Doctrine\ORM\Mapping as ORM;
  10. #[ORM\Entity(repositoryClassUseCaseTopicRepository::class)]
  11. class UseCase
  12. {
  13.     final public const RESOURCE_KEY 'use_cases';
  14.     #[ORM\Id]
  15.     #[ORM\GeneratedValue]
  16.     #[ORM\Column(typeTypes::INTEGER)]
  17.     private ?int $id null;
  18.     #[ORM\ManyToOne(targetEntityUseCaseTopic::class, inversedBy'useCases')]
  19.     #[ORM\JoinColumn(nullabletrueonDelete'SET NULL')]
  20.     private ?UseCaseTopic $useCaseTopic null;
  21.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  22.     private ?string $image null;
  23.     /**
  24.      * @var Collection<string, UseCaseTranslation>
  25.      */
  26.     #[ORM\OneToMany(mappedBy'useCase'targetEntityUseCaseTranslation::class, cascade: ['persist'], indexBy'locale')]
  27.     private Collection $translations;
  28.     private string $locale;
  29.     public function __construct()
  30.     {
  31.         $this->translations = new ArrayCollection();
  32.     }
  33.     public function getId(): ?int
  34.     {
  35.         return $this->id;
  36.     }
  37.     public function setUseCaseTopic(?UseCaseTopic $topic): void
  38.     {
  39.         $this->useCaseTopic $topic;
  40.     }
  41.     public function getUseCaseTopic(): ?UseCaseTopic
  42.     {
  43.         return $this->useCaseTopic;
  44.     }
  45.     public function getTitle(): ?string
  46.     {
  47.         $translation $this->getTranslation($this->locale);
  48.         if (!$translation instanceof UseCaseTranslation) {
  49.             return null;
  50.         }
  51.         return $translation->getTitle();
  52.     }
  53.     public function setTitle(string $title): void
  54.     {
  55.         $translation $this->getTranslation($this->locale);
  56.         if (!$translation instanceof UseCaseTranslation) {
  57.             $translation $this->createTranslation($this->locale);
  58.         }
  59.         $translation->setTitle($title);
  60.     }
  61.     public function getTitleMobile(): ?string
  62.     {
  63.         $translation $this->getTranslation($this->locale);
  64.         if (!$translation instanceof UseCaseTranslation) {
  65.             return null;
  66.         }
  67.         return $translation->getTitleMobile();
  68.     }
  69.     public function setTitleMobile(string $title): void
  70.     {
  71.         $translation $this->getTranslation($this->locale);
  72.         if (!$translation instanceof UseCaseTranslation) {
  73.             $translation $this->createTranslation($this->locale);
  74.         }
  75.         $translation->setTitleMobile($title);
  76.     }
  77.     public function getDescription(): ?string
  78.     {
  79.         $translation $this->getTranslation($this->locale);
  80.         if (!$translation instanceof UseCaseTranslation) {
  81.             return null;
  82.         }
  83.         return $translation->getDescription();
  84.     }
  85.     public function setDescription(string $description): void
  86.     {
  87.         $translation $this->getTranslation($this->locale);
  88.         if (!$translation instanceof UseCaseTranslation) {
  89.             $translation $this->createTranslation($this->locale);
  90.         }
  91.         $translation->setDescription($description);
  92.     }
  93.     public function getImage(): ?string
  94.     {
  95.         return $this->image;
  96.     }
  97.     public function setImage(string $image): void
  98.     {
  99.         $this->image $image;
  100.     }
  101.     public function getTags(): ?array
  102.     {
  103.         $translation $this->getTranslation($this->locale);
  104.         if (!$translation instanceof UseCaseTranslation) {
  105.             return null;
  106.         }
  107.         return $translation->getTags();
  108.     }
  109.     public function setTags(array $tags): void
  110.     {
  111.         $translation $this->getTranslation($this->locale);
  112.         if (!$translation instanceof UseCaseTranslation) {
  113.             $translation $this->createTranslation($this->locale);
  114.         }
  115.         $translation->setTags($tags);
  116.     }
  117.     public function getLocale(): string
  118.     {
  119.         return $this->locale;
  120.     }
  121.     public function setLocale(string $locale): self
  122.     {
  123.         $this->locale $locale;
  124.         return $this;
  125.     }
  126.     /**
  127.      * @return UseCaseTranslation[]
  128.      */
  129.     public function getTranslations(): array
  130.     {
  131.         return $this->translations->toArray();
  132.     }
  133.     protected function getTranslation(string $locale): ?UseCaseTranslation
  134.     {
  135.         if (!$this->translations->containsKey($locale)) {
  136.             return null;
  137.         }
  138.         return $this->translations->get($locale);
  139.     }
  140.     protected function createTranslation(string $locale): UseCaseTranslation
  141.     {
  142.         $translation = new UseCaseTranslation($this$locale);
  143.         $this->translations->set($locale$translation);
  144.         return $translation;
  145.     }
  146. }