<?php
namespace App\Entity;
use App\Repository\RoleRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: RoleRepository::class)]
#[ORM\Table(name: 'tb_roles')]
#[ORM\HasLifecycleCallbacks]
class Role
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: "integer", unique: true)]
private ?int $id;
#[ORM\Column(type: 'string', length: 50, nullable: false)]
private ?string $code;
#[ORM\Column(type: 'string', length: 50, nullable: false)]
private ?string $name;
#[ORM\Column(type: 'string', length: 100, nullable: false)]
private ?string $libelle;
#[ORM\Column(type: 'integer', nullable: false)]
private ?int $type;
#[ORM\Column(type: 'datetime', nullable: false)]
private \DateTimeInterface $createdAt;
#[ORM\Column(type: 'datetime', nullable: false)]
private ?\DateTimeInterface $modifiedAt;
#[ORM\ManyToMany(targetEntity: User::class, mappedBy: 'rls')]
private Collection $users;
public function __construct()
{
$this->createdAt = new \DateTime();
$this->users = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(string $code): self
{
$this->code = $code;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getLibelle(): ?string
{
return $this->libelle;
}
public function setLibelle(?string $libelle): self
{
$this->libelle = $libelle;
return $this;
}
public function getType(): ?int
{
return $this->type;
}
public function setType(?int $type): self
{
$this->type = $type;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getModifiedAt(): ?\DateTimeInterface
{
return $this->modifiedAt;
}
public function setModifiedAt(?\DateTimeInterface $modifiedAt): self
{
$this->modifiedAt = $modifiedAt;
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->addRole($this);
}
return $this;
}
public function removeUser(User $user): self
{
if ($this->users->removeElement($user)) {
$user->removeRole($this);
}
return $this;
}
/**
* @ORM\PreUpdate
*/
public function onUpdate() {
$this->modifiedAt = new \DateTime();
}
public function __toString()
{
return $this->getLibelle();
}
}