src/Entity/Usuario.php line 27

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UsuarioRepository;
  4. use DateTime;
  5. use DateTimeInterface;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use JMS\Serializer\Annotation as Serializer;
  10. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  11. use Symfony\Component\Security\Core\User\UserInterface;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. use App\Validator as CustomAssert;
  14. #[ORM\InheritanceType('JOINED')]
  15. #[ORM\DiscriminatorColumn(name: 'tipo', type: 'string')]
  16. #[ORM\DiscriminatorMap(['usuario' => 'Usuario'])]
  17. #[ORM\Entity(repositoryClass: UsuarioRepository::class)]
  18. #[UniqueEntity('usuario')]
  19. #[UniqueEntity('email')]
  20. #[UniqueEntity('dniNie')]
  21. #[ORM\Table(name: 'usuario')]
  22. #[ORM\UniqueConstraint(name: 'unique_usuario', columns: ['usuario'])]
  23. #[ORM\UniqueConstraint(name: 'unique_email', columns: ['email'])]
  24. class Usuario implements UserInterface
  25. {
  26. #[ORM\Id]
  27. #[ORM\GeneratedValue]
  28. #[ORM\Column(type: 'integer')]
  29. #[Serializer\Groups(groups: ['api'])]
  30. private ?int $id = null;
  31. #[Assert\NotBlank]
  32. #[Assert\Length(max: 190)]
  33. #[ORM\Column(type: 'string', length: 190, unique: true)]
  34. #[Serializer\Groups(groups: ['api'])]
  35. private ?string $usuario = null;
  36. #[Assert\NotBlank]
  37. #[Assert\Email]
  38. #[Assert\Length(max: 190)]
  39. #[ORM\Column(type: 'string', length: 190, unique: true)]
  40. #[Serializer\Groups(groups: ['api'])]
  41. private ?string $email = null;
  42. #[ORM\Column(type: 'array')]
  43. #[Serializer\Groups(groups: ['api'])]
  44. private ?array $roles = [];
  45. #[Assert\Length(max: 255)]
  46. #[ORM\Column(type: 'string')]
  47. private ?string $password = null;
  48. #[Assert\Length(max: 255)]
  49. #[ORM\Column(type: 'string', nullable: true)]
  50. #[Serializer\Groups(groups: ['api'])]
  51. private ?string $imagen = null;
  52. #[ORM\Column(type: 'boolean')]
  53. private ?bool $borrado = false;
  54. #[ORM\Column(type: 'datetime', nullable: true)]
  55. private ?DateTimeInterface $ultimoAcceso = null;
  56. #[ORM\Column(type: 'datetime', nullable: true)]
  57. #[Serializer\Groups(groups: ['api'])]
  58. private ?DateTime $ultimoAccesoApp = null;
  59. #[ORM\Column(type: 'datetime')]
  60. #[Serializer\Groups(groups: ['api'])]
  61. private ?DateTime $fechaRegistro = null;
  62. #[Assert\Length(max: 255)]
  63. #[ORM\Column(type: 'string', nullable: true)]
  64. protected $tokenConfirmacion;
  65. #[ORM\Column(type: 'datetime', nullable: true)]
  66. protected $fechaSolicitudPassword;
  67. #[ORM\Column(type: 'boolean')]
  68. #[Serializer\Groups(groups: ['api'])]
  69. private ?bool $activo = true;
  70. #[ORM\Column(type: 'boolean')]
  71. private ?bool $aceptaCondicionesPrivacidad = null;
  72. #[ORM\OneToMany(mappedBy: 'usuario', targetEntity: NotificacionPush::class)]
  73. private Collection $notificacionesPushes;
  74. #[ORM\Column(type: 'boolean')]
  75. private bool $recibirEmailsSistema = true;
  76. #[Assert\Length(max: 255)]
  77. #[ORM\Column(type: 'string', length: 255, nullable: true)]
  78. private ?string $nombre = null;
  79. #[Assert\Length(max: 255)]
  80. #[ORM\Column(type: 'string', length: 255, nullable: true)]
  81. private ?string $apellidos = null;
  82. #[CustomAssert\IsDniNie]
  83. #[ORM\Column(type: 'string', length: 9, unique: true, nullable: true)]
  84. private ?string $dniNie = null;
  85. #[ORM\Column(type: 'date', nullable: true)]
  86. private ?DateTimeInterface $fechaNacimiento = null;
  87. #[ORM\ManyToOne(targetEntity: SexoUsuario::class, inversedBy: 'usuarios')]
  88. private ?SexoUsuario $sexo = null;
  89. #[ORM\OneToMany(mappedBy: 'usuario', targetEntity: Solicitud::class)]
  90. private Collection $solicitudes;
  91. #[ORM\ManyToOne(targetEntity: Localidad::class, inversedBy: 'usuarios')]
  92. private ?Localidad $localidad = null;
  93. #[ORM\Column(type: 'string', length: 255, nullable: true)]
  94. private ?string $direccion = null;
  95. #[ORM\Column(type: 'string', length: 5, nullable: true)]
  96. private ?string $codigoPostal = null;
  97. #[ORM\Column(type: 'string', length: 9, nullable: true)]
  98. private ?string $telefono1 = null;
  99. #[ORM\Column(type: 'string', length: 9, nullable: true)]
  100. private ?string $telefono2 = null;
  101. #[ORM\ManyToOne(inversedBy: 'usuarios')]
  102. private ?EmpresaFormacion $empresaFormacion = null;
  103. #[ORM\OneToMany(mappedBy: 'usuario', targetEntity: BitacoraUsuario::class)]
  104. private Collection $mensagesBitacora;
  105. #[ORM\OneToMany(mappedBy: 'autor', targetEntity: BitacoraUsuario::class)]
  106. private Collection $mensajesBitacoraComoAutor;
  107. #[ORM\Column]
  108. private bool $llamar = true;
  109. #[ORM\OneToMany(mappedBy: 'usuario', targetEntity: InscripcionUsuarioJornadaCurso::class)]
  110. private Collection $inscripcionesJornadasCursos;
  111. public function __construct()
  112. {
  113. $this->fechaRegistro = new DateTime();
  114. $this->setRoles([]);
  115. $this->notificacionesPushes = new ArrayCollection();
  116. $this->solicitudes = new ArrayCollection();
  117. $this->mensagesBitacora = new ArrayCollection();
  118. $this->mensajesBitacoraComoAutor = new ArrayCollection();
  119. $this->inscripcionesJornadasCursos = new ArrayCollection();
  120. }
  121. public function getId(): ?int
  122. {
  123. return $this->id;
  124. }
  125. public function setId(?int $id): self
  126. {
  127. $this->id = $id;
  128. return $this;
  129. }
  130. public function getUsuario(): ?string
  131. {
  132. return $this->usuario;
  133. }
  134. public function setUsuario(?string $usuario): self
  135. {
  136. $this->usuario = $usuario;
  137. return $this;
  138. }
  139. public function getEmail(): ?string
  140. {
  141. return $this->email;
  142. }
  143. public function setEmail(?string $email): self
  144. {
  145. $this->email = $email;
  146. $this->usuario = $email;
  147. return $this;
  148. }
  149. /**
  150. * A visual identifier that represents this user.
  151. *
  152. * @see UserInterface
  153. */
  154. public function getUsername(): string
  155. {
  156. return (string) $this->usuario;
  157. }
  158. /**
  159. * @see UserInterface
  160. */
  161. public function getRoles(): array
  162. {
  163. $roles = $this->roles;
  164. // guarantee every user at least has ROLE_USER
  165. $roles[] = 'ROLE_USER';
  166. return array_unique($roles);
  167. }
  168. public function setRoles(?array $roles): self
  169. {
  170. $this->roles = $roles;
  171. return $this;
  172. }
  173. /**
  174. * @see UserInterface
  175. */
  176. public function getPassword(): string
  177. {
  178. return $this->password;
  179. }
  180. public function setPassword(?string $password): self
  181. {
  182. $this->password = $password;
  183. return $this;
  184. }
  185. /**
  186. * @see UserInterface
  187. */
  188. public function getSalt(): void
  189. {
  190. // not needed when using the "bcrypt" algorithm in security.yaml
  191. }
  192. /**
  193. * @see UserInterface
  194. */
  195. public function eraseCredentials(): void
  196. {
  197. // If you store any temporary, sensitive data on the user, clear it here
  198. // $this->plainPassword = null;
  199. }
  200. public function getImagen(): ?string
  201. {
  202. return $this->imagen;
  203. }
  204. public function setImagen(?string $imagen): self
  205. {
  206. $this->imagen = $imagen;
  207. return $this;
  208. }
  209. public function getBorrado(): ?bool
  210. {
  211. return $this->borrado;
  212. }
  213. public function setBorrado(?bool $borrado): self
  214. {
  215. $this->borrado = $borrado;
  216. return $this;
  217. }
  218. public function getUltimoAcceso(): ?DateTimeInterface
  219. {
  220. return $this->ultimoAcceso;
  221. }
  222. public function setUltimoAcceso(?DateTimeInterface $ultimoAcceso): self
  223. {
  224. $this->ultimoAcceso = $ultimoAcceso;
  225. return $this;
  226. }
  227. public function getActivo(): ?bool
  228. {
  229. return $this->activo;
  230. }
  231. public function setActivo(?bool $activo): self
  232. {
  233. $this->activo = $activo;
  234. return $this;
  235. }
  236. /**
  237. * @return mixed
  238. */
  239. public function getTokenConfirmacion()
  240. {
  241. return $this->tokenConfirmacion;
  242. }
  243. public function setTokenConfirmacion(?string $tokenConfirmacion): Usuario
  244. {
  245. $this->tokenConfirmacion = $tokenConfirmacion;
  246. return $this;
  247. }
  248. public function getFechaSolicitudPassword(): ?DateTime
  249. {
  250. return $this->fechaSolicitudPassword;
  251. }
  252. public function setFechaSolicitudPassword(?DateTime $fechaSolicitudPassword): Usuario
  253. {
  254. $this->fechaSolicitudPassword = $fechaSolicitudPassword;
  255. return $this;
  256. }
  257. public function getUltimoAccesoApp(): ?DateTime
  258. {
  259. return $this->ultimoAccesoApp;
  260. }
  261. public function setUltimoAccesoApp(?DateTime $ultimoAccesoApp): Usuario
  262. {
  263. $this->ultimoAccesoApp = $ultimoAccesoApp;
  264. return $this;
  265. }
  266. public function getFechaRegistro(): ?DateTime
  267. {
  268. return $this->fechaRegistro;
  269. }
  270. public function setFechaRegistro(?DateTime $fechaRegistro): Usuario
  271. {
  272. $this->fechaRegistro = $fechaRegistro;
  273. return $this;
  274. }
  275. public function isAceptaCondicionesPrivacidad(): ?bool
  276. {
  277. return $this->aceptaCondicionesPrivacidad;
  278. }
  279. public function setAceptaCondicionesPrivacidad(?bool $aceptaCondicionesPrivacidad): self
  280. {
  281. $this->aceptaCondicionesPrivacidad = $aceptaCondicionesPrivacidad;
  282. return $this;
  283. }
  284. /**
  285. * @return Collection<int, NotificacionPush>
  286. */
  287. public function getNotificacionesPushes(): Collection
  288. {
  289. return $this->notificacionesPushes;
  290. }
  291. public function addNotificacionesPush(?NotificacionPush $notificacionesPush): self
  292. {
  293. if (!$this->notificacionesPushes->contains($notificacionesPush)) {
  294. $this->notificacionesPushes[] = $notificacionesPush;
  295. $notificacionesPush->setUsuario($this);
  296. }
  297. return $this;
  298. }
  299. public function removeNotificacionesPush(?NotificacionPush $notificacionesPush): self
  300. {
  301. // set the owning side to null (unless already changed)
  302. if ($this->notificacionesPushes->removeElement($notificacionesPush) && $notificacionesPush->getUsuario() === $this) {
  303. $notificacionesPush->setUsuario(null);
  304. }
  305. return $this;
  306. }
  307. public function isRecibirEmailsSistema(): ?bool
  308. {
  309. return $this->recibirEmailsSistema;
  310. }
  311. public function setRecibirEmailsSistema(bool $recibirEmailsSistema): self
  312. {
  313. $this->recibirEmailsSistema = $recibirEmailsSistema;
  314. return $this;
  315. }
  316. public function getNombre(): ?string
  317. {
  318. return $this->nombre;
  319. }
  320. public function setNombre(?string $nombre): self
  321. {
  322. $this->nombre = $nombre;
  323. return $this;
  324. }
  325. public function getApellidos(): ?string
  326. {
  327. return $this->apellidos;
  328. }
  329. public function setApellidos(?string $apellidos): self
  330. {
  331. $this->apellidos = $apellidos;
  332. return $this;
  333. }
  334. public function getDniNie(): ?string
  335. {
  336. return $this->dniNie;
  337. }
  338. public function setDniNie(?string $dniNie): self
  339. {
  340. $this->dniNie = $dniNie;
  341. return $this;
  342. }
  343. public function getFechaNacimiento(): ?DateTimeInterface
  344. {
  345. return $this->fechaNacimiento;
  346. }
  347. public function setFechaNacimiento(?DateTimeInterface $fechaNacimiento): self
  348. {
  349. $this->fechaNacimiento = $fechaNacimiento;
  350. return $this;
  351. }
  352. public function getSexo(): ?SexoUsuario
  353. {
  354. return $this->sexo;
  355. }
  356. public function setSexo(?SexoUsuario $sexo): self
  357. {
  358. $this->sexo = $sexo;
  359. return $this;
  360. }
  361. /**
  362. * @return Collection<int, Solicitud>
  363. */
  364. public function getSolicitudes(): Collection
  365. {
  366. return $this->solicitudes;
  367. }
  368. public function addSolicitude(Solicitud $solicitude): self
  369. {
  370. if (!$this->solicitudes->contains($solicitude)) {
  371. $this->solicitudes[] = $solicitude;
  372. $solicitude->setUsuario($this);
  373. }
  374. return $this;
  375. }
  376. public function removeSolicitude(Solicitud $solicitude): self
  377. {
  378. // set the owning side to null (unless already changed)
  379. if ($this->solicitudes->removeElement($solicitude) && $solicitude->getUsuario() === $this) {
  380. $solicitude->setUsuario(null);
  381. }
  382. return $this;
  383. }
  384. public function getLocalidad(): ?Localidad
  385. {
  386. return $this->localidad;
  387. }
  388. public function setLocalidad(?Localidad $localidad): self
  389. {
  390. $this->localidad = $localidad;
  391. return $this;
  392. }
  393. public function getDireccion(): ?string
  394. {
  395. return $this->direccion;
  396. }
  397. public function setDireccion(?string $direccion): self
  398. {
  399. $this->direccion = $direccion;
  400. return $this;
  401. }
  402. public function getCodigoPostal(): ?string
  403. {
  404. return $this->codigoPostal;
  405. }
  406. public function setCodigoPostal(?string $codigoPostal): self
  407. {
  408. $this->codigoPostal = $codigoPostal;
  409. return $this;
  410. }
  411. public function getTelefono1(): ?string
  412. {
  413. return $this->telefono1;
  414. }
  415. public function setTelefono1(?string $telefono1): self
  416. {
  417. $this->telefono1 = $telefono1;
  418. return $this;
  419. }
  420. public function getTelefono2(): ?string
  421. {
  422. return $this->telefono2;
  423. }
  424. public function setTelefono2(?string $telefono2): self
  425. {
  426. $this->telefono2 = $telefono2;
  427. return $this;
  428. }
  429. public function getEmpresaFormacion(): ?EmpresaFormacion
  430. {
  431. return $this->empresaFormacion;
  432. }
  433. public function setEmpresaFormacion(?EmpresaFormacion $empresaFormacion): static
  434. {
  435. $this->empresaFormacion = $empresaFormacion;
  436. return $this;
  437. }
  438. /**
  439. * @return Collection<int, BitacoraUsuario>
  440. */
  441. public function getMensagesBitacora(): Collection
  442. {
  443. return $this->mensagesBitacora;
  444. }
  445. public function addMensagesBitacora(BitacoraUsuario $mensagesBitacora): static
  446. {
  447. if (!$this->mensagesBitacora->contains($mensagesBitacora)) {
  448. $this->mensagesBitacora->add($mensagesBitacora);
  449. $mensagesBitacora->setUsuario($this);
  450. }
  451. return $this;
  452. }
  453. public function removeMensagesBitacora(BitacoraUsuario $mensagesBitacora): static
  454. {
  455. if ($this->mensagesBitacora->removeElement($mensagesBitacora)) {
  456. // set the owning side to null (unless already changed)
  457. if ($mensagesBitacora->getUsuario() === $this) {
  458. $mensagesBitacora->setUsuario(null);
  459. }
  460. }
  461. return $this;
  462. }
  463. /**
  464. * @return Collection<int, BitacoraUsuario>
  465. */
  466. public function getMensajesBitacoraComoAutor(): Collection
  467. {
  468. return $this->mensajesBitacoraComoAutor;
  469. }
  470. public function addMensajesBitacoraComoAutor(BitacoraUsuario $mensajesBitacoraComoAutor): static
  471. {
  472. if (!$this->mensajesBitacoraComoAutor->contains($mensajesBitacoraComoAutor)) {
  473. $this->mensajesBitacoraComoAutor->add($mensajesBitacoraComoAutor);
  474. $mensajesBitacoraComoAutor->setAutor($this);
  475. }
  476. return $this;
  477. }
  478. public function removeMensajesBitacoraComoAutor(BitacoraUsuario $mensajesBitacoraComoAutor): static
  479. {
  480. if ($this->mensajesBitacoraComoAutor->removeElement($mensajesBitacoraComoAutor)) {
  481. // set the owning side to null (unless already changed)
  482. if ($mensajesBitacoraComoAutor->getAutor() === $this) {
  483. $mensajesBitacoraComoAutor->setAutor(null);
  484. }
  485. }
  486. return $this;
  487. }
  488. public function isLlamar(): ?bool
  489. {
  490. return $this->llamar;
  491. }
  492. public function setLlamar(bool $llamar): static
  493. {
  494. $this->llamar = $llamar;
  495. return $this;
  496. }
  497. /**
  498. * @return Collection<int, InscripcionUsuarioJornadaCurso>
  499. */
  500. public function getInscripcionesJornadasCursos(): Collection
  501. {
  502. return $this->inscripcionesJornadasCursos;
  503. }
  504. public function addInscripcionesJornadasCurso(InscripcionUsuarioJornadaCurso $inscripcionesJornadasCurso): static
  505. {
  506. if (!$this->inscripcionesJornadasCursos->contains($inscripcionesJornadasCurso)) {
  507. $this->inscripcionesJornadasCursos->add($inscripcionesJornadasCurso);
  508. $inscripcionesJornadasCurso->setUsuario($this);
  509. }
  510. return $this;
  511. }
  512. public function removeInscripcionesJornadasCurso(InscripcionUsuarioJornadaCurso $inscripcionesJornadasCurso): static
  513. {
  514. if ($this->inscripcionesJornadasCursos->removeElement($inscripcionesJornadasCurso)) {
  515. // set the owning side to null (unless already changed)
  516. if ($inscripcionesJornadasCurso->getUsuario() === $this) {
  517. $inscripcionesJornadasCurso->setUsuario(null);
  518. }
  519. }
  520. return $this;
  521. }
  522. }