src/Entity/ModelMenu.php line 16

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ModelMenuRepository;
  4. use App\Trait\ActivableTrait;
  5. use App\Trait\DateTrait;
  6. use App\Trait\DeletableTrait;
  7. use DateTimeImmutable;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Doctrine\Common\Collections\Collection;
  10. use Doctrine\DBAL\Types\Types;
  11. use Doctrine\ORM\Mapping as ORM;
  12. #[ORM\Entity(repositoryClassModelMenuRepository::class)]
  13. class ModelMenu
  14. {
  15.     use ActivableTrait;
  16.     use DateTrait;
  17.     use DeletableTrait;
  18.     #[ORM\Id]
  19.     #[ORM\GeneratedValue]
  20.     #[ORM\Column]
  21.     private ?int $id null;
  22.     #[ORM\ManyToMany(targetEntityModel::class)]
  23.     private Collection $model;
  24.     #[ORM\Column(length255)]
  25.     private ?string $name null;
  26.     #[ORM\Column(length255nullabletrue)]
  27.     private ?string $icon null;
  28.     #[ORM\Column(length255nullabletrue)]
  29.     private ?string $path null;
  30.     #[ORM\Column(typeTypes::JSON)]
  31.     private array $permissions = [];
  32.     #[ORM\ManyToOne(targetEntityself::class, inversedBy'modelSubmenus')]
  33.     private ?self $parent null;
  34.     #[ORM\OneToMany(mappedBy'parent'targetEntityself::class, cascade: ['all'], orphanRemovaltrue)]
  35.     private Collection $modelSubmenus;
  36.     public function __construct()
  37.     {
  38.         $this->isActive true;
  39.         if (is_null($this->createdAt)) $this->createdAt = new DateTimeImmutable();
  40.         $this->updatedAt = new DateTimeImmutable();
  41.         $this->model = new ArrayCollection();
  42.         $this->modelSubmenus = new ArrayCollection();
  43.     }
  44.     public function getId(): ?int
  45.     {
  46.         return $this->id;
  47.     }
  48.     /**
  49.      * @return Collection<int, Model>
  50.      */
  51.     public function getModel(): Collection
  52.     {
  53.         return $this->model;
  54.     }
  55.     public function addModel(Model $model): self
  56.     {
  57.         if (!$this->model->contains($model)) {
  58.             $this->model->add($model);
  59.         }
  60.         return $this;
  61.     }
  62.     public function removeModel(Model $model): self
  63.     {
  64.         $this->model->removeElement($model);
  65.         return $this;
  66.     }
  67.     public function getName(): ?string
  68.     {
  69.         return $this->name;
  70.     }
  71.     public function setName(string $name): self
  72.     {
  73.         $this->name $name;
  74.         return $this;
  75.     }
  76.     public function getIcon(): ?string
  77.     {
  78.         return $this->icon;
  79.     }
  80.     public function setIcon(?string $icon): self
  81.     {
  82.         $this->icon $icon;
  83.         return $this;
  84.     }
  85.     public function getPath(): ?string
  86.     {
  87.         return $this->path;
  88.     }
  89.     public function setPath(?string $path): self
  90.     {
  91.         $this->path $path;
  92.         return $this;
  93.     }
  94.     public function getPermissions(): array
  95.     {
  96.         return $this->permissions;
  97.     }
  98.     public function setPermissions(array $permissions): self
  99.     {
  100.         $this->permissions $permissions;
  101.         return $this;
  102.     }
  103.     public function getParent(): ?self
  104.     {
  105.         return $this->parent;
  106.     }
  107.     public function setParent(?self $parent): self
  108.     {
  109.         $this->parent $parent;
  110.         return $this;
  111.     }
  112.     /**
  113.      * @return Collection<int, self>
  114.      */
  115.     public function getModelSubmenus(): Collection
  116.     {
  117.         return $this->modelSubmenus;
  118.     }
  119.     public function addModelSubmenu(self $modelSubmenu): self
  120.     {
  121.         if (!$this->modelSubmenus->contains($modelSubmenu)) {
  122.             $this->modelSubmenus->add($modelSubmenu);
  123.             $modelSubmenu->setParent($this);
  124.         }
  125.         return $this;
  126.     }
  127.     public function removeModelSubmenu(self $modelSubmenu): self
  128.     {
  129.         if ($this->modelSubmenus->removeElement($modelSubmenu)) {
  130.             // set the owning side to null (unless already changed)
  131.             if ($modelSubmenu->getParent() === $this) {
  132.                 $modelSubmenu->setParent(null);
  133.             }
  134.         }
  135.         return $this;
  136.     }
  137.     public function __toString(): string
  138.     {
  139.         return $this->name;
  140.     }
  141. }