src/Entity/Gos/Group.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Gos;
  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\Gos\GroupRepository")
  8.  * @ORM\Table(name="user_groups")
  9.  */
  10. class Group
  11. {
  12.     /**
  13.      * @ORM\Id()
  14.      * @ORM\GeneratedValue()
  15.      * @ORM\Column(type="integer")
  16.      */
  17.     private $id;
  18.     /**
  19.      * @ORM\Column(type="string")
  20.      */
  21.     private $name;
  22.     /**
  23.      * @ORM\Column(type="array")
  24.      */
  25.     private $roles;
  26.     /**
  27.      * @ORM\ManyToMany(targetEntity="App\Entity\Gos\User", mappedBy="groups")
  28.      */
  29.     private $users;
  30.     public function __construct()
  31.     {
  32.         $this->users = new ArrayCollection();
  33.         $this->roles = array();
  34.     }
  35.     public function __toString()
  36.     {
  37.         return $this->name;
  38.     }
  39.     public function getId(): ?int
  40.     {
  41.         return $this->id;
  42.     }
  43.     /**
  44.      * @return Collection|User[]
  45.      */
  46.     public function getUsers(): Collection
  47.     {
  48.         return $this->users;
  49.     }
  50.     public function addUser(User $user): self
  51.     {
  52.         if (!$this->users->contains($user)) {
  53.             $this->users[] = $user;
  54.             $user->addGroup($this);
  55.         }
  56.         return $this;
  57.     }
  58.     public function removeUser(User $user): self
  59.     {
  60.         if ($this->users->contains($user)) {
  61.             $this->users->removeElement($user);
  62.             $user->removeGroup($this);
  63.         }
  64.         return $this;
  65.     }
  66.     public function getName(): ?string
  67.     {
  68.         return $this->name;
  69.     }
  70.     public function setName(string $name): self
  71.     {
  72.         $this->name $name;
  73.         return $this;
  74.     }
  75.     public function getRoles(): ?array
  76.     {
  77.         return $this->roles;
  78.     }
  79.     public function hasRole($role): bool
  80.     {
  81.         return in_array(strtoupper($role), $this->rolestrue);
  82.     }
  83.     public function addRole($role): self
  84.     {
  85.         if (!$this->hasRole($role))
  86.         {
  87.             $this->roles[] = strtoupper($role);
  88.         }
  89.         return $this;
  90.     }
  91.     public function setRoles(array $roles): self
  92.     {
  93.         $this->roles $roles;
  94.         return $this;
  95.     }
  96.     public function removeRole($role): self
  97.     {
  98.         if (false !== $key array_search(strtoupper($role), $this->rolestrue))
  99.         {
  100.             unset($this->roles[$key]);
  101.             $this->roles array_values($this->roles);
  102.         }
  103.         return $this;
  104.     }
  105. }