src/Entity/JurisprudenceCategory.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\JurisprudenceCategoryRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use phpDocumentor\Reflection\PseudoTypes\False_;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. /**
  10.  * @ORM\Entity(repositoryClass=JurisprudenceCategoryRepository::class)
  11.  */
  12. class JurisprudenceCategory
  13. {
  14.     /**
  15.      * @ORM\Id
  16.      * @ORM\GeneratedValue
  17.      * @ORM\Column(type="integer")
  18.      */
  19.     private $id;
  20.     /**
  21.      * @Assert\NotBlank
  22.      * @ORM\Column(type="string", length=255)
  23.      */
  24.     private string $name;
  25.     /**
  26.      * @ORM\Column(type="boolean")
  27.      */
  28.     private bool $enabled false;
  29.     /**
  30.      * @ORM\Column(type="datetime", nullable=true)
  31.      */
  32.     private ?\Datetime $createdAt;
  33.     /**
  34.      * @var JurisprudenceCategory
  35.      * @ORM\ManyToOne(targetEntity=JurisprudenceCategory::class, inversedBy="childrens")
  36.      * @ORM\JoinColumn(nullable="true", onDelete="SET NULL")
  37.      */
  38.     private ?JurisprudenceCategory $parent;
  39.     /**
  40.      * @var JurisprudenceCategory[]
  41.      * @ORM\OneToMany(targetEntity=JurisprudenceCategory::class, mappedBy="parent")
  42.      */
  43.     private $childrens;
  44.     /**
  45.      * @ORM\ManyToMany(targetEntity="App\Entity\Jurisprudence", mappedBy="category")
  46.      */
  47.     private $jps;
  48.     public function __construct()
  49.     {
  50.         $this->createdAt = new \DateTime();
  51.         $this->childrens = new ArrayCollection();
  52.         $this->jps = new ArrayCollection();
  53.     }
  54.     public function getId(): ?int
  55.     {
  56.         return $this->id;
  57.     }
  58.     public function getName(): ?string
  59.     {
  60.         return $this->name;
  61.     }
  62.     public function setName(string $name): self
  63.     {
  64.         $this->name $name;
  65.         return $this;
  66.     }
  67.     public function getCreatedAt(): ?\DateTimeInterface
  68.     {
  69.         return $this->createdAt;
  70.     }
  71.     public function setCreatedAt(?\DateTimeInterface $createdAt): self
  72.     {
  73.         $this->createdAt $createdAt;
  74.         return $this;
  75.     }
  76.     public function getParent(): ?self
  77.     {
  78.         return $this->parent;
  79.     }
  80.     public function setParent(?self $parent): self
  81.     {
  82.         $this->parent $parent;
  83.         return $this;
  84.     }
  85.     /**
  86.      * @return Collection|self[]
  87.      */
  88.     public function getChildrens(): Collection
  89.     {
  90.         return $this->childrens;
  91.     }
  92.     public function addChildren(self $children): self
  93.     {
  94.         if (!$this->childrens->contains($children)) {
  95.             $this->childrens[] = $children;
  96.             $children->setParent($this);
  97.         }
  98.         return $this;
  99.     }
  100.     public function removeChildren(self $children): self
  101.     {
  102.         if ($this->childrens->removeElement($children)) {
  103.             // set the owning side to null (unless already changed)
  104.             if ($children->getParent() === $this) {
  105.                 $children->setParent(null);
  106.             }
  107.         }
  108.         return $this;
  109.     }
  110.     public function isEnabled(): bool
  111.     {
  112.         return $this->enabled;
  113.     }
  114.     public function setEnabled(bool $enabled): void
  115.     {
  116.         $this->enabled $enabled;
  117.     }
  118.     public function __toString()
  119.     {
  120.         return '#'.$this->id.' - '.$this->name;
  121.     }
  122.     /**
  123.      * @return Collection<int, Jurisprudence>
  124.      */
  125.     public function getJps(): Collection
  126.     {
  127.         return $this->jps;
  128.     }
  129.     public function addJp(Jurisprudence $jp): self
  130.     {
  131.         if (!$this->jps->contains($jp)) {
  132.             $this->jps[] = $jp;
  133.             $jp->addCategory($this);
  134.         }
  135.         return $this;
  136.     }
  137.     public function removeJp(Jurisprudence $jp): self
  138.     {
  139.         if ($this->jps->removeElement($jp)) {
  140.             $jp->removeCategory($this);
  141.         }
  142.         return $this;
  143.     }
  144. }