src/Entity/Categories.php line 11

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CategoriesRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ORM\Entity(repositoryClassCategoriesRepository::class)]
  8. class Categories
  9. {
  10.     #[ORM\Id]
  11.     #[ORM\GeneratedValue]
  12.     #[ORM\Column]
  13.     private ?int $id null;
  14.     #[ORM\Column(length255)]
  15.     private ?string $name null;
  16.     #[ORM\Column(nullabletrue)] // Champs facultatif, car une catégorie peut ne pas avoir d'icône
  17.     private ?string $icon null;
  18.    
  19.     #[ORM\ManyToOne(targetEntityself::class, inversedBy'categories')]
  20.     private ?self $parent null;
  21.     #[ORM\OneToMany(mappedBy'parent'targetEntityself::class)]
  22.     private Collection $categories;
  23.     #[ORM\OneToMany(mappedBy'categories'targetEntityActuality::class)]
  24.     private Collection $actualities;
  25.     #[ORM\OneToMany(mappedBy'categorie'targetEntityPrestation::class)]
  26.     private Collection $prestations;
  27.     public function __construct()
  28.     {
  29.         $this->categories = new ArrayCollection();
  30.         $this->actualities = new ArrayCollection();
  31.         $this->prestations = new ArrayCollection();
  32.     }
  33.     public function getId(): ?int
  34.     {
  35.         return $this->id;
  36.     }
  37.     public function getName(): ?string
  38.     {
  39.         return $this->name;
  40.     }
  41.     public function setName(string $name): self
  42.     {
  43.         $this->name $name;
  44.         return $this;
  45.     }
  46.     public function getParent(): ?self
  47.     {
  48.         return $this->parent;
  49.     }
  50.     public function setParent(?self $parent): self
  51.     {
  52.         $this->parent $parent;
  53.         return $this;
  54.     }
  55.     public function getIcon(): ?string
  56.     {
  57.         return $this->icon;
  58.     }
  59.     public function setIcon(?string $icon): self
  60.     {
  61.         $this->icon $icon;
  62.         return $this;
  63.     }
  64.     /**
  65.      * @return Collection<int, self>
  66.      */
  67.     public function getCategories(): Collection
  68.     {
  69.         return $this->categories;
  70.     }
  71.     public function addCategory(self $category): self
  72.     {
  73.         if (!$this->categories->contains($category)) {
  74.             $this->categories->add($category);
  75.             $category->setParent($this);
  76.         }
  77.         return $this;
  78.     }
  79.     public function removeCategory(self $category): self
  80.     {
  81.         if ($this->categories->removeElement($category)) {
  82.             // set the owning side to null (unless already changed)
  83.             if ($category->getParent() === $this) {
  84.                 $category->setParent(null);
  85.             }
  86.         }
  87.         return $this;
  88.     }
  89.     /**
  90.      * @return Collection<int, Actuality>
  91.      */
  92.     public function getActualities(): Collection
  93.     {
  94.         return $this->actualities;
  95.     }
  96.     public function addActuality(Actuality $actuality): self
  97.     {
  98.         if (!$this->actualities->contains($actuality)) {
  99.             $this->actualities->add($actuality);
  100.             $actuality->setCategories($this);
  101.         }
  102.         return $this;
  103.     }
  104.     public function removeActuality(Actuality $actuality): self
  105.     {
  106.         if ($this->actualities->removeElement($actuality)) {
  107.             // set the owning side to null (unless already changed)
  108.             if ($actuality->getCategories() === $this) {
  109.                 $actuality->setCategories(null);
  110.             }
  111.         }
  112.         return $this;
  113.     }
  114.     /**
  115.      * @return Collection<int, Prestation>
  116.      */
  117.     public function getPrestations(): Collection
  118.     {
  119.         return $this->prestations;
  120.     }
  121.     public function addPrestation(Prestation $prestation): static
  122.     {
  123.         if (!$this->prestations->contains($prestation)) {
  124.             $this->prestations->add($prestation);
  125.             $prestation->setCategorie($this);
  126.         }
  127.         return $this;
  128.     }
  129.     public function removePrestation(Prestation $prestation): static
  130.     {
  131.         if ($this->prestations->removeElement($prestation)) {
  132.             // set the owning side to null (unless already changed)
  133.             if ($prestation->getCategorie() === $this) {
  134.                 $prestation->setCategorie(null);
  135.             }
  136.         }
  137.         return $this;
  138.     }
  139. }