src/Entity/User.php line 52
<?phpnamespace App\Entity;use Doctrine\Common\Collections\Collection;use Doctrine\DBAL\Types\Types;use Symfony\Component\Validator\Constraints as Assert;use App\Entity\TransaccionAfiliado;use App\Entity\Transaccion;use Symfony\Component\Validator\ExecutionContextInterface;use FOS\UserBundle\Model\User as BaseUser;use FOS\UserBundle\Model\UserInterface;// use Sonata\UserBundle\Model\UserInterface;// use Sonata\UserBundle\Entity\BaseUser;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\ORM\Mapping as ORM;use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;use Symfony\Component\Validator\Constraints\NotBlank;use App\Entity\Oficina;use JMS\Serializer\Annotation as JMS;use Knp\DoctrineBehaviors\Contract\Entity\TimestampableInterface;use Knp\DoctrineBehaviors\Model\Timestampable\TimestampableTrait;/*** @ORM\Entity(repositoryClass="App\Repository\UserRepository")* @ORM\Table(name="usuarios")* @UniqueEntity(fields="username")* @ORM\HasLifecycleCallbacks* @ORM\AttributeOverrides({* @ORM\AttributeOverride(name="email",* column=@ORM\Column(* name = "email",* length = 255,* nullable=true,* unique=false* )* )* })* @ORM\AttributeOverrides({* @ORM\AttributeOverride(name="emailCanonical",* column=@ORM\Column(* name="email_canonical",* length=255,* nullable=true,* unique=false* )* )* })*/class User extends BaseUser implements UserInterface /*implements TimestampableInterface{use TimestampableTrait;*/{const SALUTE_SR = 1;const SALUTE_SRA = 2;const SALUTE_SRTA = 3;const R_USER = "ROLE_USER";const R_ADMIN = "ROLE_ADMIN";const R_MANAGER = "ROLE_MANAGER";const R_SUPER_ADMIN = "ROLE_SUPER_ADMIN";const R_AFILIADO = "ROLE_AFILIADO";const R_NOAFILIADO = "ROLE_NOAFILIADO";/*** @ORM\Id* @ORM\Column(type="integer")* @ORM\GeneratedValue(strategy="AUTO")* @JMS\Groups({"api-stats"})*/protected $id;/*** @ORM\Column(type="string")* @JMS\Groups({"api-stats"})*/protected $idCard;/*** @ORM\Column(type="string", nullable=true)* @JMS\Groups({"api-stats"})*/protected $erpId;/*** @ORM\Column(type="string", nullable=true)*/protected $fidCard;/*** @ORM\Column(type="smallint")*/protected $salute = self::SALUTE_SR;/*** @ORM\Column(type="string")* @NotBlank(message="Por favor, ingrese un nombre")*/protected $name = "";/*** @ORM\Column(type="string", nullable=true)*/protected $fullName = "";protected $telefono = "";/*** @ORM\Column(type="date", nullable=true)*/protected $birthDate;/*** @ORM\ManyToOne(targetEntity="Oficina")* @ORM\JoinColumn(name="oficina", referencedColumnName="id", nullable=true)*/protected $oficinaGestion;/**** @ORM\Column(type="boolean")*/protected $newsletter = true;/*** @ORM\Column(type="string", nullable=true)*/protected $mobile;/*** Contraseña plana*/// protected ?string $plainPassword = "";/*** @ORM\Column(type="string", nullable=true)*/protected $role;/*** @ORM\Column(type="datetime")*/protected $registerDate;/**** @ORM\Column(type="boolean")*/protected $estado = true;/**** @ORM\Column(type="string", nullable=true)** @Assert\File(maxSize = "10M", mimeTypes={ "image/jpeg", "image/jpg", "image/png", "image/gif", "image/bmp", "image/x-windows-bmp"}, groups = {"create"} )*/protected $urlImagen;protected $urlImagenCheckbox;/****@ORM\Column(type="string" , nullable=true)** @Assert\File(maxSize = "10M", mimeTypes={ "image/jpeg", "image/jpg", "image/png", "image/gif", "image/bmp", "image/x-windows-bmp"}, groups = {"create"})*/protected $urlImagen2;/*** @ORM\Column(type="string", nullable=true)*/protected $nombreVisible;/*** @Assert\GreaterThan("today")*/protected $fechaCaducidad;protected $fechaNacimiento;/*** @var ArrayCollection** @ORM\OneToMany(targetEntity="Transaccion", mappedBy="usuario")*/protected $transacciones;/*** @var ArrayCollection** @ORM\OneToMany(targetEntity="TransaccionAfiliado", mappedBy="afiliado")* @ORM\OrderBy({"fechaEntrega" = "DESC"})*/protected $transaccionesDelAfiliado;/*** @var ArrayCollection** @ORM\OneToMany(targetEntity="Reserva", mappedBy="usuario")*/protected $reservas;/*** @var ArrayCollection** @ORM\OneToMany(targetEntity="Alerta", mappedBy="usuario", orphanRemoval=true)*/protected $alerts;/*** @ORM\Column(type="string", nullable=true)*/private $idiomaPreferido;/*** @ORM\Column(type="string", nullable=true)*/protected $aliceId;protected $tipoDocumento;protected $pais;/*** @ORM\Column(type="string", nullable=true)*/protected $direccion1;/*** @ORM\Column(type="string", nullable=true)*/protected $ciudad;/*** @ORM\Column(type="string", nullable=true)*/protected $county;/*** @ORM\Column(type="string", nullable=true)*/protected $cp;/*** @var ArrayCollection** @ORM\OneToMany(targetEntity="UserStats", mappedBy="user", orphanRemoval=true, cascade={"remove"})* @ORM\OrderBy({"id" = "DESC"})*/protected $userStats;/*** @var ArrayCollection** @ORM\OneToMany(targetEntity="HistorialDevolucion", mappedBy="usuario")*/protected $historialDevoluciones;public function __construct(){// parent::__construct();$this->registerDate = new \DateTime("now");$this->lineas = new ArrayCollection();$this->transacciones = new ArrayCollection();$this->transaccionesDelAfiliado = new ArrayCollection();$this->reservas = new ArrayCollection();$this->alerts = new ArrayCollection();$this->userStats = new ArrayCollection();$this->roles = [];$this->enabled = true;$this->historialDevoluciones = new ArrayCollection();}public function isEnabled(): bool{//return(count($this->transacciones)>0);return $this->enabled;}/*** Set erpId** @param string $erpId* @return User*/public function setErpId($erpId){$this->erpId = $erpId;return $this;}/*** Get erpId** @return string*/public function getErpId(){return $this->erpId;}public function getUrlImagenCheckbox(){return $this->urlImagenCheckbox;}public function setUrlImagenCheckbox($urlImagenCheckbox){$this->urlImagenCheckbox = $urlImagenCheckbox;return $this;}/*** Set pais** @param string $pais* @return User*/public function setPais($pais){$this->pais = $pais;return $this;}/*** Get pais** @return string*/public function getPais(){return $this->pais;}/*** Get id** @return integer*/public function getId(){return $this->id;}/*** Set salute** @param integer $salute* @return User*/public function setSalute($salute){$this->salute = $salute;return $this;}/*** Get salute** @return integer*/public function getSalute(){return $this->salute;}/*** Set name** @param string $name* @return User*/public function setName($name){$this->name = $name;return $this;}/*** Get name** @return string*/public function getName(){return $this->name;}/*** Set fullName** @param string $fullName* @return User*/public function setFullName($fullName){$this->fullName = $fullName;return $this;}/*** Get fullName** @return string*/public function getFullName(){return $this->fullName;}/*** Set fidCard** @param string $fidCard* @return User*/public function setFidCard($fidCard){$this->fidCard = $fidCard;return $this;}/*** Get fidCard** @return string*/public function getFidCard(){return $this->fidCard;}/*** Set idCard** @param string $idCard* @return User*/public function setIdCard($idCard){$this->idCard = $idCard;if (!$this->id)$this->setUsername($idCard);return $this;}/*** Get idCard** @return string*/public function getIdCard(){return $this->idCard;}/*** Set idCard** @param string $idCard* @return User*/public function setTelefono($telefono){$this->telefono = $telefono;}/*** Get idCard** @return string*/public function getTelefono(){return $this->telefono;}/*** Set birthDate** @param string $birthDate* @return User*/public function setBirthDate($birthDate){$this->birthDate = $birthDate;return $this;}/*** Get birthDate** @return string*/public function getBirthDate(){return $this->birthDate;}/*** Set urlImagen** @param string $urlImagen* @return User*/public function setUrlImagen($urlImagen){$this->urlImagen = $urlImagen;return $this;}/*** Get urlImagen** @return string*/public function getUrlImagen(){return $this->urlImagen;}/*** Set urlImagen2** @param string $urlImagen2* @return User*/public function setUrlImagen2($urlImagen2){$this->urlImagen2 = $urlImagen2;return $this;}/*** Get urlImagen2** @return string*/public function getUrlImagen2(){return $this->urlImagen2;}/*public function addUrlImage($urlImagen){$this->urlImagenes[0] = $urlImagen->first();$this->urlImagenes[1] = $urlImagen->last();return $this;}*//*** Set nombreVisible** @param string $nombreVisible* @return User*/public function setNombreVisible($nombreVisible){$this->nombreVisible = $nombreVisible;return $this;}/*** Get nombreVisible** @return string*/public function getNombreVisible(){return $this->nombreVisible;}/*** Set register Date** @param $date Date* @return User*/public function setRegisterDate($date){$this->registerDate = $date;return $this;}/*** Get registerDate** @return date*/public function getRegisterDate(){return $this->registerDate;}/*** Set estado** @param string $estado* @return User*/public function setEstado($estado){$this->estado = $estado;return $this;}/*** Get estado** @return boolean*/public function getEstado(){return $this->estado;}/*** Set newsletter** @param string $newsletter* @return User*/public function setNewsletter($newsletter){$this->newsletter = $newsletter;return $this;}/*** Get newsletter** @return boolean*/public function getNewsletter(){return $this->newsletter;}/*** Set fechaCaducidad** @param date $fechaCaducidad* @return User*/public function setFechaCaducidad($fechaCaducidad){$this->fechaCaducidad = $fechaCaducidad;return $this;}/*** Get fechaCaducidad** @return date*/public function getFechaCaducidad(){return $this->fechaCaducidad;}/*** @Assert\IsTrue(message = "user.fullAge")*/public function isFechaNacimientoLegal(){if($this->fechaNacimiento){$date= $this->fechaNacimiento->format('Y-m-d');if (time() < strtotime('+18 years', strtotime($date))) {return false;}}return true;}/*** @Assert\IsTrue(message = "user.expiredDocument")*/public function isFechaCaducidadLegal(){if($this->fechaCaducidad){$date= $this->fechaCaducidad->format('Y-m-d');if ( time() > strtotime('+1 day', strtotime($date))) {return false;}}return true;}/*** Set fechaNacimiento** @param date $fechaNacimiento* @return User*/public function setFechaNacimiento($fechaNacimiento){$this->fechaNacimiento = $fechaNacimiento;return $this;}/*** Get fechaCaducidad** @return date*/public function getFechaNacimiento(){return $this->fechaNacimiento;}/*** Set mobile** @param string $mobile* @return User*/public function setMobile($mobile){$this->mobile = $mobile;return $this;}/*** Get mobile** @return string*/public function getMobile(){return $this->mobile;}// /**// * @return mixed// */// public function getPlainPassword(): string// {// return $this->plainPassword;// }//// /**// * @param string $plainPassword// */// public function setPlainPassword($plainPassword): void// {// $this->plainPassword = $plainPassword;// }public function setRole($role){$this->role = $role;}public function getRole(){return $this->role;}/*** Set oficina** @param Oficina $oficina* @return Oficina*/public function setOficinaGestion($oficina){$this->oficinaGestion = $oficina;}/*** @return mixed*/public function getOficinaGestion(){return $this->oficinaGestion;}public function __toString(){if ($this->fullName)return $this->fullName;elsereturn $this->name." (".$this->email.")";}public static function getPossibleRoles(){return array(self::R_USER => "Usuario",self::R_ADMIN => "Administrador",self::R_MANAGER => "Gestor",self::R_SUPER_ADMIN => "Super Administrador",self::R_AFILIADO => "Afiliado",);}/*** Returns an array of the user roles that an admin can create a user with*/public static function getAdminRoles(){return array(self::R_MANAGER => "Gestor",self::R_ADMIN => "Administrador",);}/*** Returns an array of the user roles that an admin can create a user with*/public static function getAfiliadoRol(){return array(self::R_AFILIADO => "Afiliado",self::R_NOAFILIADO => "No afiliado",);}public function checkUserActive(ExecutionContextInterface $context){if(!$this->isEnabled()){$context->addViolationAt('email','Su cuenta está desactivada. Póngase en contacto con el administrador de la web.',array(),null);}}public function getTipoDocumento(){return $this->tipoDocumento;}public function setTipoDocumento($tipoDocumento){$this->tipoDocumento=$tipoDocumento;}public function setTransacciones($transacciones){$this->transacciones = $transacciones;return $this;}public function getTransacciones(){return $this->transacciones;}public function setTransaccionesAfiliadas($transaccionesDelAfiliado){$this->transaccionesAfiliadas = $transaccionesDelAfiliado;return $this;}public function getTransaccionesAfiliadas(){return $this->transaccionesAfiliadas;}public function setTransaccionesDelAfiliado($transaccionesDelAfiliado){$this->transaccionesDelAfiliado = $transaccionesDelAfiliado;return $this;}public function getTransaccionesDelAfiliado(){return $this->transaccionesDelAfiliado;}public function setReservas($reservas){$this->reservas = $reservas;return $this;}public function getReservas(){return $this->reservas;}public function setIdiomaPreferido($idiomaPreferido){$this->idiomaPreferido = $idiomaPreferido;return $this;}public function getIdiomaPreferido(){return $this->idiomaPreferido;}/*** @return ArrayCollection*/public function getAlerts(){return $this->alerts;}/*** @param ArrayCollection $alerts* @return ArrayCollection*/public function setAlerts(ArrayCollection $alerts){return $this->alerts=$alerts;}/*** @param Alerta $alerta* @return $this*/public function addAlerta(Alerta $alerta){$this->alerts[]=$alerta;$alerta->setUsuario($this);return $this;}/*** @param Alerta $alerta* @return $this*/public function removeAlerta(Alerta $alerta){$this->alerts->removeElement($alerta);return $this;}/*** @ORM\PrePersist*/public function setCreateRole(): void{if ( $this->role == 'ROLE_MANAGER' ) {$this->addRole('ROLE_MANAGER');$this->idCard = $this->username;} elseif ( $this->role == 'ROLE_ADMIN' ) {$this->addRole('ROLE_ADMIN');$this->idCard = $this->username;} elseif ( $this->role == 'ROLE_AFILIADO' ) {$this->addRole('ROLE_AFILIADO');} elseif ( $this->role == 'ROLE_NOAFILIADO' ) {}}/*** @ORM\PreUpdate*/public function setEditRole(): void{if ( $this->role == 'ROLE_MANAGER' ) {$this->removeRole('ROLE_ADMIN');$this->addRole('ROLE_MANAGER');} elseif ( $this->role == 'ROLE_ADMIN' ) {$this->removeRole('ROLE_MANAGER');$this->addRole('ROLE_ADMIN');} elseif ( $this->role == 'ROLE_AFILIADO' ) {$this->addRole('ROLE_AFILIADO');} elseif ( $this->role == 'ROLE_NOAFILIADO' ) {$this->removeRole('ROLE_AFILIADO');}}/*** Set aliceId** @return string*/public function setAliceId($aliceId){$this->aliceId = $aliceId;return $this;}/*** Get aliceId** @return string*/public function getAliceId(){return $this->aliceId;}public function isNewsletter(): ?bool{return $this->newsletter;}public function isEstado(): ?bool{return $this->estado;}public function addTransaccione(Transaccion $transaccione): self{if (!$this->transacciones->contains($transaccione)) {$this->transacciones->add($transaccione);$transaccione->setUsuario($this);}return $this;}public function removeTransaccione(Transaccion $transaccione): self{if ($this->transacciones->removeElement($transaccione)) {// set the owning side to null (unless already changed)if ($transaccione->getUsuario() === $this) {$transaccione->setUsuario(null);}}return $this;}public function addTransaccionesDelAfiliado(TransaccionAfiliado $transaccionesDelAfiliado): self{if (!$this->transaccionesDelAfiliado->contains($transaccionesDelAfiliado)) {$this->transaccionesDelAfiliado->add($transaccionesDelAfiliado);$transaccionesDelAfiliado->setAfiliado($this);}return $this;}public function removeTransaccionesDelAfiliado(TransaccionAfiliado $transaccionesDelAfiliado): self{if ($this->transaccionesDelAfiliado->removeElement($transaccionesDelAfiliado)) {// set the owning side to null (unless already changed)if ($transaccionesDelAfiliado->getAfiliado() === $this) {$transaccionesDelAfiliado->setAfiliado(null);}}return $this;}public function addReserva(Reserva $reserva): self{if (!$this->reservas->contains($reserva)) {$this->reservas->add($reserva);$reserva->setUsuario($this);}return $this;}public function removeReserva(Reserva $reserva): self{if ($this->reservas->removeElement($reserva)) {// set the owning side to null (unless already changed)if ($reserva->getUsuario() === $this) {$reserva->setUsuario(null);}}return $this;}public function addAlert(Alerta $alert): self{if (!$this->alerts->contains($alert)) {$this->alerts->add($alert);$alert->setUsuario($this);}return $this;}public function removeAlert(Alerta $alert): self{if ($this->alerts->removeElement($alert)) {// set the owning side to null (unless already changed)if ($alert->getUsuario() === $this) {$alert->setUsuario(null);}}return $this;}public function getDireccion1(): ?string{return $this->direccion1;}public function setDireccion1(?string $direccion1): self{$this->direccion1 = $direccion1;return $this;}public function getCiudad(): ?string{return $this->ciudad;}public function setCiudad(?string $ciudad): self{$this->ciudad = $ciudad;return $this;}public function getCounty(): ?string{return $this->county;}public function setCounty(?string $county): self{$this->county = $county;return $this;}public function getCp(): ?string{return $this->cp;}public function setCp(?string $cp): self{$this->cp = $cp;return $this;}public function getHistorialDevoluciones(){return $this->historialDevoluciones;}public function addHistorialDevolucion($historialDevolucion){if (!$this->historialDevoluciones->contains($historialDevolucion)) {$this->historialDevoluciones->add($historialDevolucion);$historialDevolucion->setUsuario($this);}return $this;}public function removeHistorialDevolucion($historialDevolucion){if ($this->historialDevoluciones->removeElement($historialDevolucion)) {// set the owning side to null (unless already changed)if ($historialDevolucion->getUsuario() === $this) {$historialDevolucion->setUsuario(null);}}return $this;}}