src/Entity/User.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  6. use Symfony\Component\Security\Core\User\UserInterface;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. #[ORM\Entity(repositoryClassUserRepository::class)]
  9. class User implements UserInterfacePasswordAuthenticatedUserInterface
  10. {
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column]
  14.     private ?int $id null;
  15.     #[ORM\Column(length180uniquetrue)]
  16.     private ?string $email null;
  17.     #[ORM\Column]
  18.     private array $roles = [];
  19.     /**
  20.      * @var string The hashed password
  21.      */
  22.     #[ORM\Column]
  23.     private ?string $password null;
  24.     #[ORM\Column(length255nullabletrue)]
  25.     private ?string $nombres null;
  26.     /*
  27.     #[ORM\Column(length: 255, nullable: true)]
  28.     private ?string $region = null;
  29.     */
  30.     #[ORM\ManyToOne(targetEntity:"App\Entity\Region")]
  31.     private $region;
  32.     #[ORM\Column(type'boolean'nullable:true)]
  33.     private $activo null;
  34.     #[ORM\Column(type'boolean'nullable:true)]
  35.     private $super_admin null;
  36.     #[ORM\ManyToMany(targetEntity"App\Entity\Region"inversedBy'usuarios')]
  37.     private $regiones;
  38.     public function __construct()
  39.     {
  40.         $this->regiones = new ArrayCollection();
  41.     }
  42.     public function getId(): ?int
  43.     {
  44.         return $this->id;
  45.     }
  46.     public function getEmail(): ?string
  47.     {
  48.         return $this->email;
  49.     }
  50.     public function setEmail(string $email): self
  51.     {
  52.         $this->email $email;
  53.         return $this;
  54.     }
  55.     /**
  56.      * A visual identifier that represents this user.
  57.      *
  58.      * @see UserInterface
  59.      */
  60.     public function getUserIdentifier(): string
  61.     {
  62.         return (string) $this->email;
  63.     }
  64.     /**
  65.      * @see UserInterface
  66.      */
  67.     public function getRoles(): array
  68.     {
  69.         $roles $this->roles;
  70.         if(is_array($roles) && isset($roles['roles']) && is_array($roles['roles'])){
  71.             $roles['roles'][] =  'ROLE_USER';
  72.             if($this->super_admin){
  73.                 $roles['roles'][] =  'ROLE_SUPER_ADMIN';
  74.             }
  75.             return array_values($roles['roles']);
  76.         }
  77.         if($this->super_admin){
  78.             return ['ROLE_USER''ROLE_SUPER_ADMIN'];
  79.         }
  80.         return ['ROLE_USER'];
  81.     }
  82.     public function setRoles(array $roles): self
  83.     {
  84.         $this->roles $roles;
  85.         return $this;
  86.     }
  87.     public function getRoleLabel(){
  88.         //["role"]
  89.         $label="";
  90.         $roles $this->getRoles();
  91.         if ($roles["role"]=="ROLE_ADMIN"){
  92.             $label="Administrador";
  93.         }elseif($roles["role"]=="ROLE_ADMISOR"){
  94.             $label="Admisor";
  95.         }elseif($roles["role"]=="ROLE_EVALUADOR_IND"){
  96.             $label="Evaluador Individual";
  97.         }elseif($roles["role"]=="ROLE_EVALUADOR_COL"){
  98.             $label="Evaluador Colectivo";
  99.         }else{
  100.             $label="-";
  101.         }
  102.         return $label;
  103.     }
  104.     public function getRolesLabel() : array
  105.     {
  106.         $roleDictionary = [
  107.             'ROLE_EVALUADOR_ADM' => 'Evaluador - Admisibilidad',
  108.             'ROLE_EVALUADOR_IND' => 'Evaluador - Individual',
  109.             'ROLE_EVALUADOR_COL' => 'Evaluador - Colectivo',
  110.             'ROLE_SUPERVISOR_POS' => 'Supervisor - Postulaciones',
  111.             'ROLE_ADMINISTRADOR_USU' => 'Administrador - Usuarios',
  112.             'ROLE_ADMINISTRADOR_CON' => 'Administrador - Convocatorias',
  113.             'ROLE_ADMINISTRADOR_POS' => 'Administrador - Postulaciones',
  114.             // ROLES PUNTO DE CULTURA
  115.             'ROLE_PU_EVALUADOR_ADM' => 'Punto Cultura - Evaluador - Admisibilidad',
  116.             'ROLE_PU_EVALUADOR_COL' => 'Punto Cultura - Evaluador - Colectivo',
  117.             'ROLE_PU_EVALUADOR_SEL' => 'Punto Cultura - Evaluador - Selección',
  118.             'ROLE_PU_SUPERVISOR_POS' => 'Punto Cultura - Supervisor - Postulaciones',
  119.             'ROLE_PU_ADMINISTRADOR_CON' => 'Punto Cultura - Administrador - Convocatorias',
  120.         ];
  121.         $rolesArray $this->roles;
  122.         $rolesla = [];
  123.         foreach($rolesArray as $keyrol => $rol){
  124.             if($keyrol != 'roles') continue;
  125.             foreach($rol as $r){
  126.                 $rolesla[] = $roleDictionary[$r];
  127.             }
  128.         }
  129.         return $rolesla;
  130.     }
  131.     public function getRolesValue() : array
  132.     {
  133.         $rolesArray $this->roles;
  134.         $rolesla = [];
  135.         foreach($rolesArray as $keyrol => $rol){
  136.             if($keyrol != 'roles') continue;
  137.             $rolesla $rol;
  138.         }
  139.         return $rolesla;
  140.     }
  141.     public function setRolesValue(array $rolVal) : self
  142.     {
  143.         $this->roles = array("roles"=>$rolVal);
  144.         return $this;
  145.     }
  146.     public function getRoleValue(){
  147.         $roles $this->getRoles();
  148.         if (isset($roles["role"])){
  149.             return $roles["role"];
  150.         }else{
  151.             return "";
  152.         }
  153.         /*
  154.         if ($roles["role"]=="ROLE_ADMIN"){
  155.             $label="Administrador";
  156.         }elseif($roles["role"]=="ROLE_ADMISOR"){
  157.             $label="Admisor";
  158.         }elseif($roles["role"]=="ROLE_EVALUADOR_IND"){
  159.             $label="Evaluador Individual";
  160.         }elseif($roles["role"]=="ROLE_EVALUADOR_COL"){
  161.             $label="Evaluador Colectivo";
  162.         }else{
  163.             $label="-";
  164.         }
  165.         return $label;
  166.         */
  167.     }
  168.     /**
  169.      * @see PasswordAuthenticatedUserInterface
  170.      */
  171.     public function getPassword(): string
  172.     {
  173.         return $this->password;
  174.     }
  175.     public function setPassword(string $password): self
  176.     {
  177.         $this->password $password;
  178.         return $this;
  179.     }
  180.     /**
  181.      * @see UserInterface
  182.      */
  183.     public function eraseCredentials()
  184.     {
  185.         // If you store any temporary, sensitive data on the user, clear it here
  186.         // $this->plainPassword = null;
  187.     }
  188.     public function getNombres(): ?string
  189.     {
  190.         return $this->nombres;
  191.     }
  192.     public function setNombres(?string $nombres): self
  193.     {
  194.         $this->nombres $nombres;
  195.         return $this;
  196.     }
  197.     /*
  198.     public function getRegion(): ?string
  199.     {
  200.         return $this->region;
  201.     }
  202.     public function setRegion(?string $region): self
  203.     {
  204.         $this->region = $region;
  205.         return $this;
  206.     }
  207.     */
  208.     public function getRegion(): ?Region
  209.     {
  210.         return $this->region;
  211.     }
  212.     public function setRegion(?Region $region): self
  213.     {
  214.         $this->region $region;
  215.         return $this;
  216.     }
  217.     public function isActivo(): ?bool
  218.     {
  219.         return $this->activo;
  220.     }
  221.     public function setActivo(?bool $activo): self
  222.     {
  223.         $this->activo $activo;
  224.         return $this;
  225.     }
  226.     public function isSuperAdmin(): ?bool
  227.     {
  228.         return $this->super_admin;
  229.     }
  230.     public function setSuperAdmin(?bool $super_admin): self
  231.     {
  232.         $this->super_admin $super_admin;
  233.         return $this;
  234.     }
  235.     // public function getRegiones(): array
  236.     // {
  237.     //     $regiones = $this->regiones;
  238.     //     return array_unique($regiones);
  239.     // }
  240.     // public function setRegiones(array $regiones): self
  241.     // {
  242.     //     if(is_array($regiones)) $this->regiones = $regiones;
  243.     //     return $this;
  244.     // }
  245.     public function getRegionesLabel(){
  246.         $label="";
  247.         $regiones $this->getRegiones();
  248.         foreach($regiones as $keyRegion => $region){
  249.             $enlace $keyRegion == '' ', ';
  250.             $label $label $enlace $region->getNombre();
  251.         }
  252.         return $label;
  253.     }
  254.     public function getRegiones()
  255.     {
  256.         return $this->regiones;
  257.     }
  258.     public function addRegion(Region $region): self
  259.     {
  260.         if (!$this->regiones->contains($region)) {
  261.             $this->regiones->add($region);
  262.         }
  263.         return $this;
  264.     }
  265.     public function removeRegion(Region $region): self
  266.     {
  267.         $this->regiones->removeElement($region);
  268.         return $this;
  269.     }
  270. }