<?php
/**
* Created by Mediterranean Develup Solutions.
* User: jorge.defreitas@develup.solutions
* Date: 14/06/2017
* Time: 16:51
*/
namespace App\Entity;
use App\Entity\SettingsRol;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* User
*/
#[ORM\Entity(repositoryClass: \App\Repository\UserRepository::class)]
#[UniqueEntity('username')]
#[UniqueEntity('email')]
#[ORM\HasLifecycleCallbacks]
#[ORM\Table(name: 'users')]
class User implements UserInterface
{
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
#[ORM\Column(type: 'integer')]
#[Groups(['assistant:read'])]
private ?int $id = null;
#[ORM\Column(name: 'picture', type: 'string', length: 255, nullable: true)]
private ?string $picture = null;
#[ORM\Column(name: 'signature', type: 'string', length: 255, nullable: true)]
private ?string $signature = null;
#[ORM\Column(name: 'username', type: 'string', length: 255, unique: true)]
#[Assert\NotBlank]
#[Groups(['assistant:read'])]
private ?string $username = null;
#[ORM\Column(name: 'email', type: 'string', length: 255, unique: true)]
#[Assert\NotBlank]
#[Assert\Email]
#[Groups(['assistant:read'])]
private ?string $email = null;
#[ORM\Column(name: 'password', type: 'string', length: 64)]
private ?string $password = null;
#[ORM\Column(name: 'movil_password', type: 'string', length: 255, nullable: true)]
private ?string $movilPassword = null;
#[ORM\Column(name: 'pass_gmail', type: 'string', length: 100, nullable: true)]
private ?string $passGmail = null;
#[ORM\Column(name: 'firm_gmail', type: 'text', nullable: true)]
private ?string $firmGmail = null;
#[ORM\Column(name: 'name', type: 'string', length: 255)]
#[Assert\NotBlank]
#[Groups(['assistant:read'])]
private ?string $name = null;
#[ORM\Column(name: 'last_name', type: 'string', length: 255)]
#[Assert\NotBlank]
#[Groups(['assistant:read'])]
private ?string $lastname = null;
#[ORM\Column(name: 'telephone', type: 'string', length: 255, nullable: true)]
private ?string $telephone = null;
#[ORM\Column(name: 'mobile', type: 'string', length: 255, nullable: true)]
private ?string $mobile = null;
#[ORM\ManyToOne(targetEntity: \App\Entity\SettingsOffice::class)]
#[ORM\JoinColumn(name: 'id_office', referencedColumnName: 'id', nullable: true)]
private ?SettingsOffice $office = null;
#[ORM\Column(name: 'status', type: 'boolean')]
private ?bool $status = null;
#[ORM\ManyToOne(targetEntity: \App\Entity\SettingsCompany::class)]
#[ORM\JoinColumn(name: 'id_company', referencedColumnName: 'id', nullable: true)]
private ?SettingsCompany $company = null;
/**
* Relación ManyToOne con SettingsRol usando la misma columna id_user_rol.
*/
#[ORM\ManyToOne(targetEntity: SettingsRol::class)]
#[ORM\JoinColumn(name: 'id_user_rol', referencedColumnName: 'id', nullable: true)]
private ?SettingsRol $settingsRol = null;
/**
* Cambiamos de integer a ManyToOne para que Doctrine sepa qué es un equipo
*/
#[ORM\ManyToOne(targetEntity: SettingsTeam::class)]
#[ORM\JoinColumn(name: 'id_team', referencedColumnName: 'id', nullable: true)]
private ?SettingsTeam $team = null;
#[ORM\Column(name: 'team_leader', type: 'boolean', nullable: true)]
private ?bool $teamleader = null;
#[ORM\Column(name: 'role', type: 'string', length: 50)]
private ?string $role = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $accessKey = null;
#[ORM\Column(name: 'language', type: 'string', length: 11, nullable: true)]
private ?string $language = null;
#[ORM\Column(name: 'color', type: 'string', length: 11, nullable: true)]
private ?string $color = null;
#[ORM\Column(name: 'sidebar', type: 'boolean', nullable: true)]
private ?bool $sidebar = null;
#[ORM\Column(name: 'created_at', type: 'datetime')]
private ?\DateTime $createdAt = null;
#[ORM\Column(name: 'updated_at', type: 'datetime')]
private ?\DateTime $updatedAt = null;
#[ORM\Column(name: 'description', type: 'text', nullable: true)]
private ?string $description = null;
#[ORM\Column(name: 'job_title', type: 'string', length: 255, nullable: true)]
private ?string $jobTitle = null;
#[ORM\OneToMany(targetEntity: UserNotification::class, mappedBy: 'user', orphanRemoval: true)]
private Collection $userNotifications;
/**
* Nueva relación ManyToMany con ManteApp
*/
#[ORM\ManyToMany(targetEntity: ManteApp::class)]
#[ORM\JoinTable(name: 'user_mante_app')]
private Collection $apps;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $resetToken = null;
public function __construct()
{
$this->userNotifications = new ArrayCollection();
$this->apps = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function setId(int $id): self
{
$this->id = $id;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
// 1. NUEVO MÉTODO OBLIGATORIO: El identificador único (email o username)
public function getUserIdentifier(): string
{
return (string) $this->email; // O $this->username, lo que uses para loguearte
}
// 2. MANTENER POR COMPATIBILIDAD (Pero actualizarlo)
/**
* @deprecated since Symfony 5.3, use getUserIdentifier instead
*/
public function getUsername(): string
{
return $this->getUserIdentifier();
}
public function setUsername(string $username): self
{
$this->username = $username;
return $this;
}
public function getPassword(): ?string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
public function getSalt(): ?string
{
// bcrypt no requiere salt separado.
return null;
}
public function eraseCredentials(): void
{
}
public function getRole(): ?string
{
return $this->role;
}
public function setRole(?string $role = null): self
{
$this->role = $role;
return $this;
}
public function getRoles(): array
{
return [$this->getRole()];
}
public function getAccessKey(): ?string
{
return $this->accessKey;
}
public function setAccessKey(?string $accessKey = null): self
{
$this->accessKey = $accessKey;
return $this;
}
public function setCreatedAt(\DateTime $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getCreatedAt(): ?\DateTime
{
return $this->createdAt;
}
public function setUpdatedAt(\DateTime $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getUpdatedAt(): ?\DateTime
{
return $this->updatedAt;
}
#[ORM\PrePersist]
public function setCreatedAtValue(): void
{
$this->createdAt = new \DateTime();
}
#[ORM\PrePersist]
#[ORM\PreUpdate]
public function setUpdatedAtValue(): void
{
$this->updatedAt = new \DateTime();
}
public function setPicture(?string $picture): self
{
$this->picture = $picture;
return $this;
}
public function getPicture(): ?string
{
return $this->picture;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setLastname(string $lastname): self
{
$this->lastname = $lastname;
return $this;
}
public function getLastname(): ?string
{
return $this->lastname;
}
public function setTelephone(?string $telephone): self
{
$this->telephone = $telephone;
return $this;
}
public function getTelephone(): ?string
{
return $this->telephone;
}
public function setMobile(?string $mobile): self
{
$this->mobile = $mobile;
return $this;
}
public function getMobile(): ?string
{
return $this->mobile;
}
public function setOffice(?SettingsOffice $office): self
{
$this->office = $office;
return $this;
}
public function getOffice(): ?SettingsOffice
{
return $this->office;
}
public function setStatus(bool $status): self
{
$this->status = $status;
return $this;
}
public function getStatus(): ?bool
{
return $this->status;
}
public function setCompany(?SettingsCompany $company): self
{
$this->company = $company;
return $this;
}
public function getCompany(): ?SettingsCompany
{
return $this->company;
}
/**
* Setter “antiguo” para el id de rol.
* No afecta a Doctrine.
*/
public function setUserrol(?SettingsRol $userrol): self
{
// CAMBIO: Antes decía $this->userrol, ahora $this->settingsRol
$this->settingsRol = $userrol;
return $this;
}
/**
* Devuelve el id del SettingsRol si existe; si no, el valor crudo.
*/
public function getUserrol(): ?SettingsRol
{
// CAMBIO: Antes decía $this->userrol, ahora $this->settingsRol
return $this->settingsRol;
}
public function setTeam(?SettingsTeam $team): self
{
$this->team = $team;
return $this;
}
public function getTeam(): ?SettingsTeam
{
return $this->team;
}
public function setTeamleader(?bool $teamleader): self
{
$this->teamleader = $teamleader;
return $this;
}
public function getTeamleader(): ?bool
{
return $this->teamleader;
}
public function setLanguage(?string $language): self
{
$this->language = $language;
return $this;
}
public function getLanguage(): ?string
{
return $this->language;
}
public function setPassGmail(?string $passGmail): self
{
$this->passGmail = $passGmail;
return $this;
}
public function getPassGmail(): ?string
{
return $this->passGmail;
}
public function setFirmGmail(?string $firmGmail): self
{
$this->firmGmail = $firmGmail;
return $this;
}
public function getFirmGmail(): ?string
{
return $this->firmGmail;
}
public function setColor(?string $color): self
{
$this->color = $color;
return $this;
}
public function getColor(): ?string
{
return $this->color;
}
public function setSidebar(?bool $sidebar): self
{
$this->sidebar = $sidebar;
return $this;
}
public function getSidebar(): ?bool
{
return $this->sidebar;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setJobTitle(?string $jobTitle): self
{
$this->jobTitle = $jobTitle;
return $this;
}
public function getJobTitle(): ?string
{
return $this->jobTitle;
}
/**
* Obtiene el nombre completo.
* Al ser campos obligatorios (@Assert\NotBlank), no necesitamos comprobaciones extra.
*/
public function getFullName(): string
{
return "{$this->name} {$this->lastname}";
}
public function setMovilPassword(?string $movilPassword): self
{
$this->movilPassword = $movilPassword;
return $this;
}
public function getMovilPassword(): ?string
{
return $this->movilPassword;
}
/**
* Relación ManyToOne con SettingsRol
*/
public function getSettingsRol(): ?SettingsRol
{
return $this->settingsRol;
}
public function setSettingsRol(?SettingsRol $settingsRol): self
{
$this->settingsRol = $settingsRol;
return $this;
}
/**
* @return Collection<int, UserNotification>
*/
public function getUserNotifications(): Collection
{
return $this->userNotifications;
}
public function addUserNotification(UserNotification $userNotification): self
{
if (!$this->userNotifications->contains($userNotification)) {
$this->userNotifications[] = $userNotification;
$userNotification->setUser($this);
}
return $this;
}
public function removeUserNotification(UserNotification $userNotification): self
{
if ($this->userNotifications->removeElement($userNotification)) {
if ($userNotification->getUser() === $this) {
$userNotification->setUser(null); // This might need adjustment if setUser expects User, passing null might arguably be allowed if property is nullable, checking that...
// Checking previous code: $userNotification->setUser(null);
// We should check UserNotification definition, but for now assuming it accepts null or we will fix it later.
// However, UserNotification::setUser typically expects User or null. Let's assume nullable for now or we check if UserNotification allows null.
// Re-reading original User.php:200 mappedBy="user".
// In UserNotification.php (not visible, but inferred), user property likely links back.
// If the relationship is mandatory, this might be an issue, but standard generated code allows nulling to break association.
}
}
return $this;
}
/**
* @return Collection|ManteApp[]
*/
public function getApps(): Collection
{
return $this->apps;
}
public function addApp(ManteApp $app): self
{
if (!$this->apps->contains($app)) {
$this->apps[] = $app;
}
return $this;
}
public function removeApp(ManteApp $app): self
{
if ($this->apps->contains($app)) {
$this->apps->removeElement($app);
}
return $this;
}
public function __toString(): string
{
// Cambia 'getName()' por 'getEmail()' o 'getUsername()' si tu entidad usa otro campo para el nombre
return (string) $this->getName();
}
public function getResetToken(): ?string
{
return $this->resetToken;
}
public function setResetToken(?string $resetToken): self
{
$this->resetToken = $resetToken;
return $this;
}
public function getSignature(): ?string
{
return $this->signature;
}
public function setSignature(?string $signature): self
{
$this->signature = $signature;
return $this;
}
}