src/Entity/User.php line 28

Open in your IDE?
  1. <?php
  2. /**
  3. * Created by Mediterranean Develup Solutions.
  4. * User: jorge.defreitas@develup.solutions
  5. * Date: 14/06/2017
  6. * Time: 16:51
  7. */
  8. namespace App\Entity;
  9. use App\Entity\SettingsRol;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Doctrine\Common\Collections\Collection;
  12. use Doctrine\ORM\Mapping as ORM;
  13. use Symfony\Component\Security\Core\User\UserInterface;
  14. use Symfony\Component\Serializer\Annotation\Groups;
  15. use Symfony\Component\Validator\Constraints as Assert;
  16. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  17. /**
  18. * User
  19. */
  20. #[ORM\Entity(repositoryClass: \App\Repository\UserRepository::class)]
  21. #[UniqueEntity('username')]
  22. #[UniqueEntity('email')]
  23. #[ORM\HasLifecycleCallbacks]
  24. #[ORM\Table(name: 'users')]
  25. class User implements UserInterface
  26. {
  27. #[ORM\Id]
  28. #[ORM\GeneratedValue(strategy: 'AUTO')]
  29. #[ORM\Column(type: 'integer')]
  30. #[Groups(['assistant:read'])]
  31. private ?int $id = null;
  32. #[ORM\Column(name: 'picture', type: 'string', length: 255, nullable: true)]
  33. private ?string $picture = null;
  34. #[ORM\Column(name: 'signature', type: 'string', length: 255, nullable: true)]
  35. private ?string $signature = null;
  36. #[ORM\Column(name: 'username', type: 'string', length: 255, unique: true)]
  37. #[Assert\NotBlank]
  38. #[Groups(['assistant:read'])]
  39. private ?string $username = null;
  40. #[ORM\Column(name: 'email', type: 'string', length: 255, unique: true)]
  41. #[Assert\NotBlank]
  42. #[Assert\Email]
  43. #[Groups(['assistant:read'])]
  44. private ?string $email = null;
  45. #[ORM\Column(name: 'password', type: 'string', length: 64)]
  46. private ?string $password = null;
  47. #[ORM\Column(name: 'movil_password', type: 'string', length: 255, nullable: true)]
  48. private ?string $movilPassword = null;
  49. #[ORM\Column(name: 'pass_gmail', type: 'string', length: 100, nullable: true)]
  50. private ?string $passGmail = null;
  51. #[ORM\Column(name: 'firm_gmail', type: 'text', nullable: true)]
  52. private ?string $firmGmail = null;
  53. #[ORM\Column(name: 'name', type: 'string', length: 255)]
  54. #[Assert\NotBlank]
  55. #[Groups(['assistant:read'])]
  56. private ?string $name = null;
  57. #[ORM\Column(name: 'last_name', type: 'string', length: 255)]
  58. #[Assert\NotBlank]
  59. #[Groups(['assistant:read'])]
  60. private ?string $lastname = null;
  61. #[ORM\Column(name: 'telephone', type: 'string', length: 255, nullable: true)]
  62. private ?string $telephone = null;
  63. #[ORM\Column(name: 'mobile', type: 'string', length: 255, nullable: true)]
  64. private ?string $mobile = null;
  65. #[ORM\ManyToOne(targetEntity: \App\Entity\SettingsOffice::class)]
  66. #[ORM\JoinColumn(name: 'id_office', referencedColumnName: 'id', nullable: true)]
  67. private ?SettingsOffice $office = null;
  68. #[ORM\Column(name: 'status', type: 'boolean')]
  69. private ?bool $status = null;
  70. #[ORM\ManyToOne(targetEntity: \App\Entity\SettingsCompany::class)]
  71. #[ORM\JoinColumn(name: 'id_company', referencedColumnName: 'id', nullable: true)]
  72. private ?SettingsCompany $company = null;
  73. /**
  74. * Relación ManyToOne con SettingsRol usando la misma columna id_user_rol.
  75. */
  76. #[ORM\ManyToOne(targetEntity: SettingsRol::class)]
  77. #[ORM\JoinColumn(name: 'id_user_rol', referencedColumnName: 'id', nullable: true)]
  78. private ?SettingsRol $settingsRol = null;
  79. /**
  80. * Cambiamos de integer a ManyToOne para que Doctrine sepa qué es un equipo
  81. */
  82. #[ORM\ManyToOne(targetEntity: SettingsTeam::class)]
  83. #[ORM\JoinColumn(name: 'id_team', referencedColumnName: 'id', nullable: true)]
  84. private ?SettingsTeam $team = null;
  85. #[ORM\Column(name: 'team_leader', type: 'boolean', nullable: true)]
  86. private ?bool $teamleader = null;
  87. #[ORM\Column(name: 'role', type: 'string', length: 50)]
  88. private ?string $role = null;
  89. #[ORM\Column(type: 'string', length: 255, nullable: true)]
  90. private ?string $accessKey = null;
  91. #[ORM\Column(name: 'language', type: 'string', length: 11, nullable: true)]
  92. private ?string $language = null;
  93. #[ORM\Column(name: 'color', type: 'string', length: 11, nullable: true)]
  94. private ?string $color = null;
  95. #[ORM\Column(name: 'sidebar', type: 'boolean', nullable: true)]
  96. private ?bool $sidebar = null;
  97. #[ORM\Column(name: 'created_at', type: 'datetime')]
  98. private ?\DateTime $createdAt = null;
  99. #[ORM\Column(name: 'updated_at', type: 'datetime')]
  100. private ?\DateTime $updatedAt = null;
  101. #[ORM\Column(name: 'description', type: 'text', nullable: true)]
  102. private ?string $description = null;
  103. #[ORM\Column(name: 'job_title', type: 'string', length: 255, nullable: true)]
  104. private ?string $jobTitle = null;
  105. #[ORM\OneToMany(targetEntity: UserNotification::class, mappedBy: 'user', orphanRemoval: true)]
  106. private Collection $userNotifications;
  107. /**
  108. * Nueva relación ManyToMany con ManteApp
  109. */
  110. #[ORM\ManyToMany(targetEntity: ManteApp::class)]
  111. #[ORM\JoinTable(name: 'user_mante_app')]
  112. private Collection $apps;
  113. #[ORM\Column(type: 'string', length: 255, nullable: true)]
  114. private ?string $resetToken = null;
  115. public function __construct()
  116. {
  117. $this->userNotifications = new ArrayCollection();
  118. $this->apps = new ArrayCollection();
  119. }
  120. public function getId(): ?int
  121. {
  122. return $this->id;
  123. }
  124. public function setId(int $id): self
  125. {
  126. $this->id = $id;
  127. return $this;
  128. }
  129. public function getEmail(): ?string
  130. {
  131. return $this->email;
  132. }
  133. public function setEmail(string $email): self
  134. {
  135. $this->email = $email;
  136. return $this;
  137. }
  138. // 1. NUEVO MÉTODO OBLIGATORIO: El identificador único (email o username)
  139. public function getUserIdentifier(): string
  140. {
  141. return (string) $this->email; // O $this->username, lo que uses para loguearte
  142. }
  143. // 2. MANTENER POR COMPATIBILIDAD (Pero actualizarlo)
  144. /**
  145. * @deprecated since Symfony 5.3, use getUserIdentifier instead
  146. */
  147. public function getUsername(): string
  148. {
  149. return $this->getUserIdentifier();
  150. }
  151. public function setUsername(string $username): self
  152. {
  153. $this->username = $username;
  154. return $this;
  155. }
  156. public function getPassword(): ?string
  157. {
  158. return $this->password;
  159. }
  160. public function setPassword(string $password): self
  161. {
  162. $this->password = $password;
  163. return $this;
  164. }
  165. public function getSalt(): ?string
  166. {
  167. // bcrypt no requiere salt separado.
  168. return null;
  169. }
  170. public function eraseCredentials(): void
  171. {
  172. }
  173. public function getRole(): ?string
  174. {
  175. return $this->role;
  176. }
  177. public function setRole(?string $role = null): self
  178. {
  179. $this->role = $role;
  180. return $this;
  181. }
  182. public function getRoles(): array
  183. {
  184. return [$this->getRole()];
  185. }
  186. public function getAccessKey(): ?string
  187. {
  188. return $this->accessKey;
  189. }
  190. public function setAccessKey(?string $accessKey = null): self
  191. {
  192. $this->accessKey = $accessKey;
  193. return $this;
  194. }
  195. public function setCreatedAt(\DateTime $createdAt): self
  196. {
  197. $this->createdAt = $createdAt;
  198. return $this;
  199. }
  200. public function getCreatedAt(): ?\DateTime
  201. {
  202. return $this->createdAt;
  203. }
  204. public function setUpdatedAt(\DateTime $updatedAt): self
  205. {
  206. $this->updatedAt = $updatedAt;
  207. return $this;
  208. }
  209. public function getUpdatedAt(): ?\DateTime
  210. {
  211. return $this->updatedAt;
  212. }
  213. #[ORM\PrePersist]
  214. public function setCreatedAtValue(): void
  215. {
  216. $this->createdAt = new \DateTime();
  217. }
  218. #[ORM\PrePersist]
  219. #[ORM\PreUpdate]
  220. public function setUpdatedAtValue(): void
  221. {
  222. $this->updatedAt = new \DateTime();
  223. }
  224. public function setPicture(?string $picture): self
  225. {
  226. $this->picture = $picture;
  227. return $this;
  228. }
  229. public function getPicture(): ?string
  230. {
  231. return $this->picture;
  232. }
  233. public function setName(string $name): self
  234. {
  235. $this->name = $name;
  236. return $this;
  237. }
  238. public function getName(): ?string
  239. {
  240. return $this->name;
  241. }
  242. public function setLastname(string $lastname): self
  243. {
  244. $this->lastname = $lastname;
  245. return $this;
  246. }
  247. public function getLastname(): ?string
  248. {
  249. return $this->lastname;
  250. }
  251. public function setTelephone(?string $telephone): self
  252. {
  253. $this->telephone = $telephone;
  254. return $this;
  255. }
  256. public function getTelephone(): ?string
  257. {
  258. return $this->telephone;
  259. }
  260. public function setMobile(?string $mobile): self
  261. {
  262. $this->mobile = $mobile;
  263. return $this;
  264. }
  265. public function getMobile(): ?string
  266. {
  267. return $this->mobile;
  268. }
  269. public function setOffice(?SettingsOffice $office): self
  270. {
  271. $this->office = $office;
  272. return $this;
  273. }
  274. public function getOffice(): ?SettingsOffice
  275. {
  276. return $this->office;
  277. }
  278. public function setStatus(bool $status): self
  279. {
  280. $this->status = $status;
  281. return $this;
  282. }
  283. public function getStatus(): ?bool
  284. {
  285. return $this->status;
  286. }
  287. public function setCompany(?SettingsCompany $company): self
  288. {
  289. $this->company = $company;
  290. return $this;
  291. }
  292. public function getCompany(): ?SettingsCompany
  293. {
  294. return $this->company;
  295. }
  296. /**
  297. * Setter “antiguo” para el id de rol.
  298. * No afecta a Doctrine.
  299. */
  300. public function setUserrol(?SettingsRol $userrol): self
  301. {
  302. // CAMBIO: Antes decía $this->userrol, ahora $this->settingsRol
  303. $this->settingsRol = $userrol;
  304. return $this;
  305. }
  306. /**
  307. * Devuelve el id del SettingsRol si existe; si no, el valor crudo.
  308. */
  309. public function getUserrol(): ?SettingsRol
  310. {
  311. // CAMBIO: Antes decía $this->userrol, ahora $this->settingsRol
  312. return $this->settingsRol;
  313. }
  314. public function setTeam(?SettingsTeam $team): self
  315. {
  316. $this->team = $team;
  317. return $this;
  318. }
  319. public function getTeam(): ?SettingsTeam
  320. {
  321. return $this->team;
  322. }
  323. public function setTeamleader(?bool $teamleader): self
  324. {
  325. $this->teamleader = $teamleader;
  326. return $this;
  327. }
  328. public function getTeamleader(): ?bool
  329. {
  330. return $this->teamleader;
  331. }
  332. public function setLanguage(?string $language): self
  333. {
  334. $this->language = $language;
  335. return $this;
  336. }
  337. public function getLanguage(): ?string
  338. {
  339. return $this->language;
  340. }
  341. public function setPassGmail(?string $passGmail): self
  342. {
  343. $this->passGmail = $passGmail;
  344. return $this;
  345. }
  346. public function getPassGmail(): ?string
  347. {
  348. return $this->passGmail;
  349. }
  350. public function setFirmGmail(?string $firmGmail): self
  351. {
  352. $this->firmGmail = $firmGmail;
  353. return $this;
  354. }
  355. public function getFirmGmail(): ?string
  356. {
  357. return $this->firmGmail;
  358. }
  359. public function setColor(?string $color): self
  360. {
  361. $this->color = $color;
  362. return $this;
  363. }
  364. public function getColor(): ?string
  365. {
  366. return $this->color;
  367. }
  368. public function setSidebar(?bool $sidebar): self
  369. {
  370. $this->sidebar = $sidebar;
  371. return $this;
  372. }
  373. public function getSidebar(): ?bool
  374. {
  375. return $this->sidebar;
  376. }
  377. public function setDescription(?string $description): self
  378. {
  379. $this->description = $description;
  380. return $this;
  381. }
  382. public function getDescription(): ?string
  383. {
  384. return $this->description;
  385. }
  386. public function setJobTitle(?string $jobTitle): self
  387. {
  388. $this->jobTitle = $jobTitle;
  389. return $this;
  390. }
  391. public function getJobTitle(): ?string
  392. {
  393. return $this->jobTitle;
  394. }
  395. /**
  396. * Obtiene el nombre completo.
  397. * Al ser campos obligatorios (@Assert\NotBlank), no necesitamos comprobaciones extra.
  398. */
  399. public function getFullName(): string
  400. {
  401. return "{$this->name} {$this->lastname}";
  402. }
  403. public function setMovilPassword(?string $movilPassword): self
  404. {
  405. $this->movilPassword = $movilPassword;
  406. return $this;
  407. }
  408. public function getMovilPassword(): ?string
  409. {
  410. return $this->movilPassword;
  411. }
  412. /**
  413. * Relación ManyToOne con SettingsRol
  414. */
  415. public function getSettingsRol(): ?SettingsRol
  416. {
  417. return $this->settingsRol;
  418. }
  419. public function setSettingsRol(?SettingsRol $settingsRol): self
  420. {
  421. $this->settingsRol = $settingsRol;
  422. return $this;
  423. }
  424. /**
  425. * @return Collection<int, UserNotification>
  426. */
  427. public function getUserNotifications(): Collection
  428. {
  429. return $this->userNotifications;
  430. }
  431. public function addUserNotification(UserNotification $userNotification): self
  432. {
  433. if (!$this->userNotifications->contains($userNotification)) {
  434. $this->userNotifications[] = $userNotification;
  435. $userNotification->setUser($this);
  436. }
  437. return $this;
  438. }
  439. public function removeUserNotification(UserNotification $userNotification): self
  440. {
  441. if ($this->userNotifications->removeElement($userNotification)) {
  442. if ($userNotification->getUser() === $this) {
  443. $userNotification->setUser(null); // This might need adjustment if setUser expects User, passing null might arguably be allowed if property is nullable, checking that...
  444. // Checking previous code: $userNotification->setUser(null);
  445. // We should check UserNotification definition, but for now assuming it accepts null or we will fix it later.
  446. // However, UserNotification::setUser typically expects User or null. Let's assume nullable for now or we check if UserNotification allows null.
  447. // Re-reading original User.php:200 mappedBy="user".
  448. // In UserNotification.php (not visible, but inferred), user property likely links back.
  449. // If the relationship is mandatory, this might be an issue, but standard generated code allows nulling to break association.
  450. }
  451. }
  452. return $this;
  453. }
  454. /**
  455. * @return Collection|ManteApp[]
  456. */
  457. public function getApps(): Collection
  458. {
  459. return $this->apps;
  460. }
  461. public function addApp(ManteApp $app): self
  462. {
  463. if (!$this->apps->contains($app)) {
  464. $this->apps[] = $app;
  465. }
  466. return $this;
  467. }
  468. public function removeApp(ManteApp $app): self
  469. {
  470. if ($this->apps->contains($app)) {
  471. $this->apps->removeElement($app);
  472. }
  473. return $this;
  474. }
  475. public function __toString(): string
  476. {
  477. // Cambia 'getName()' por 'getEmail()' o 'getUsername()' si tu entidad usa otro campo para el nombre
  478. return (string) $this->getName();
  479. }
  480. public function getResetToken(): ?string
  481. {
  482. return $this->resetToken;
  483. }
  484. public function setResetToken(?string $resetToken): self
  485. {
  486. $this->resetToken = $resetToken;
  487. return $this;
  488. }
  489. public function getSignature(): ?string
  490. {
  491. return $this->signature;
  492. }
  493. public function setSignature(?string $signature): self
  494. {
  495. $this->signature = $signature;
  496. return $this;
  497. }
  498. }