src/Entity/Category.php line 13

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CategoryRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Gedmo\Mapping\Annotation as Gedmo;
  8. use Gedmo\Translatable\Translatable;
  9. #[ORM\Entity(repositoryClassCategoryRepository::class)]
  10. class Category implements Translatable
  11. {
  12.     #[ORM\Id]
  13.     #[ORM\GeneratedValue]
  14.     #[ORM\Column]
  15.     private ?int $id null;
  16.     #[Gedmo\Translatable]
  17.     #[ORM\Column(length255)]
  18.     private ?string $title null;
  19.     #[ORM\OneToMany(mappedBy'category'targetEntityWarEvent::class)]
  20.     #[ORM\OrderBy(['date' => 'ASC'])]
  21.     private Collection $warEvents;
  22.     #[Gedmo\Locale]
  23.     private string $locale '';
  24.     #[ORM\Column(length255)]
  25.     private ?string $slug null;
  26.     #[ORM\Column(nullabletrue)]
  27.     private ?int $weight null;
  28.     public function __construct()
  29.     {
  30.         $this->warEvents = new ArrayCollection();
  31.     }
  32.     public static function new(): Category
  33.     {
  34.         return new Category();
  35.     }
  36.     public function getId(): ?int
  37.     {
  38.         return $this->id;
  39.     }
  40.     public function getTitle(): ?string
  41.     {
  42.         return $this->title;
  43.     }
  44.     public function setTitle(string $title): self
  45.     {
  46.         $this->title $title;
  47.         return $this;
  48.     }
  49.     /**
  50.      * @return Collection<int, WarEvent>
  51.      */
  52.     public function getWarEvents(): Collection
  53.     {
  54.         return $this->warEvents;
  55.     }
  56.     public function addWarEvent(WarEvent $warEvent): self
  57.     {
  58.         if (!$this->warEvents->contains($warEvent)) {
  59.             $this->warEvents->add($warEvent);
  60.             $warEvent->setCategory($this);
  61.         }
  62.         return $this;
  63.     }
  64.     public function removeWarEvent(WarEvent $warEvent): self
  65.     {
  66.         if ($this->warEvents->removeElement($warEvent)) {
  67.             // set the owning side to null (unless already changed)
  68.             if ($warEvent->getCategory() === $this) {
  69.                 $warEvent->setCategory(null);
  70.             }
  71.         }
  72.         return $this;
  73.     }
  74.     public function __toString(): string
  75.     {
  76.         return strval($this->title);
  77.     }
  78.     public function setTranslatableLocale($locale)
  79.     {
  80.         $this->locale $locale;
  81.     }
  82.     public function getLocale(): string
  83.     {
  84.         return $this->locale;
  85.     }
  86.     public function getSlug(): ?string
  87.     {
  88.         return $this->slug;
  89.     }
  90.     public function setSlug(string $slug): self
  91.     {
  92.         $this->slug $slug;
  93.         return $this;
  94.     }
  95.     public function filterWarEvents(): self
  96.     {
  97.         $this->warEvents $this->warEvents->filter(function (WarEvent $event) {
  98.             return $event->isVisible();
  99.         });
  100.         return $this;
  101.     }
  102.     public function getWeight(): ?int
  103.     {
  104.         return $this->weight;
  105.     }
  106.     public function setWeight(?int $weight): self
  107.     {
  108.         $this->weight $weight;
  109.         return $this;
  110.     }
  111. }