src/Entity/User.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Validator as PerseoAssert;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Gedmo\Mapping\Annotation as Gedmo;
  9. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  10. use Symfony\Component\Security\Core\User\UserInterface;
  11. use Symfony\Component\Uid\Uuid;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. /**
  14. * @ORM\Entity(repositoryClass="App\Repository\UserRepository")
  15. * @ORM\Table(name="user", schema="perseo")
  16. * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false, hardDelete=true)
  17. * @PerseoAssert\ContraintsValidarEntidadCp()
  18. */
  19. class User implements UserInterface, PasswordAuthenticatedUserInterface
  20. {
  21. /**
  22. * @ORM\Id
  23. * @ORM\Column(type="uuid", unique=true)
  24. * @ORM\GeneratedValue(strategy="CUSTOM")
  25. * @ORM\CustomIdGenerator(class="doctrine.uuid_generator")
  26. */
  27. protected $id;
  28. /**
  29. * @ORM\Column(type="string", unique=true, length=180, nullable=false)
  30. */
  31. protected $username;
  32. /**
  33. * @ORM\Column(type="string", unique=true, length=180, nullable=false)
  34. */
  35. protected $email;
  36. /**
  37. * @ORM\Column(type="json", nullable=false)
  38. */
  39. protected $roles = [];
  40. /**
  41. * @var string The hashed password
  42. * @ORM\Column(type="string", nullable=false)
  43. */
  44. protected $password;
  45. /**
  46. * @ORM\Column(type="string", nullable=true)
  47. */
  48. protected $nombre;
  49. /**
  50. * @ORM\Column(type="string", nullable=true, name="primer_apellido")
  51. */
  52. protected $primerApellido;
  53. /**
  54. * @ORM\Column(type="string", nullable=true, name="segundo_apellido")
  55. */
  56. protected $segundoApellido;
  57. /**
  58. * @ORM\Column(type="bigint", nullable=true, name="tipo_genero_id", options={"unsigned":true})
  59. */
  60. protected $tipoGenero;
  61. /**
  62. * @ORM\Column(type="string", nullable=true)
  63. */
  64. protected $direccion;
  65. /**
  66. * @ORM\Column(type="string", length=12, nullable=true)
  67. * @Assert\Length(min = 5, max = 12)
  68. */
  69. protected $cp;
  70. /**
  71. * @ORM\Column(type="string", nullable=true)
  72. */
  73. protected $region;
  74. /**
  75. * @ORM\Column(type="string", nullable=true)
  76. */
  77. protected $ciudad;
  78. /**
  79. * @ORM\Column(type="string", nullable=true)
  80. */
  81. protected $telefono;
  82. /**
  83. * @ORM\Column(type="datetime", nullable=true, name="deleted_at")
  84. */
  85. protected $deletedAt;
  86. /**
  87. * @ORM\Column(type="datetime", nullable=false, options={"default":"2019-01-01 00:00:00"})
  88. * @Gedmo\Timestampable(on="update")
  89. */
  90. protected $updatedAt;
  91. /**
  92. * @ORM\Column(type="datetime", nullable=false, options={"default":"2019-01-01 00:00:00"})
  93. * @Gedmo\Timestampable(on="create")
  94. */
  95. protected $createdAt;
  96. /**
  97. * @ORM\Column(type="string", length=2, nullable=true, name="pais")
  98. */
  99. protected $pais;
  100. /**
  101. * @ORM\ManyToOne(targetEntity="App\Entity\CCAA", inversedBy="user")
  102. * @ORM\JoinColumn(name="ccaa_id", referencedColumnName="id")
  103. */
  104. protected $ccaa;
  105. /*
  106. * @ORM\ManyToOne(targetEntity="App\Entity\Ciudad", inversedBy="user")
  107. * @ORM\JoinColumn(name="ciudad_id", referencedColumnName="id")
  108. */
  109. //protected $ciudad;
  110. /**
  111. * @ORM\ManyToOne(targetEntity="App\Entity\Provincia", inversedBy="user")
  112. * @ORM\JoinColumn(name="provincia_id", referencedColumnName="id")
  113. */
  114. protected $provincia;
  115. /**
  116. * @ORM\OneToOne(targetEntity="App\Entity\Cliente", inversedBy="user", cascade={"persist"})
  117. * @ORM\JoinColumn(name="cliente_id", referencedColumnName="id", nullable=true, unique=true)
  118. */
  119. protected $cliente;
  120. /**
  121. * @ORM\OneToOne(targetEntity="App\Entity\Usuario", inversedBy="user", cascade={"persist"})
  122. * @ORM\JoinColumn(name="usuario_id", referencedColumnName="id", nullable=true, unique=true)
  123. */
  124. protected $usuario;
  125. public function __construct()
  126. {
  127. // $this->cliente = new Cliente();
  128. // $this->usuario = new Usuario();
  129. }
  130. public function getNombreCompleto()
  131. {
  132. return $this->getNombre() . ' ' . $this->getPrimerApellido() . ' ' . $this->getSegundoApellido();
  133. }
  134. public function getIniciales()
  135. {
  136. return mb_substr($this->getNombre(), 0, 1) . ' ' . mb_substr($this->getPrimerApellido(), 0, 1) . ' ' . mb_substr($this->getSegundoApellido(), 0, 1);
  137. }
  138. public function getId(): ?Uuid
  139. {
  140. return $this->id;
  141. }
  142. /**
  143. * @deprecated since Symfony 5.3, use getUserIdentifier instead
  144. */
  145. public function getUsername(): string
  146. {
  147. return (string) $this->username;
  148. }
  149. public function setUsername(string $username): self
  150. {
  151. $this->username = $username;
  152. return $this;
  153. }
  154. /**
  155. * A visual identifier that represents this user.
  156. *
  157. * @see UserInterface
  158. */
  159. public function getUserIdentifier(): string
  160. {
  161. return (string) $this->username;
  162. }
  163. /**
  164. * @see UserInterface
  165. */
  166. public function getRoles(): array
  167. {
  168. $roles = $this->roles;
  169. // guarantee every user at least has ROLE_USER
  170. $roles[] = 'ROLE_USER';
  171. return array_unique($roles);
  172. }
  173. public function setRoles(array $roles): self
  174. {
  175. $this->roles = $roles;
  176. return $this;
  177. }
  178. /**
  179. * @see PasswordAuthenticatedUserInterface
  180. */
  181. public function getPassword(): ?string
  182. {
  183. return $this->password;
  184. }
  185. public function setPassword(?string $password): self
  186. {
  187. $this->password = $password;
  188. return $this;
  189. }
  190. /**
  191. * Returning a salt is only needed, if you are not using a modern
  192. * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  193. *
  194. * @see UserInterface
  195. */
  196. public function getSalt(): ?string
  197. {
  198. return null;
  199. }
  200. /**
  201. * @see UserInterface
  202. */
  203. public function eraseCredentials()
  204. {
  205. // If you store any temporary, sensitive data on the user, clear it here
  206. // $this->plainPassword = null;
  207. }
  208. public function getCliente(): ?Cliente
  209. {
  210. return $this->cliente;
  211. }
  212. public function setCliente(Cliente $cliente): self
  213. {
  214. $this->cliente = $cliente;
  215. return $this;
  216. }
  217. public function getUsuario(): ?Usuario
  218. {
  219. return $this->usuario;
  220. }
  221. public function setUsuario(?Usuario $usuario): self
  222. {
  223. $this->usuario = $usuario;
  224. return $this;
  225. }
  226. public function getEmail(): ?string
  227. {
  228. return $this->email;
  229. }
  230. public function setEmail(string $email): self
  231. {
  232. $this->email = $email;
  233. return $this;
  234. }
  235. public function getNombre(): ?string
  236. {
  237. return $this->nombre;
  238. }
  239. public function setNombre(?string $nombre): self
  240. {
  241. $this->nombre = $nombre;
  242. return $this;
  243. }
  244. public function getPrimerApellido(): ?string
  245. {
  246. return $this->primerApellido;
  247. }
  248. public function setPrimerApellido(?string $primerApellido): self
  249. {
  250. $this->primerApellido = $primerApellido;
  251. return $this;
  252. }
  253. public function getSegundoApellido(): ?string
  254. {
  255. return $this->segundoApellido;
  256. }
  257. public function setSegundoApellido(?string $segundoApellido): self
  258. {
  259. $this->segundoApellido = $segundoApellido;
  260. return $this;
  261. }
  262. public function getTipoGenero(): ?string
  263. {
  264. return $this->tipoGenero;
  265. }
  266. public function setTipoGenero(?string $tipoGenero): self
  267. {
  268. $this->tipoGenero = $tipoGenero;
  269. return $this;
  270. }
  271. public function getDireccion(): ?string
  272. {
  273. return $this->direccion;
  274. }
  275. public function setDireccion(?string $direccion): self
  276. {
  277. $this->direccion = $direccion;
  278. return $this;
  279. }
  280. public function getCp(): ?string
  281. {
  282. return $this->cp;
  283. }
  284. public function setCp(?string $cp): self
  285. {
  286. $this->cp = $cp;
  287. return $this;
  288. }
  289. public function getTelefono(): ?string
  290. {
  291. return $this->telefono;
  292. }
  293. public function setTelefono(?string $telefono): self
  294. {
  295. $this->telefono = $telefono;
  296. return $this;
  297. }
  298. public function getCreatedAt(): ?\DateTimeInterface
  299. {
  300. return $this->createdAt;
  301. }
  302. public function setCreatedAt(\DateTimeInterface $createdAt): self
  303. {
  304. $this->createdAt = $createdAt;
  305. return $this;
  306. }
  307. public function getUpdatedAt(): ?\DateTimeInterface
  308. {
  309. return $this->updatedAt;
  310. }
  311. public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  312. {
  313. $this->updatedAt = $updatedAt;
  314. return $this;
  315. }
  316. public function getCcaa(): ?CCAA
  317. {
  318. return $this->ccaa;
  319. }
  320. public function setCcaa(?CCAA $ccaa): self
  321. {
  322. $this->ccaa = $ccaa;
  323. return $this;
  324. }
  325. public function getCiudad(): ?string
  326. {
  327. return $this->ciudad;
  328. }
  329. public function setCiudad(?string $ciudad): self
  330. {
  331. $this->ciudad = $ciudad;
  332. return $this;
  333. }
  334. public function getPais(): ?string
  335. {
  336. return $this->pais;
  337. }
  338. public function setPais(?string $pais): self
  339. {
  340. $this->pais = $pais;
  341. return $this;
  342. }
  343. public function getProvincia(): ?Provincia
  344. {
  345. return $this->provincia;
  346. }
  347. public function setProvincia(?Provincia $provincia): self
  348. {
  349. $this->provincia = $provincia;
  350. return $this;
  351. }
  352. public function getDeletedAt(): ?\DateTimeInterface
  353. {
  354. return $this->deletedAt;
  355. }
  356. public function setDeletedAt(?\DateTimeInterface $deletedAt): self
  357. {
  358. $this->deletedAt = $deletedAt;
  359. return $this;
  360. }
  361. public function getRegion(): ?string
  362. {
  363. return $this->region;
  364. }
  365. public function setRegion(?string $region): static
  366. {
  367. $this->region = $region;
  368. return $this;
  369. }
  370. }