src/Entity/User.php line 29

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