src/Entity/Permission.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. /**
  7.  * @ORM\Entity(repositoryClass="App\Repository\PermissionRepository")
  8.  */
  9. class Permission
  10. {
  11.     /**
  12.      * @ORM\Id()
  13.      * @ORM\GeneratedValue()
  14.      * @ORM\Column(type="integer")
  15.      */
  16.     private $id;
  17.     /**
  18.      * @ORM\Column(type="string", length=255)
  19.      */
  20.     private $name;
  21.     /**
  22.      * @ORM\Column(type="string", length=255)
  23.      */
  24.     private $code;
  25.     /**
  26.      * @ORM\Column(type="text", nullable=true)
  27.      */
  28.     private $description;
  29.     /**
  30.      * @ORM\ManyToMany(targetEntity="App\Entity\UserGroup", mappedBy="permission")
  31.      */
  32.     private $userGroups;
  33.     public function __construct()
  34.     {
  35.         $this->userGroups = new ArrayCollection();
  36.     }
  37.     public function getId(): ?int
  38.     {
  39.         return $this->id;
  40.     }
  41.     public function getName(): ?string
  42.     {
  43.         return $this->name;
  44.     }
  45.     public function setName(string $name): self
  46.     {
  47.         $this->name $name;
  48.         return $this;
  49.     }
  50.     public function getCode(): ?string
  51.     {
  52.         return $this->code;
  53.     }
  54.     public function setCode(string $code): self
  55.     {
  56.         $this->code $code;
  57.         return $this;
  58.     }
  59.     public function getDescription(): ?string
  60.     {
  61.         return $this->description;
  62.     }
  63.     public function setDescription(?string $description): self
  64.     {
  65.         $this->description $description;
  66.         return $this;
  67.     }
  68.     /**
  69.      * @return Collection|UserGroup[]
  70.      */
  71.     public function getUserGroups(): Collection
  72.     {
  73.         return $this->userGroups;
  74.     }
  75.     public function addUserGroup(UserGroup $userGroup): self
  76.     {
  77.         if (!$this->userGroups->contains($userGroup)) {
  78.             $this->userGroups[] = $userGroup;
  79.             $userGroup->addPermission($this);
  80.         }
  81.         return $this;
  82.     }
  83.     public function removeUserGroup(UserGroup $userGroup): self
  84.     {
  85.         if ($this->userGroups->contains($userGroup)) {
  86.             $this->userGroups->removeElement($userGroup);
  87.             $userGroup->removePermission($this);
  88.         }
  89.         return $this;
  90.     }
  91.     public function __toString()
  92.     {
  93.         return $this->name;
  94.     }
  95.     public function getAllFields()
  96.     {
  97.         return get_object_vars($this);
  98.     }
  99. }