src/Entity/Roles.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\RolesRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. #[ORM\Entity(repositoryClass: RolesRepository::class)]
  8. class Roles
  9. {
  10.     #[ORM\Id]
  11.     #[ORM\GeneratedValue]
  12.     #[ORM\Column]
  13.     private ?int $id = null;
  14.     #[ORM\Column(length: 255)]
  15.     private ?string $name = null;
  16.     #[ORM\Column]
  17.     private ?bool $is_admin = false;
  18.     #[ORM\ManyToMany(targetEntity: Users::class, mappedBy: 'roles')]
  19.     private Collection $users;
  20.     #[ORM\ManyToMany(targetEntity: Tipologias::class, inversedBy: 'users')]
  21.     private Collection $tipologia;
  22.     public function __construct()
  23.     {
  24.         $this->administrators = new ArrayCollection();
  25.         $this->users = new ArrayCollection();
  26.         $this->tipologia = new ArrayCollection();
  27.     }
  28.     public function __toString()
  29.     {
  30.         return $this->getName(); // Reemplaza "getName()" con el método que devuelve el nombre en tu entidad Roles
  31.     }
  32.      /**
  33.      * @return Collection<int, Roles>
  34.      */
  35.     public function getTipologia(): Collection
  36.     {
  37.         return $this->tipologia;
  38.     }
  39.     public function addTipologia(Tipologias $tipologias): self
  40.     {
  41.         if (!$this->tipologia->contains($tipologias)) {
  42.             $this->tipologia->add($tipologias);
  43.         }
  44.         return $this;
  45.     }
  46.     public function removeTipologia(Tipologias $tipologias): self
  47.     {
  48.         $this->tipologia->removeElement($tipologias);
  49.         return $this;
  50.     }
  51.     /**
  52.      * @return Collection|User[]
  53.      */
  54.     public function getUsers(): Collection
  55.     {
  56.         return $this->users;
  57.     }
  58.     public function getId(): ?int
  59.     {
  60.         return $this->id;
  61.     }
  62.     public function getName(): ?string
  63.     {
  64.         return $this->name;
  65.     }
  66.     public function setName(string $name): self
  67.     {
  68.         $this->name = $name;
  69.         return $this;
  70.     }
  71.     public function getIsAdmin(): ?bool
  72.     {
  73.         return $this->is_admin;
  74.     }
  75.     public function setIsAdmin(bool $is_admin): self
  76.     {
  77.         $this->is_admin = $is_admin;
  78.         return $this;
  79.     }
  80.     public function addUser(Users $user): self
  81.     {
  82.         if (!$this->users->contains($user)) {
  83.             $this->users->add($user);
  84.             $user->addRole($this);
  85.         }
  86.         return $this;
  87.     }
  88.     public function removeUser(Users $user): self
  89.     {
  90.         if ($this->users->removeElement($user)) {
  91.             $user->removeRole($this);
  92.         }
  93.         return $this;
  94.     }
  95. }