<?php
namespace App\Entity;
use App\Repository\UserRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Doctrine\Common\Collections\ArrayCollection;
#[ORM\Entity(repositoryClass: UserRepository::class)]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 180, unique: true)]
private ?string $email = null;
#[ORM\Column]
private array $roles = [];
/**
* @var string The hashed password
*/
#[ORM\Column]
private ?string $password = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $nombres = null;
/*
#[ORM\Column(length: 255, nullable: true)]
private ?string $region = null;
*/
#[ORM\ManyToOne(targetEntity:"App\Entity\Region")]
private $region;
#[ORM\Column(type: 'boolean', nullable:true)]
private $activo = null;
#[ORM\Column(type: 'boolean', nullable:true)]
private $super_admin = null;
#[ORM\ManyToMany(targetEntity: "App\Entity\Region", inversedBy: 'usuarios')]
private $regiones;
public function __construct()
{
$this->regiones = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string) $this->email;
}
/**
* @see UserInterface
*/
public function getRoles(): array
{
$roles = $this->roles;
if(is_array($roles) && isset($roles['roles']) && is_array($roles['roles'])){
$roles['roles'][] = 'ROLE_USER';
if($this->super_admin){
$roles['roles'][] = 'ROLE_SUPER_ADMIN';
}
return array_values($roles['roles']);
}
if($this->super_admin){
return ['ROLE_USER', 'ROLE_SUPER_ADMIN'];
}
return ['ROLE_USER'];
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
public function getRoleLabel(){
//["role"]
$label="";
$roles = $this->getRoles();
if ($roles["role"]=="ROLE_ADMIN"){
$label="Administrador";
}elseif($roles["role"]=="ROLE_ADMISOR"){
$label="Admisor";
}elseif($roles["role"]=="ROLE_EVALUADOR_IND"){
$label="Evaluador Individual";
}elseif($roles["role"]=="ROLE_EVALUADOR_COL"){
$label="Evaluador Colectivo";
}else{
$label="-";
}
return $label;
}
public function getRolesLabel() : array
{
$roleDictionary = [
'ROLE_EVALUADOR_ADM' => 'Evaluador - Admisibilidad',
'ROLE_EVALUADOR_IND' => 'Evaluador - Individual',
'ROLE_EVALUADOR_COL' => 'Evaluador - Colectivo',
'ROLE_SUPERVISOR_POS' => 'Supervisor - Postulaciones',
'ROLE_ADMINISTRADOR_USU' => 'Administrador - Usuarios',
'ROLE_ADMINISTRADOR_CON' => 'Administrador - Convocatorias',
'ROLE_ADMINISTRADOR_POS' => 'Administrador - Postulaciones',
// ROLES PUNTO DE CULTURA
'ROLE_PU_EVALUADOR_ADM' => 'Punto Cultura - Evaluador - Admisibilidad',
'ROLE_PU_EVALUADOR_COL' => 'Punto Cultura - Evaluador - Colectivo',
'ROLE_PU_EVALUADOR_SEL' => 'Punto Cultura - Evaluador - Selección',
'ROLE_PU_SUPERVISOR_POS' => 'Punto Cultura - Supervisor - Postulaciones',
'ROLE_PU_ADMINISTRADOR_CON' => 'Punto Cultura - Administrador - Convocatorias',
];
$rolesArray = $this->roles;
$rolesla = [];
foreach($rolesArray as $keyrol => $rol){
if($keyrol != 'roles') continue;
foreach($rol as $r){
$rolesla[] = $roleDictionary[$r];
}
}
return $rolesla;
}
public function getRolesValue() : array
{
$rolesArray = $this->roles;
$rolesla = [];
foreach($rolesArray as $keyrol => $rol){
if($keyrol != 'roles') continue;
$rolesla = $rol;
}
return $rolesla;
}
public function setRolesValue(array $rolVal) : self
{
$this->roles = array("roles"=>$rolVal);
return $this;
}
public function getRoleValue(){
$roles = $this->getRoles();
if (isset($roles["role"])){
return $roles["role"];
}else{
return "";
}
/*
if ($roles["role"]=="ROLE_ADMIN"){
$label="Administrador";
}elseif($roles["role"]=="ROLE_ADMISOR"){
$label="Admisor";
}elseif($roles["role"]=="ROLE_EVALUADOR_IND"){
$label="Evaluador Individual";
}elseif($roles["role"]=="ROLE_EVALUADOR_COL"){
$label="Evaluador Colectivo";
}else{
$label="-";
}
return $label;
*/
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function getNombres(): ?string
{
return $this->nombres;
}
public function setNombres(?string $nombres): self
{
$this->nombres = $nombres;
return $this;
}
/*
public function getRegion(): ?string
{
return $this->region;
}
public function setRegion(?string $region): self
{
$this->region = $region;
return $this;
}
*/
public function getRegion(): ?Region
{
return $this->region;
}
public function setRegion(?Region $region): self
{
$this->region = $region;
return $this;
}
public function isActivo(): ?bool
{
return $this->activo;
}
public function setActivo(?bool $activo): self
{
$this->activo = $activo;
return $this;
}
public function isSuperAdmin(): ?bool
{
return $this->super_admin;
}
public function setSuperAdmin(?bool $super_admin): self
{
$this->super_admin = $super_admin;
return $this;
}
// public function getRegiones(): array
// {
// $regiones = $this->regiones;
// return array_unique($regiones);
// }
// public function setRegiones(array $regiones): self
// {
// if(is_array($regiones)) $this->regiones = $regiones;
// return $this;
// }
public function getRegionesLabel(){
$label="";
$regiones = $this->getRegiones();
foreach($regiones as $keyRegion => $region){
$enlace = $keyRegion == 0 ? '' : ', ';
$label = $label . $enlace . $region->getNombre();
}
return $label;
}
public function getRegiones()
{
return $this->regiones;
}
public function addRegion(Region $region): self
{
if (!$this->regiones->contains($region)) {
$this->regiones->add($region);
}
return $this;
}
public function removeRegion(Region $region): self
{
$this->regiones->removeElement($region);
return $this;
}
}