src/Entity/Perfil.php line 13

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\PerfilRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use App\Entity\User;
  9. #[ORM\Entity(repositoryClassPerfilRepository::class)]
  10. class Perfil
  11. {
  12.     #[ORM\Id]
  13.     #[ORM\GeneratedValue]
  14.     #[ORM\Column]
  15.     private ?int $id null;
  16.     #[ORM\Column(length255)]
  17.     private ?string $nome null;
  18.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  19.     private ?string $descricao null;
  20.     #[ORM\Column]
  21.     private ?bool $ativo null;
  22.     
  23.     
  24.     #[ORM\OneToMany(targetEntityUser::class, mappedBy'Perfil'orphanRemovaltrue)]
  25.     private Collection $Usuarios;
  26.     #[ORM\ManyToMany(targetEntityPermissao::class, mappedBy'Perfil')]
  27.     private Collection $Permissoes;
  28.     public function __construct()
  29.     {
  30.         $this->Permissoes = new ArrayCollection();
  31.         $this->Usuarios = new ArrayCollection();
  32.     }
  33.     public function getId(): ?int
  34.     {
  35.         return $this->id;
  36.     }
  37.     
  38.     public function getNome(): ?string
  39.     {
  40.         return $this->nome;
  41.     }
  42.     public function setNome(string $nome): self
  43.     {
  44.         $this->nome $nome;
  45.         return $this;
  46.     }
  47.     public function getDescricao(): ?string
  48.     {
  49.         return $this->descricao;
  50.     }
  51.     public function setDescricao(?string $descricao): self
  52.     {
  53.         $this->descricao $descricao;
  54.         return $this;
  55.     }
  56.     public function isAtivo(): ?bool
  57.     {
  58.         return $this->ativo;
  59.     }
  60.     public function setAtivo(bool $ativo): self
  61.     {
  62.         $this->ativo $ativo;
  63.         return $this;
  64.     }
  65.     
  66.     public function ativodesc()
  67.     {
  68.         return $this->isAtivo() ? "Ativo" "Inativo";
  69.     }
  70.     /**
  71.      * @return Collection<int, Permissao>
  72.      */
  73.     public function getPermissoes(): Collection
  74.     {
  75.         return $this->Permissoes;
  76.     }
  77.     public function addPermissoes(Permissao $permissoes): self
  78.     {
  79.         if (!$this->Permissoes->contains($permissoes)) {
  80.             $this->Permissoes->add($permissoes);
  81.             $permissoes->addPerfil($this);
  82.         }
  83.         return $this;
  84.     }
  85.     public function removePermissoes(Permissao $permissoes): self
  86.     {
  87.         if ($this->Permissoes->removeElement($permissoes)) {
  88.             $permissoes->removePerfil($this);
  89.         }
  90.         return $this;
  91.     }
  92.     
  93.     public function clearPermissoes(\Doctrine\ORM\EntityManager $em): self
  94.     {
  95.         $vetPermissoes $this->getPermissoes();
  96.         foreach($vetPermissoes as $permissao){
  97.             $this->removePermissoes($permissao);
  98.         }
  99.         $em->persist($this);
  100.         $em->flush();
  101.         return $this;
  102.     }
  103.     
  104.     /**
  105.      * @return Collection<int, Usuario>
  106.      */
  107.     public function getUsuarios(): Collection
  108.     {
  109.         return $this->Usuarios;
  110.     }
  111.     public function addUsuario(User $user): self
  112.     {
  113.         if (!$this->Usuarios->contains($user)) {
  114.             $this->Usuarios->add($user);
  115.             $user->setUsuario($this);
  116.         }
  117.         return $this;
  118.     }
  119.     public function removeUsuario(User $usuario): self
  120.     {
  121.         if ($this->Usuarios->removeElement($usuario)) {
  122.             // set the owning side to null (unless already changed)
  123.             if ($usuario->getP() === $this) {
  124.                 $usuario->setUsuario(null);
  125.             }
  126.         }
  127.         return $this;
  128.     }
  129. }