src/Entity/Role.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\RoleRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ORM\Entity(repositoryClassRoleRepository::class)]
  8. #[ORM\Table(name'tb_roles')]
  9. #[ORM\HasLifecycleCallbacks]
  10. class Role
  11. {
  12.     #[ORM\Id]
  13.     #[ORM\GeneratedValue]
  14.     #[ORM\Column(type"integer"uniquetrue)]
  15.     private ?int $id;
  16.     #[ORM\Column(type'string'length50nullablefalse)]
  17.     private ?string $code;
  18.     #[ORM\Column(type'string'length50nullablefalse)]
  19.     private ?string $name;
  20.     #[ORM\Column(type'string'length100nullablefalse)]
  21.     private ?string $libelle;
  22.     #[ORM\Column(type'integer'nullablefalse)]
  23.     private ?int $type;
  24.     #[ORM\Column(type'datetime'nullablefalse)]
  25.     private \DateTimeInterface $createdAt;
  26.     #[ORM\Column(type'datetime'nullablefalse)]
  27.     private ?\DateTimeInterface $modifiedAt;
  28.     #[ORM\ManyToMany(targetEntityUser::class, mappedBy'rls')]
  29.     private Collection $users;
  30.     public function __construct()
  31.     {
  32.         $this->createdAt = new \DateTime();
  33.         $this->users = new ArrayCollection();
  34.     }
  35.     public function getId(): ?int
  36.     {
  37.         return $this->id;
  38.     }
  39.     public function getCode(): ?string
  40.     {
  41.         return $this->code;
  42.     }
  43.     public function setCode(string $code): self
  44.     {
  45.         $this->code $code;
  46.         return $this;
  47.     }
  48.     public function getName(): ?string
  49.     {
  50.         return $this->name;
  51.     }
  52.     public function setName(string $name): self
  53.     {
  54.         $this->name $name;
  55.         return $this;
  56.     }
  57.     public function getLibelle(): ?string
  58.     {
  59.         return $this->libelle;
  60.     }
  61.     public function setLibelle(?string $libelle): self
  62.     {
  63.         $this->libelle $libelle;
  64.         return $this;
  65.     }
  66.     public function getType(): ?int
  67.     {
  68.         return $this->type;
  69.     }
  70.     public function setType(?int $type): self
  71.     {
  72.         $this->type $type;
  73.         return $this;
  74.     }
  75.     public function getCreatedAt(): ?\DateTimeInterface
  76.     {
  77.         return $this->createdAt;
  78.     }
  79.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  80.     {
  81.         $this->createdAt $createdAt;
  82.         return $this;
  83.     }
  84.     public function getModifiedAt(): ?\DateTimeInterface
  85.     {
  86.         return $this->modifiedAt;
  87.     }
  88.     public function setModifiedAt(?\DateTimeInterface $modifiedAt): self
  89.     {
  90.         $this->modifiedAt $modifiedAt;
  91.         return $this;
  92.     }
  93.     /**
  94.      * @return Collection|User[]
  95.      */
  96.     public function getUsers(): Collection
  97.     {
  98.         return $this->users;
  99.     }
  100.     public function addUser(User $user): self
  101.     {
  102.         if (!$this->users->contains($user)) {
  103.             $this->users[] = $user;
  104.             $user->addRole($this);
  105.         }
  106.         return $this;
  107.     }
  108.     public function removeUser(User $user): self
  109.     {
  110.         if ($this->users->removeElement($user)) {
  111.             $user->removeRole($this);
  112.         }
  113.         return $this;
  114.     }
  115.     /**
  116.      * @ORM\PreUpdate
  117.      */
  118.     public function onUpdate() {
  119.         $this->modifiedAt = new \DateTime();
  120.     }
  121.     public function __toString()
  122.     {
  123.         return $this->getLibelle();
  124.     }
  125. }