<?php
namespace App\Core\Entity;
use App\Core\Entity\Chat\Participante;
use App\Core\Entity\Seguidor;
use App\Core\Entity\Bloqueos;
use App\Core\Entity\Cybersource\CybersourceTransLog;
use App\Core\Entity\Institucion\Director;
use App\Core\Entity\TutorialUsuario;
use App\Entity\Calendario;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\SerializerInterface;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use App\Core\Entity\Country;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
/**
* @ORM\Entity(repositoryClass="App\Core\Repository\UserRepository")
* @Vich\Uploadable()
*/
class User implements UserInterface, SerializerInterface, PasswordAuthenticatedUserInterface
{
const JSON_FIELDS = [
'id', 'imageName', 'primerNombre', 'segundoNombre', 'tercerNombre', 'primerApellido', 'segundoApellido', 'nombreCompleto', 'email', 'username', 'numeroTelefonico', 'fechaNacimiento', 'genero', 'informacionPerfil' => ['id'], 'idioma', 'createdAt', 'emailConfirmado', 'paisCodigoTelefonicoId' => ['id', 'nombre', 'codigoTelefonico']
];
const ARRAY_GROUPS_TO_SERIALIZE = ['user','main','informacionPerfil', 'city', 'idiomaPerfil', 'idioma', 'empleoPerfil', 'empleo', 'colegioPerfil', 'colegio', 'profesionPerfil', 'profesion', 'universidadPerfil', 'universidad'];
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
* @Groups("main")
*/
private $id;
/**
* @ORM\Column(type="string", length=180, unique=true)
* @Groups("main")
*/
private $email;
/**
* @ORM\Column(type="string", length=180, unique=true, nullable=true)
* @Groups("main")
*/
private $username;
/**
* @ORM\Column(type="string", length=50, unique=true, nullable=true)
* @Groups("main")
*/
private $googleId;
/**
* @ORM\Column(type="string", length=50, unique=true, nullable=true)
* @Groups("main")
*/
private $facebookId;
/**
* @ORM\Column(type="array")
*/
private $roles = [];
/**
* @var string The hashed password
* @ORM\Column(type="string", nullable=true)
*/
private $password;
/**
* @ORM\Column(type="string", length=50)
* @Groups("main")
*/
private $primerNombre;
/**
* @ORM\Column(type="string", length=50, nullable=true)
* * @Groups("main")
*/
private $segundoNombre;
/**
* @ORM\Column(type="string", length=50, nullable=true)
* * @Groups("main")
*/
private $tercerNombre;
/**
* @ORM\Column(type="string", length=50)
* @Groups("main")
*/
private $primerApellido;
/**
* @ORM\Column(type="string", length=50, nullable=true)
* @Groups("main")
*/
private $segundoApellido;
/**
* @ORM\Column(type="string", length=255)
* @Groups("main")
*/
private $nombreCompleto;
/**
* @ORM\OneToOne(targetEntity="App\Core\Entity\Maestro", mappedBy="user", cascade={"persist", "remove"})
*/
private $maestro;
/**
* @ORM\OneToOne(targetEntity="App\Core\Entity\Estudiante", mappedBy="user", cascade={"persist", "remove"})
*/
private $estudiante;
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*
* @Vich\UploadableField(mapping="imagen_de_usuario", fileNameProperty="imageName", size="imageSize")
*
* @var File|null
*/
private $imageFile;
/**
* @ORM\Column(type="string", length=200, nullable=true)
* @Groups("main")
*
* @var string|null
*/
private $imageName;
/**
* @ORM\Column(type="integer", nullable=true)
*
* @var int|null
*/
private $imageSize;
/**
* @ORM\Column(type="string", length=16, nullable=true)
* @Groups("main")
*/
private $numeroTelefonico;
/**
* @ORM\ManyToOne(targetEntity=Country::class)
* @ORM\JoinColumn(nullable=true)
*/
private $paisCodigoTelefonico;
/**
* @ORM\Column(type="date", nullable=true)
* @Groups("main")
*/
private $fechaNacimiento;
/**
* @ORM\Column(type="integer", nullable=true)
* @Groups("main")
*/
private $genero;
/**
* @ORM\OneToOne(targetEntity="App\Core\Entity\InformacionPerfil")
* @ORM\JoinColumn(nullable=true)
* @Groups("main")
*/
private $informacionPerfil;
/**
* @ORM\Column(type="string", length=10, nullable=false)
* @Groups("main")
*/
private $idioma;
/**
* @ORM\OneToMany(targetEntity="App\Core\Entity\CategoriaUsuario", mappedBy="usuario", orphanRemoval=false)
*/
private $categoriasUsuario;
/**
* @ORM\OneToMany(targetEntity=Participante::class, mappedBy="usuario", orphanRemoval=true)
*/
private $participacionesChat;
/**
* @ORM\OneToMany(targetEntity=Seguidor::class, mappedBy="seguidor")
*/
private $seguidos;
/**
* @ORM\OneToMany(targetEntity=Seguidor::class, mappedBy="seguido")
*/
private $seguidores;
public $yaSeguido;
/**
* @ORM\OneToMany(targetEntity=Bloqueos::class, mappedBy="bloqueador")
*/
private $bloqueados;
/**
* @ORM\OneToMany(targetEntity=Bloqueos::class, mappedBy="bloqueado")
*/
private $bloqueadores;
/**
* @ORM\Column(type="datetime")
* @Groups("main")
*/
private $createdAt;
/**
* @ORM\OneToMany(targetEntity=CybersourceTransLog::class, mappedBy="user", orphanRemoval=true)
*/
private $cybersourceTransLogs;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $tokenConfirmarEmail;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $tokenRecuperarPassword;
/**
* @ORM\Column(type="boolean", nullable=true, options={"default": false})
*/
private $emailConfirmado = false;
/**
* @ORM\Column(type="boolean", nullable=true, options={"default": false})
*/
private $debitoAutomatico = false;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $tokenCybersource;
/**
* @ORM\OneToOne(targetEntity=Director::class, mappedBy="usuario", cascade={"persist", "remove"})
*/
private $director;
/**
* @ORM\OneToMany(targetEntity=TutorialUsuario::class, mappedBy="user", orphanRemoval=true)
*/
private $tutorialesUsuario;
/**
* @ORM\OneToMany(targetEntity=Notificacion::class, mappedBy="destinatario", orphanRemoval=true)
*/
private $notificaciones;
/**
* @ORM\Column(type="boolean", nullable=true, options={"default": true})
*/
private $tutorial = true;
/**
* @ORM\OneToOne(targetEntity=Calendario::class, cascade={"persist", "remove"})
*/
private $calendario;
public function __construct()
{
$this->categoriasUsuario = new ArrayCollection();
$this->participacionesChat = new ArrayCollection();
$this->seguidos = new ArrayCollection();
$this->seguidores = new ArrayCollection();
$this->bloqueados = new ArrayCollection();
$this->bloqueadores = new ArrayCollection();
$this->cybersourceTransLogs = new ArrayCollection();
$this->tutorialesUsuario = new ArrayCollection();
$this->notificaciones = new ArrayCollection();
}
/**
* @return bool
*/
public function isTutorial(): bool
{
return $this->tutorial;
}
/**
* @param bool $tutorial
*/
public function setTutorial(bool $tutorial): void
{
$this->tutorial = $tutorial;
}
public function getId(): ?int
{
return $this->id;
}
public function getUserIdentifier(): string
{
return $this->username;
}
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 getUsername(): string
{
return (string) $this->username;
}
public function setUsername(string $username): self
{
$this->username = $username;
return $this;
}
public function getGoogleId(): ?string
{
return $this->googleId;
}
public function setGoogleId(?string $googleId): self
{
$this->googleId = $googleId;
return $this;
}
public function getFacebookId(): ?string
{
return $this->facebookId;
}
public function setFacebookId(?string $facebookId): self
{
$this->facebookId = $facebookId;
return $this;
}
/**
* @see UserInterface
*/
public function getRoles(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER';
return array_unique($roles);
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
/**
* @see UserInterface
*/
public function getPassword(): string
{
return (string) $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* @see UserInterface
*/
public function getSalt()
{
// not needed when using the "bcrypt" algorithm in security.yaml
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function getPrimerNombre(): ?string
{
return $this->primerNombre;
}
public function setPrimerNombre(string $primerNombre): self
{
$this->primerNombre = $primerNombre;
return $this;
}
public function getSegundoNombre(): ?string
{
return $this->segundoNombre;
}
public function setSegundoNombre(string $segundoNombre): self
{
$this->segundoNombre = $segundoNombre;
return $this;
}
public function getTercerNombre(): ?string
{
return $this->tercerNombre;
}
public function setTercerNombre(string $tercerNombre): self
{
$this->tercerNombre = $tercerNombre;
return $this;
}
public function getPrimerApellido(): ?string
{
return $this->primerApellido;
}
public function setPrimerApellido(string $primerApellido): self
{
$this->primerApellido = $primerApellido;
return $this;
}
public function getSegundoApellido(): ?string
{
return $this->segundoApellido;
}
public function setSegundoApellido(?string $segundoApellido): self
{
$this->segundoApellido = $segundoApellido;
return $this;
}
public function getNombreCompleto(): ?string
{
return $this->nombreCompleto;
}
public function asignarNombreCompleto(): self
{
$nombres = '';
$nombres .= $this->primerNombre . ' ';
if ($this->segundoNombre) {
$nombres .= $this->segundoNombre . ' ';
}
if ($this->tercerNombre) {
$nombres .= $this->tercerNombre . ' ';
}
$nombres .= $this->primerApellido;
if ($this->segundoApellido) {
$nombres .= ' ' . $this->segundoApellido;
}
$this->nombreCompleto = $nombres;
return $this;
}
public function getMaestro(): ?Maestro
{
return $this->maestro;
}
public function setMaestro(Maestro $maestro): self
{
$this->maestro = $maestro;
// set the owning side of the relation if necessary
if ($maestro->getUser() !== $this) {
$maestro->setUser($this);
}
return $this;
}
public function getEstudiante(): ?Estudiante
{
return $this->estudiante;
}
public function setEstudiante(Estudiante $estudiante): self
{
$this->estudiante = $estudiante;
// set the owning side of the relation if necessary
if ($estudiante->getUser() !== $this) {
$estudiante->setUser($this);
}
return $this;
}
/**
* If manually uploading a file (i.e. not using Symfony Form) ensure an instance
* of 'UploadedFile' is injected into this setter to trigger the update. If this
* bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
* must be able to accept an instance of 'File' as the bundle will inject one here
* during Doctrine hydration.
*
* @param File|UploadedFile|null $uploadedFile
*/
public function setImageFile(?File $uploadedFile = null): void
{
$this->imageFile = $uploadedFile;
if (null !== $uploadedFile) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->setImageSize($uploadedFile->getSize());
}
}
public function getImageFile(): ?File
{
return $this->imageFile;
}
public function setImageName(?string $imageName): void
{
$this->imageName = $imageName;
}
public function getImageName(): ?string
{
return $this->imageName;
}
public function setImageSize(?int $imageSize): void
{
$this->imageSize = $imageSize;
}
public function getImageSize(): ?int
{
return $this->imageSize;
}
/**
* @inheritDoc
*/
public function serialize($data, $format, array $context = [])
{
// TODO: Implement serialize() method.
}
/**
* @inheritDoc
*/
public function deserialize($data, $type, $format, array $context = [])
{
// TODO: Implement deserialize() method.
}
public function getNumeroTelefonico(): ?string
{
return $this->numeroTelefonico;
}
public function setNumeroTelefonico(?string $numeroTelefonico): self
{
$this->numeroTelefonico = $numeroTelefonico;
return $this;
}
public function getFechaNacimiento(): ?\DateTimeInterface
{
return $this->fechaNacimiento;
}
public function setFechaNacimiento(?\DateTimeInterface $fechaNacimiento): self
{
$this->fechaNacimiento = $fechaNacimiento;
return $this;
}
public function getGenero(): ?int
{
return $this->genero;
}
public function setGenero(?int $genero): self
{
$this->genero = $genero;
return $this;
}
public function getInformacionPerfil(): ?InformacionPerfil
{
return $this->informacionPerfil;
}
public function setInformacionPerfil(InformacionPerfil $informacionPerfil): self
{
$this->informacionPerfil = $informacionPerfil;
return $this;
}
function asignarNombresUsuario($todosLosNombres) {
//Separa los nombres que ingres
$nombres = $this->eliminarPosicionesVacias(explode(" ", trim($todosLosNombres)));
$this->setPrimerNombre($nombres[0]);
if(count($nombres) > 1) {
$this->setSegundoNombre($nombres[1]);
if(count($nombres) > 2) {
$tercerNombre = '';
for ($i = 2; $i < count($nombres); $i++) {
$tercerNombre .= $nombres[$i];
if ($i !== count($nombres) - 1) {
$tercerNombre .= ' ';
}
}
$this->setTercerNombre($tercerNombre);
}
}
}
function asignarApellidosUsuario($todosLosApellidos) {
//Separa los apellidos que ingres
$apellidos = $this->eliminarPosicionesVacias(explode(" ", trim($todosLosApellidos)));
$this->setPrimerApellido($apellidos[0]);
if(count($apellidos) >= 2) {
$segundoApellido = '';
for ($i = 1; $i < count($apellidos); $i++) {
$segundoApellido .= $apellidos[$i];
if ($i !== count($apellidos) - 1) {
$segundoApellido .= ' ';
}
}
$this->setSegundoApellido($segundoApellido);
}
}
function eliminarPosicionesVacias($stringsArray) {
$nuevoArray = [];
foreach ($stringsArray as $string) {
if (trim($string) !== '') {
array_push($nuevoArray, $string);
}
}
return $nuevoArray;
}
public function getIdioma(): ?string
{
return $this->idioma;
}
public function setIdioma(string $idioma): self
{
$this->idioma = $idioma;
return $this;
}
/**
* @return Collection|CategoriaUsuario[]
*/
public function getCategoriasUsuario(): Collection
{
return $this->categoriasUsuario;
}
public function addCategoriaUsuario(CategoriaUsuario $categoriaUsuario): self
{
if (!$this->categoriasUsuario->contains($categoriaUsuario)) {
$this->categoriasUsuario[] = $categoriaUsuario;
$categoriaUsuario->setUsuario($this);
}
return $this;
}
public function removeCategoriaUsuario(CategoriaUsuario $categoriaUsuario): self
{
if ($this->categoriasUsuario->contains($categoriaUsuario)) {
$this->categoriasUsuario->removeElement($categoriaUsuario);
// set the owning side to null (unless already changed)
if ($categoriaUsuario->getUsuario() === $this) {
$categoriaUsuario->setUsuario(null);
}
}
return $this;
}
/**
* @return Collection|Participante[]
*/
public function getParticipacionesChat(): Collection
{
return $this->participacionesChat;
}
public function addParticipacionesChat(Participante $participacionesChat): self
{
if (!$this->participacionesChat->contains($participacionesChat)) {
$this->participacionesChat[] = $participacionesChat;
$participacionesChat->setUsuario($this);
}
return $this;
}
public function removeParticipacionesChat(Participante $participacionesChat): self
{
if ($this->participacionesChat->contains($participacionesChat)) {
$this->participacionesChat->removeElement($participacionesChat);
// set the owning side to null (unless already changed)
if ($participacionesChat->getUsuario() === $this) {
$participacionesChat->setUsuario(null);
}
}
return $this;
}
/**
* @return Collection|Seguidor[]
*/
public function getSeguidos(): Collection
{
return $this->seguidos;
}
public function addSeguido(Seguidor $seguido): self
{
if (!$this->seguidos->contains($seguido)) {
$this->seguidos[] = $seguido;
$seguido->setSeguidor($this);
}
return $this;
}
public function removeSeguido(Seguidor $seguido): self
{
if ($this->seguidos->contains($seguido)) {
$this->seguidos->removeElement($seguido);
// set the owning side to null (unless already changed)
if ($seguido->getSeguidor() === $this) {
$seguido->setSeguidor(null);
}
}
return $this;
}
/**
* @return Collection|Seguidor[]
*/
public function getSeguidores(): Collection
{
return $this->seguidores;
}
public function addSeguidor(Seguidor $seguidore): self
{
if (!$this->seguidores->contains($seguidore)) {
$this->seguidores[] = $seguidore;
$seguidore->setSeguido($this);
}
return $this;
}
public function removeSeguidor(Seguidor $seguidore): self
{
if ($this->seguidores->contains($seguidore)) {
$this->seguidores->removeElement($seguidore);
// set the owning side to null (unless already changed)
if ($seguidore->getSeguido() === $this) {
$seguidore->setSeguido(null);
}
}
return $this;
}
/**
* @return Collection|Bloqueos[]
*/
public function getBloqueados(): Collection
{
return $this->bloqueados;
}
public function addBloqueado(Bloqueos $bloqueado): self
{
if (!$this->bloqueados->contains($bloqueado)) {
$this->bloqueados[] = $bloqueado;
$bloqueado->setBloqueador($this);
}
return $this;
}
public function removeBloqueado(Bloqueos $bloqueado): self
{
if ($this->bloqueados->removeElement($bloqueado)) {
// set the owning side to null (unless already changed)
if ($bloqueado->getBloqueador() === $this) {
$bloqueado->setBloqueador(null);
}
}
return $this;
}
/**
* @return Collection|Bloqueos[]
*/
public function getBloqueadores(): Collection
{
return $this->bloqueadores;
}
public function addBloqueadore(Bloqueos $bloqueadore): self
{
if (!$this->bloqueadores->contains($bloqueadore)) {
$this->bloqueadores[] = $bloqueadore;
$bloqueadore->setBloqueado($this);
}
return $this;
}
public function removeBloqueadore(Bloqueos $bloqueadore): self
{
if ($this->bloqueadores->removeElement($bloqueadore)) {
// set the owning side to null (unless already changed)
if ($bloqueadore->getBloqueado() === $this) {
$bloqueadore->setBloqueado(null);
}
}
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
/**
* @return Collection|CybersourceTransLog[]
*/
public function getCybersourceTransLogs(): Collection
{
return $this->cybersourceTransLogs;
}
public function addCybersourceTransLog(CybersourceTransLog $cybersourceTransLog): self
{
if (!$this->cybersourceTransLogs->contains($cybersourceTransLog)) {
$this->cybersourceTransLogs[] = $cybersourceTransLog;
$cybersourceTransLog->setUser($this);
}
return $this;
}
public function removeCybersourceTransLog(CybersourceTransLog $cybersourceTransLog): self
{
if ($this->cybersourceTransLogs->removeElement($cybersourceTransLog)) {
// set the owning side to null (unless already changed)
if ($cybersourceTransLog->getUser() === $this) {
$cybersourceTransLog->setUser(null);
}
}
return $this;
}
public function getTokenConfirmarEmail(): ?string
{
return $this->tokenConfirmarEmail;
}
public function setTokenConfirmarEmail(?string $tokenConfirmarEmail): self
{
$this->tokenConfirmarEmail = $tokenConfirmarEmail;
return $this;
}
public function getTokenRecuperarPassword(): ?string
{
return $this->tokenRecuperarPassword;
}
public function setTokenRecuperarPassword(?string $tokenRecuperarPassword): self
{
$this->tokenRecuperarPassword = $tokenRecuperarPassword;
return $this;
}
public function getEmailConfirmado(): ?bool
{
return $this->emailConfirmado;
}
public function setEmailConfirmado(bool $emailConfirmado): self
{
$this->emailConfirmado = $emailConfirmado;
return $this;
}
public function getDebitoAutomatico(): ?bool
{
return $this->debitoAutomatico;
}
public function setDebitoAutomatico(bool $debitoAutomatico): self
{
$this->debitoAutomatico = $debitoAutomatico;
return $this;
}
public function getTokenCybersource(): ?string
{
return $this->tokenCybersource;
}
public function setTokenCybersource(?string $tokenCybersource): self
{
$this->tokenCybersource = $tokenCybersource;
return $this;
}
public function getDirector(): ?Director
{
return $this->director;
}
public function setDirector(Director $director): self
{
// set the owning side of the relation if necessary
if ($director->getUser() !== $this) {
$director->setUser($this);
}
$this->director = $director;
return $this;
}
public function getCodigoNumeroTelefonico() {
return $this->paisCodigoTelefonico->getCodigoTelefonico();
}
public function getPaisCodigoNumeroTelefonico() {
return $this->paisCodigoTelefonico;
}
public function setPaisCodigoTelefonico(Country $paisCodigo): self {
$this->paisCodigoTelefonico = $paisCodigo;
return $this;
}
/**
* @return Collection|TutorialUsuario[]
*/
public function getTutorialesUsuario(): Collection
{
return $this->tutorialesUsuario;
}
public function addTutorialesUsuario(TutorialUsuario $tutorialesUsuario): self
{
if (!$this->tutorialesUsuario->contains($tutorialesUsuario)) {
$this->tutorialesUsuario[] = $tutorialesUsuario;
$tutorialesUsuario->setUser($this);
}
return $this;
}
public function removeTutorialesUsuario(TutorialUsuario $tutorialesUsuario): self
{
if ($this->tutorialesUsuario->removeElement($tutorialesUsuario)) {
// set the owning side to null (unless already changed)
if ($tutorialesUsuario->getUser() === $this) {
$tutorialesUsuario->setUser(null);
}
}
return $this;
}
/**
* @return Collection|Notificacion[]
*/
public function getNotificacionesNoVistas(): Collection
{
$notificacionesNoVistas = new ArrayCollection();
for ($i = 0; $i < $this->notificaciones->count(); $i++) {
/** @var Notificacion $notificacion */
$notificacion = $this->notificaciones->get($i);
if (!$notificacion->getVista()) {
$notificacionesNoVistas->add($notificacion);
}
}
return $notificacionesNoVistas;
}
/**
* @return Collection|Notificacion[]
*/
public function getNotificaciones(): Collection
{
return $this->notificaciones;
}
public function getCalendario(): ?Calendario
{
return $this->calendario;
}
public function setCalendario(?Calendario $calendario): self
{
$this->calendario = $calendario;
return $this;
}
}