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.     #[ORM\Column(typeTypes::STRINGlength255nullabletrue)]
  24.     private ?string $imageMobile null;
  25.     /**
  26.      * @var Collection<string, UseCaseTranslation>
  27.      */
  28.     #[ORM\OneToMany(mappedBy'useCase'targetEntityUseCaseTranslation::class, cascade: ['persist'], indexBy'locale')]
  29.     private Collection $translations;
  30.     private string $locale;
  31.     public function __construct()
  32.     {
  33.         $this->translations = new ArrayCollection();
  34.     }
  35.     public function getId(): ?int
  36.     {
  37.         return $this->id;
  38.     }
  39.     public function setUseCaseTopic(?UseCaseTopic $topic): void
  40.     {
  41.         $this->useCaseTopic $topic;
  42.     }
  43.     public function getUseCaseTopic(): ?UseCaseTopic
  44.     {
  45.         return $this->useCaseTopic;
  46.     }
  47.     public function getTitle(): ?string
  48.     {
  49.         $translation $this->getTranslation($this->locale);
  50.         if (!$translation instanceof UseCaseTranslation) {
  51.             return null;
  52.         }
  53.         return $translation->getTitle();
  54.     }
  55.     public function setTitle(string $title): void
  56.     {
  57.         $translation $this->getTranslation($this->locale);
  58.         if (!$translation instanceof UseCaseTranslation) {
  59.             $translation $this->createTranslation($this->locale);
  60.         }
  61.         $translation->setTitle($title);
  62.     }
  63.     public function getTitleMobile(): ?string
  64.     {
  65.         $translation $this->getTranslation($this->locale);
  66.         if (!$translation instanceof UseCaseTranslation) {
  67.             return null;
  68.         }
  69.         return $translation->getTitleMobile();
  70.     }
  71.     public function setTitleMobile(string $title): void
  72.     {
  73.         $translation $this->getTranslation($this->locale);
  74.         if (!$translation instanceof UseCaseTranslation) {
  75.             $translation $this->createTranslation($this->locale);
  76.         }
  77.         $translation->setTitleMobile($title);
  78.     }
  79.     public function getDescription(): ?string
  80.     {
  81.         $translation $this->getTranslation($this->locale);
  82.         if (!$translation instanceof UseCaseTranslation) {
  83.             return null;
  84.         }
  85.         return $translation->getDescription();
  86.     }
  87.     public function setDescription(string $description): void
  88.     {
  89.         $translation $this->getTranslation($this->locale);
  90.         if (!$translation instanceof UseCaseTranslation) {
  91.             $translation $this->createTranslation($this->locale);
  92.         }
  93.         $translation->setDescription($description);
  94.     }
  95.     public function getImage(): ?string
  96.     {
  97.         return $this->image;
  98.     }
  99.     public function setImage(string $image): void
  100.     {
  101.         $this->image $image;
  102.     }
  103.     public function getImageMobile(): ?string
  104.     {
  105.         return $this->imageMobile;
  106.     }
  107.     public function setImageMobile(string $image): void
  108.     {
  109.         $this->imageMobile $image;
  110.     }
  111.     public function getLocale(): string
  112.     {
  113.         return $this->locale;
  114.     }
  115.     public function setLocale(string $locale): self
  116.     {
  117.         $this->locale $locale;
  118.         return $this;
  119.     }
  120.     /**
  121.      * @return UseCaseTranslation[]
  122.      */
  123.     public function getTranslations(): array
  124.     {
  125.         return $this->translations->toArray();
  126.     }
  127.     protected function getTranslation(string $locale): ?UseCaseTranslation
  128.     {
  129.         if (!$this->translations->containsKey($locale)) {
  130.             return null;
  131.         }
  132.         return $this->translations->get($locale);
  133.     }
  134.     protected function createTranslation(string $locale): UseCaseTranslation
  135.     {
  136.         $translation = new UseCaseTranslation($this$locale);
  137.         $this->translations->set($locale$translation);
  138.         return $translation;
  139.     }
  140. }