<?phpnamespace App\Entity;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;/** * @ORM\Entity(repositoryClass="App\Repository\RoleRepository") * * @ORM\HasLifecycleCallbacks() */class Role{ public function __construct() { $this->users = new ArrayCollection(); } /** * @ORM\Id() * * @ORM\GeneratedValue() * * @ORM\Column(type="integer") */ private $id; /** * @ORM\Column(type="string", nullable=false, length=180) */ private $label = null; public function getId(): ?int { return $this->id; } public function getLabel() { return $this->label; } public function setLabel($label) { $this->label = $label; return $this; } // Special case: Role /** * @ORM\Column(type="string", length=180, unique=true) */ private $name; public function getName(): ?string { return $this->name; } public function setName(string $name): self { $this->name = $name; return $this; } /** * @ORM\Column(type="datetime", nullable=false) */ private $created_at; /** * @ORM\Column(type="datetime", nullable=true) */ private $updated_at = null; public function getCreatedAt(): \DateTimeInterface { return $this->created_at; } public function setCreatedAt(\DateTimeInterface $created_at): self { $this->created_at = $created_at; return $this; } public function getUpdatedAt(): ?\DateTimeInterface { return $this->updated_at; } public function setUpdatedAt(?\DateTimeInterface $updated_at): self { $this->updated_at = $updated_at; return $this; } /** * @ORM\PrePersist */ public function setCreatedAtValue() { $this->setCreatedAt(new \DateTime()); } /** * @ORM\PreUpdate */ public function setUpdatedAtValue() { $this->setUpdatedAt(new \DateTime()); } /** * @ORM\Column(type="datetime", nullable=true) */ private $deleted_at; public function getDeletedAt(): ?\DateTimeInterface { return $this->deleted_at; } public function setDeletedAt(?\DateTimeInterface $deleted_at): self { $this->deleted_at = $deleted_at; return $this; } // Target of a LinkedEntity from RoleController (Controller) // Origin of a OneToMany with User (Entity) /** * @ORM\OneToMany(targetEntity="App\Entity\User", mappedBy="role") */ private $users; /** * @ORM\Column(type="array", nullable=true) */ private $privileges = []; /** * @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->setRole($this); } return $this; } public function removeUser(User $user): self { if ($this->users->contains($user)) { $this->users->removeElement($user); if ($user->getRole() === $this) { $user->setRole(null); } } return $this; } public function getPrivileges(): ?array { if (!\is_array($this->privileges)) { return []; } return array_values($this->privileges); } public function setPrivileges(?array $privileges): self { if (\is_array($privileges)) { $this->privileges = array_values($privileges); } else { $this->privileges = $privileges; } return $this; }}