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.     public function __construct()
  45.     {
  46.         $this->createdAt = new \DateTime();
  47.         $this->childrens = new ArrayCollection();
  48.     }
  49.     public function getId(): ?int
  50.     {
  51.         return $this->id;
  52.     }
  53.     public function getName(): ?string
  54.     {
  55.         return $this->name;
  56.     }
  57.     public function setName(string $name): self
  58.     {
  59.         $this->name $name;
  60.         return $this;
  61.     }
  62.     public function getCreatedAt(): ?\DateTimeInterface
  63.     {
  64.         return $this->createdAt;
  65.     }
  66.     public function setCreatedAt(?\DateTimeInterface $createdAt): self
  67.     {
  68.         $this->createdAt $createdAt;
  69.         return $this;
  70.     }
  71.     public function getParent(): ?self
  72.     {
  73.         return $this->parent;
  74.     }
  75.     public function setParent(?self $parent): self
  76.     {
  77.         $this->parent $parent;
  78.         return $this;
  79.     }
  80.     /**
  81.      * @return Collection|self[]
  82.      */
  83.     public function getChildrens(): Collection
  84.     {
  85.         return $this->childrens;
  86.     }
  87.     public function addChildren(self $children): self
  88.     {
  89.         if (!$this->childrens->contains($children)) {
  90.             $this->childrens[] = $children;
  91.             $children->setParent($this);
  92.         }
  93.         return $this;
  94.     }
  95.     public function removeChildren(self $children): self
  96.     {
  97.         if ($this->childrens->removeElement($children)) {
  98.             // set the owning side to null (unless already changed)
  99.             if ($children->getParent() === $this) {
  100.                 $children->setParent(null);
  101.             }
  102.         }
  103.         return $this;
  104.     }
  105.     public function isEnabled(): bool
  106.     {
  107.         return $this->enabled;
  108.     }
  109.     public function setEnabled(bool $enabled): void
  110.     {
  111.         $this->enabled $enabled;
  112.     }
  113.     public function __toString()
  114.     {
  115.         return '#'.$this->id.' - '.$this->name;
  116.     }
  117. }