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