<?php
namespace App\Entity;
use App\Repository\GroupUserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=GroupUserRepository::class)
*/
class GroupUser
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\Column(type="string", length=255)
*/
private $code;
/**
* @ORM\ManyToMany(targetEntity=Right::class, mappedBy="groups")
*/
private $rights;
/**
* @ORM\OneToMany(targetEntity=User::class, mappedBy="groupUser")
*/
private $users;
public function __construct()
{
$this->rights = new ArrayCollection();
$this->users = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(string $code): self
{
$this->code = $code;
return $this;
}
/**
* @return Collection|Right[]
*/
public function getRights(): Collection
{
return $this->rights;
}
public function addRight(Right $right): self
{
if (!$this->rights->contains($right)) {
$this->rights[] = $right;
$right->addGroup($this);
}
return $this;
}
public function removeRight(Right $right): self
{
if ($this->rights->removeElement($right)) {
$right->removeGroup($this);
}
return $this;
}
/**
* @return Collection|User[]
*/
public function getUsers(): Collection
{
return $this->users;
}
public function addUser(User $user): self
{
if (!$this->users->contains($user)) {
$this->users[] = $user;
$user->setGroupUser($this);
}
return $this;
}
public function removeUser(User $user): self
{
if ($this->users->removeElement($user)) {
// set the owning side to null (unless already changed)
if ($user->getGroupUser() === $this) {
$user->setGroupUser(null);
}
}
return $this;
}
}