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.     public function __construct()
  172.     {
  173.         $this->userNotifications = new ArrayCollection();
  174.         $this->apps = new ArrayCollection();
  175.     }
  176.     public function getId(): ?int
  177.     {
  178.         return $this->id;
  179.     }
  180.     public function setId(int $id): self
  181.     {
  182.         $this->id $id;
  183.         return $this;
  184.     }
  185.     public function getEmail(): ?string
  186.     {
  187.         return $this->email;
  188.     }
  189.     public function setEmail(string $email): self
  190.     {
  191.         $this->email $email;
  192.         return $this;
  193.     }
  194.     // 1. NUEVO MÉTODO OBLIGATORIO: El identificador único (email o username)
  195.     public function getUserIdentifier(): string
  196.     {
  197.         return (string) $this->email// O $this->username, lo que uses para loguearte
  198.     }
  199.     // 2. MANTENER POR COMPATIBILIDAD (Pero actualizarlo)
  200.     /**
  201.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  202.      */
  203.     public function getUsername(): string
  204.     {
  205.         return $this->getUserIdentifier();
  206.     }
  207.     public function setUsername(string $username): self
  208.     {
  209.         $this->username $username;
  210.         return $this;
  211.     }
  212.     public function getPassword(): ?string
  213.     {
  214.         return $this->password;
  215.     }
  216.     public function setPassword(string $password): self
  217.     {
  218.         $this->password $password;
  219.         return $this;
  220.     }
  221.     public function getSalt(): ?string
  222.     {
  223.         // bcrypt no requiere salt separado.
  224.         return null;
  225.     }
  226.     public function eraseCredentials(): void
  227.     {
  228.     }
  229.     public function getRole(): ?string
  230.     {
  231.         return $this->role;
  232.     }
  233.     public function setRole(?string $role null): self
  234.     {
  235.         $this->role $role;
  236.         return $this;
  237.     }
  238.     public function getRoles(): array
  239.     {
  240.         return [$this->getRole()];
  241.     }
  242.     public function getAccessKey(): ?string
  243.     {
  244.         return $this->accessKey;
  245.     }
  246.     public function setAccessKey(?string $accessKey null): self
  247.     {
  248.         $this->accessKey $accessKey;
  249.         return $this;
  250.     }
  251.     public function setCreatedAt(\DateTime $createdAt): self
  252.     {
  253.         $this->createdAt $createdAt;
  254.         return $this;
  255.     }
  256.     public function getCreatedAt(): ?\DateTime
  257.     {
  258.         return $this->createdAt;
  259.     }
  260.     public function setUpdatedAt(\DateTime $updatedAt): self
  261.     {
  262.         $this->updatedAt $updatedAt;
  263.         return $this;
  264.     }
  265.     public function getUpdatedAt(): ?\DateTime
  266.     {
  267.         return $this->updatedAt;
  268.     }
  269.     /**
  270.      * @ORM\PrePersist
  271.      */
  272.     public function setCreatedAtValue(): void
  273.     {
  274.         $this->createdAt = new \DateTime();
  275.     }
  276.     /**
  277.      * @ORM\PrePersist
  278.      * @ORM\PreUpdate
  279.      */
  280.     public function setUpdatedAtValue(): void
  281.     {
  282.         $this->updatedAt = new \DateTime();
  283.     }
  284.     public function setPicture(?string $picture): self
  285.     {
  286.         $this->picture $picture;
  287.         return $this;
  288.     }
  289.     public function getPicture(): ?string
  290.     {
  291.         return $this->picture;
  292.     }
  293.     public function setName(string $name): self
  294.     {
  295.         $this->name $name;
  296.         return $this;
  297.     }
  298.     public function getName(): ?string
  299.     {
  300.         return $this->name;
  301.     }
  302.     public function setLastname(string $lastname): self
  303.     {
  304.         $this->lastname $lastname;
  305.         return $this;
  306.     }
  307.     public function getLastname(): ?string
  308.     {
  309.         return $this->lastname;
  310.     }
  311.     public function setTelephone(?string $telephone): self
  312.     {
  313.         $this->telephone $telephone;
  314.         return $this;
  315.     }
  316.     public function getTelephone(): ?string
  317.     {
  318.         return $this->telephone;
  319.     }
  320.     public function setMobile(?string $mobile): self
  321.     {
  322.         $this->mobile $mobile;
  323.         return $this;
  324.     }
  325.     public function getMobile(): ?string
  326.     {
  327.         return $this->mobile;
  328.     }
  329.     public function setOffice(?SettingsOffice $office): self
  330.     {
  331.         $this->office $office;
  332.         return $this;
  333.     }
  334.     public function getOffice(): ?SettingsOffice
  335.     {
  336.         return $this->office;
  337.     }
  338.     public function setStatus(bool $status): self
  339.     {
  340.         $this->status $status;
  341.         return $this;
  342.     }
  343.     public function getStatus(): ?bool
  344.     {
  345.         return $this->status;
  346.     }
  347.     public function setCompany(?SettingsCompany $company): self
  348.     {
  349.         $this->company $company;
  350.         return $this;
  351.     }
  352.     public function getCompany(): ?SettingsCompany
  353.     {
  354.         return $this->company;
  355.     }
  356.     /**
  357.      * Setter “antiguo” para el id de rol.
  358.      * No afecta a Doctrine.
  359.      */
  360.     public function setUserrol(?SettingsRol $userrol): self
  361.     {
  362.         // CAMBIO: Antes decía $this->userrol, ahora $this->settingsRol
  363.         $this->settingsRol $userrol;
  364.         return $this;
  365.     }
  366.     /**
  367.      * Devuelve el id del SettingsRol si existe; si no, el valor crudo.
  368.      */
  369.     public function getUserrol(): ?SettingsRol
  370.     {
  371.         // CAMBIO: Antes decía $this->userrol, ahora $this->settingsRol
  372.         return $this->settingsRol;
  373.     }
  374.     public function setTeam(?SettingsTeam $team): self
  375.     {
  376.         $this->team $team;
  377.         return $this;
  378.     }
  379.     public function getTeam(): ?SettingsTeam
  380.     {
  381.         return $this->team;
  382.     }
  383.     public function setTeamleader(?bool $teamleader): self
  384.     {
  385.         $this->teamleader $teamleader;
  386.         return $this;
  387.     }
  388.     public function getTeamleader(): ?bool
  389.     {
  390.         return $this->teamleader;
  391.     }
  392.     public function setLanguage(?string $language): self
  393.     {
  394.         $this->language $language;
  395.         return $this;
  396.     }
  397.     public function getLanguage(): ?string
  398.     {
  399.         return $this->language;
  400.     }
  401.     public function setPassGmail(?string $passGmail): self
  402.     {
  403.         $this->passGmail $passGmail;
  404.         return $this;
  405.     }
  406.     public function getPassGmail(): ?string
  407.     {
  408.         return $this->passGmail;
  409.     }
  410.     public function setFirmGmail(?string $firmGmail): self
  411.     {
  412.         $this->firmGmail $firmGmail;
  413.         return $this;
  414.     }
  415.     public function getFirmGmail(): ?string
  416.     {
  417.         return $this->firmGmail;
  418.     }
  419.     public function setColor(?string $color): self
  420.     {
  421.         $this->color $color;
  422.         return $this;
  423.     }
  424.     public function getColor(): ?string
  425.     {
  426.         return $this->color;
  427.     }
  428.     public function setSidebar(?bool $sidebar): self
  429.     {
  430.         $this->sidebar $sidebar;
  431.         return $this;
  432.     }
  433.     public function getSidebar(): ?bool
  434.     {
  435.         return $this->sidebar;
  436.     }
  437.     public function setDescription(?string $description): self
  438.     {
  439.         $this->description $description;
  440.         return $this;
  441.     }
  442.     public function getDescription(): ?string
  443.     {
  444.         return $this->description;
  445.     }
  446.     public function setJobTitle(?string $jobTitle): self
  447.     {
  448.         $this->jobTitle $jobTitle;
  449.         return $this;
  450.     }
  451.     public function getJobTitle(): ?string
  452.     {
  453.         return $this->jobTitle;
  454.     }
  455.     /**
  456.      * Obtiene el nombre completo.
  457.      * Al ser campos obligatorios (@Assert\NotBlank), no necesitamos comprobaciones extra.
  458.      */
  459.     public function getFullName(): string
  460.     {
  461.         return "{$this->name} {$this->lastname}";
  462.     }
  463.     public function setMovilPassword(?string $movilPassword): self
  464.     {
  465.         $this->movilPassword $movilPassword;
  466.         return $this;
  467.     }
  468.     public function getMovilPassword(): ?string
  469.     {
  470.         return $this->movilPassword;
  471.     }
  472.     /**
  473.      * Relación ManyToOne con SettingsRol
  474.      */
  475.     public function getSettingsRol(): ?SettingsRol
  476.     {
  477.         return $this->settingsRol;
  478.     }
  479.     public function setSettingsRol(?SettingsRol $settingsRol): self
  480.     {
  481.         $this->settingsRol $settingsRol;
  482.         return $this;
  483.     }
  484.     /**
  485.      * @return Collection<int, UserNotification>
  486.      */
  487.     public function getUserNotifications(): Collection
  488.     {
  489.         return $this->userNotifications;
  490.     }
  491.     public function addUserNotification(UserNotification $userNotification): self
  492.     {
  493.         if (!$this->userNotifications->contains($userNotification)) {
  494.             $this->userNotifications[] = $userNotification;
  495.             $userNotification->setUser($this);
  496.         }
  497.         return $this;
  498.     }
  499.     public function removeUserNotification(UserNotification $userNotification): self
  500.     {
  501.         if ($this->userNotifications->removeElement($userNotification)) {
  502.             if ($userNotification->getUser() === $this) {
  503.                 $userNotification->setUser(null); // This might need adjustment if setUser expects User, passing null might arguably be allowed if property is nullable, checking that...
  504.                 // Checking previous code: $userNotification->setUser(null);
  505.                 // We should check UserNotification definition, but for now assuming it accepts null or we will fix it later. 
  506.                 // However, UserNotification::setUser typically expects User or null. Let's assume nullable for now or we check if UserNotification allows null.
  507.                 // Re-reading original User.php:200 mappedBy="user".
  508.                 // In UserNotification.php (not visible, but inferred), user property likely links back.
  509.                 // If the relationship is mandatory, this might be an issue, but standard generated code allows nulling to break association.
  510.             }
  511.         }
  512.         return $this;
  513.     }
  514.     /**
  515.      * @return Collection|ManteApp[]
  516.      */
  517.     public function getApps(): Collection
  518.     {
  519.         return $this->apps;
  520.     }
  521.     public function addApp(ManteApp $app): self
  522.     {
  523.         if (!$this->apps->contains($app)) {
  524.             $this->apps[] = $app;
  525.         }
  526.         return $this;
  527.     }
  528.     public function removeApp(ManteApp $app): self
  529.     {
  530.         if ($this->apps->contains($app)) {
  531.             $this->apps->removeElement($app);
  532.         }
  533.         return $this;
  534.     }
  535. }