src/Entity/User.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. /**
  11.  * @ORM\Entity(repositoryClass=UserRepository::class)
  12.  * @UniqueEntity(fields={"email"}, message="There is already an account with this email")
  13.  * // @UniqueEntity(fields={"dni"}, message="There is already an account with this dni")
  14.  */
  15. class User implements UserInterfacePasswordAuthenticatedUserInterface
  16. {
  17.     /** @var Array List of available roles for users. Used on forms of user */
  18.     private const ROLES_AVAILABLE = [
  19.         'user' => 'USER',
  20.         'office' => 'OFFICE',
  21.         'admin' => 'ADMIN',
  22.     ];
  23.     // public const PRUEBA_NUMEROS = [
  24.     //     'Prueba [cod]' => "1a",
  25.     //     'Pruebaa' => "2",
  26.     //     'Pruebaaa' => "3",
  27.     //     'Pruebaaaa' => "4",
  28.     // ];
  29.     /**
  30.      * @ORM\Id
  31.      * @ORM\GeneratedValue
  32.      * @ORM\Column(type="integer")
  33.      */
  34.     private $id;
  35.     /**
  36.      * @var string
  37.      *
  38.      * @ORM\Column(name="name", type="string", length=50, nullable=true)
  39.      */
  40.     private $name '';
  41.     /**
  42.      * @var string
  43.      *
  44.      * @ORM\Column(name="surname", type="string", length=100, nullable=true)
  45.      */
  46.     private $surname '';
  47.     /**
  48.      * @ORM\Column(type="string", length=180, unique=true)
  49.      */
  50.     private $email;
  51.     /**
  52.      * @var string
  53.      *
  54.      * @ORM\Column(name="hash_aux", type="string", length=100, nullable=true)
  55.      */
  56.     private $hashAux;
  57.     /**
  58.      * @ORM\Column(type="json")
  59.      */
  60.     private $roles = [];
  61.     /**
  62.      * @ORM\Column(type="string", length=10, nullable=true)
  63.      */
  64.     private $role_bank;
  65.     /**
  66.      * @var string The hashed password
  67.      * @ORM\Column(type="string")
  68.      */
  69.     private $password;
  70.     /**
  71.      * @var int
  72.      *
  73.      * @ORM\Column(name="active", type="integer", nullable=false)
  74.      */
  75.     private $active '0';
  76.     /**
  77.      * @ORM\Column(type="boolean")
  78.      */
  79.     private $isVerified false;
  80.     /**
  81.      * @ORM\Column(type="boolean")
  82.      */
  83.     private $isBanned false;
  84.     /**
  85.      * @var string
  86.      * @ORM\Column(type="string", nullable=false, unique=true)
  87.      */
  88.     private $dni;
  89.     /**
  90.      * @var string
  91.      * @ORM\Column(type="string", nullable=true)
  92.      */
  93.     private $telephone;
  94.     /**
  95.      * @var string
  96.      * @ORM\Column(type="string", nullable=true)
  97.      */
  98.     private $address;
  99.     /**
  100.      * @var string
  101.      * @ORM\Column(type="string", nullable=true)
  102.      */
  103.     private $city;
  104.     /**
  105.      * @var string
  106.      * @ORM\Column(type="string", nullable=true)
  107.      */
  108.     private $province;
  109.     /**
  110.      * @var string
  111.      * @ORM\Column(type="string", nullable=true)
  112.      */
  113.     private $country;
  114.     /**
  115.      * @var string
  116.      * @ORM\Column(type="string", nullable=true)
  117.      */
  118.     private $zip_code;
  119.     /**
  120.      * @var string
  121.      * @ORM\Column(type="string", nullable=true)
  122.      */
  123.     private $category;
  124.     /**
  125.      * @ORM\ManyToOne(targetEntity=Institution::class, inversedBy="users")
  126.      * @ORM\JoinColumn(nullable=true)
  127.      */
  128.     private $institution;
  129.     /**
  130.      * @ORM\OneToOne(targetEntity=Ringer::class, inversedBy="user", cascade={"persist", "remove"}, fetch="EAGER")
  131.      */
  132.     private $ringer;
  133.     /**
  134.      * @ORM\OneToMany(targetEntity=GroupUser::class, mappedBy="user_id", orphanRemoval=true, fetch="EAGER")
  135.      */
  136.     private $groupUsers;
  137.     /**
  138.      * @ORM\OneToMany(targetEntity=Group::class, mappedBy="coordinator")
  139.      */
  140.     private $coordinator_groups;
  141.     /**
  142.      * @ORM\OneToMany(targetEntity=Register::class, mappedBy="user")
  143.      */
  144.     private $registers;
  145.     public function __construct()
  146.     {
  147.         $this->roles = ['ROLE_RINGER'];
  148.         $this->groupUsers = new ArrayCollection();
  149.         $this->coordinator_groups = new ArrayCollection();
  150.         $this->registers = new ArrayCollection();
  151.     }
  152.     public function __toString()
  153.     {
  154.         return $this->email;
  155.     }
  156.     public function getId(): ?int
  157.     {
  158.         return $this->id;
  159.     }
  160.     public function getName(): ?string
  161.     {
  162.         return $this->name;
  163.     }
  164.     public function setName(string $name): self
  165.     {
  166.         $this->name $name;
  167.         return $this;
  168.     }
  169.     public function getSurname(): ?string
  170.     {
  171.         return $this->surname;
  172.     }
  173.     public function setSurname(string $surname): self
  174.     {
  175.         $this->surname $surname;
  176.         return $this;
  177.     }
  178.     public function getEmail(): ?string
  179.     {
  180.         return $this->email;
  181.     }
  182.     public function setEmail(string $email): self
  183.     {
  184.         $this->email $email;
  185.         return $this;
  186.     }
  187.     public function getHashAux(): ?string
  188.     {
  189.         return $this->hashAux;
  190.     }
  191.     public function setHashAux(string $hashAux): self
  192.     {
  193.         $this->hashAux $hashAux;
  194.         return $this;
  195.     }
  196.     /**
  197.      * A visual identifier that represents this user.
  198.      *
  199.      * @see UserInterface
  200.      */
  201.     public function getUserIdentifier(): string
  202.     {
  203.         return (string) $this->email;
  204.     }
  205.     /**
  206.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  207.      */
  208.     public function getUsername(): string
  209.     {
  210.         return (string) $this->email;
  211.     }
  212.     /**
  213.      * @see UserInterface
  214.      */
  215.     public function getRoles(): array
  216.     {
  217.         $roles $this->roles;
  218.         // guarantee every user at least has ROLE_USER
  219.         $roles[] = 'ROLE_USER';
  220.         return array_unique($roles);
  221.     }
  222.     public function setRoles(array $roles): self
  223.     {
  224.         $this->roles $roles;
  225.         return $this;
  226.     }
  227.     public function getRoleBank(): string
  228.     {
  229.         return $this->role_bank;
  230.     }
  231.     public function setRoleBank(?string $role_bank): self
  232.     {
  233.         $this->role_bank $role_bank;
  234.         return $this;
  235.     }
  236.     /**
  237.      * @see PasswordAuthenticatedUserInterface
  238.      */
  239.     public function getPassword(): string
  240.     {
  241.         return $this->password;
  242.     }
  243.     public function setPassword(string $password): self
  244.     {
  245.         $this->password $password;
  246.         return $this;
  247.     }
  248.     public function getActive(): ?int
  249.     {
  250.         return $this->active;
  251.     }
  252.     public function setActive(int $active): self
  253.     {
  254.         $this->active $active;
  255.         return $this;
  256.     }
  257.     public function getDni(): string
  258.     {
  259.         return $this->dni;
  260.     }
  261.     public function setDni(string $dni): self
  262.     {
  263.         $this->dni $dni;
  264.         return $this;
  265.     }
  266.     public function getTelephone(): ?string
  267.     {
  268.         return $this->telephone;
  269.     }
  270.     public function setTelephone(string $telephone): self
  271.     {
  272.         $this->telephone $telephone;
  273.         return $this;
  274.     }
  275.     public function getAddress(): ?string
  276.     {
  277.         return $this->address;
  278.     }
  279.     public function setAddress(string $address): self
  280.     {
  281.         $this->address $address;
  282.         return $this;
  283.     }
  284.     public function getCity(): ?string
  285.     {
  286.         return $this->city;
  287.     }
  288.     public function setCity(string $city): self
  289.     {
  290.         $this->city $city;
  291.         return $this;
  292.     }
  293.     public function getProvince(): ?string
  294.     {
  295.         return $this->province;
  296.     }
  297.     public function setProvince(string $province): self
  298.     {
  299.         $this->province $province;
  300.         return $this;
  301.     }
  302.     public function getCountry(): ?string
  303.     {
  304.         return $this->country;
  305.     }
  306.     public function setCountry(string $country): self
  307.     {
  308.         $this->country $country;
  309.         return $this;
  310.     }
  311.     public function getZipcode(): ?string
  312.     {
  313.         return $this->zip_code;
  314.     }
  315.     public function setZipcode(string $zip_code): self
  316.     {
  317.         $this->zip_code $zip_code;
  318.         return $this;
  319.     }
  320.     // public function getPrueba(): string
  321.     // {
  322.     //     return $this->prueba;
  323.     // }
  324.     // public function setPrueba(string $prueba): self
  325.     // {
  326.     //     $this->prueba = $prueba;
  327.     //     return $this;
  328.     // }
  329.     public function getCategory(): ?string
  330.     {
  331.         return $this->category;
  332.     }
  333.     public function setCategory(string $category): self
  334.     {
  335.         $this->category $category;
  336.         return $this;
  337.     }
  338.     /**
  339.      * Returning a salt is only needed, if you are not using a modern
  340.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  341.      *
  342.      * @see UserInterface
  343.      */
  344.     public function getSalt(): ?string
  345.     {
  346.         return null;
  347.     }
  348.     /**
  349.      * @see UserInterface
  350.      */
  351.     public function eraseCredentials()
  352.     {
  353.         // If you store any temporary, sensitive data on the user, clear it here
  354.         // $this->plainPassword = null;
  355.     }
  356.     public function isVerified(): bool
  357.     {
  358.         return $this->isVerified;
  359.     }
  360.     public function setIsVerified(bool $isVerified): self
  361.     {
  362.         $this->isVerified $isVerified;
  363.         return $this;
  364.     }
  365.     public function isBanned(): bool
  366.     {
  367.         return $this->isBanned;
  368.     }
  369.     public function setIsBanned(bool $isBanned): self
  370.     {
  371.         $this->isBanned $isBanned;
  372.         return $this;
  373.     }
  374.     public function getRolesAvailables()
  375.     {
  376.         return self::ROLES_AVAILABLE;
  377.     }
  378.     public function getInstitution(): ?Institution
  379.     {
  380.         return $this->institution;
  381.     }
  382.     public function setInstitution(?Institution $institution): self
  383.     {
  384.         $this->institution $institution;
  385.         return $this;
  386.     }
  387.     public function getRinger(): ?Ringer
  388.     {
  389.         return $this->ringer;
  390.     }
  391.     public function setRinger(?Ringer $ringer): self
  392.     {
  393.         $this->ringer $ringer;
  394.         return $this;
  395.     }
  396.     /**
  397.      * @return Collection<int, GroupUser>
  398.      */
  399.     public function getGroupUsers(): Collection
  400.     {
  401.         return $this->groupUsers;
  402.     }
  403.     public function addGroupUser(GroupUser $groupUser): self
  404.     {
  405.         if (!$this->groupUsers->contains($groupUser)) {
  406.             $this->groupUsers[] = $groupUser;
  407.             $groupUser->setUserId($this);
  408.         }
  409.         return $this;
  410.     }
  411.     public function removeGroupUser(GroupUser $groupUser): self
  412.     {
  413.         if ($this->groupUsers->removeElement($groupUser)) {
  414.             // set the owning side to null (unless already changed)
  415.             if ($groupUser->getUserId() === $this) {
  416.                 $groupUser->setUserId(null);
  417.             }
  418.         }
  419.         return $this;
  420.     }
  421.     /**
  422.      * @return Collection<int, Group>
  423.      */
  424.     public function getCoordinatorGroups(): Collection
  425.     {
  426.         return $this->coordinator_groups;
  427.     }
  428.     public function addCoordinatorGroup(Group $coordinatorGroup): self
  429.     {
  430.         if (!$this->coordinator_groups->contains($coordinatorGroup)) {
  431.             $this->coordinator_groups[] = $coordinatorGroup;
  432.             $coordinatorGroup->setCoordinator($this);
  433.         }
  434.         return $this;
  435.     }
  436.     public function removeCoordinatorGroup(Group $coordinatorGroup): self
  437.     {
  438.         if ($this->coordinator_groups->removeElement($coordinatorGroup)) {
  439.             // set the owning side to null (unless already changed)
  440.             if ($coordinatorGroup->getCoordinator() === $this) {
  441.                 $coordinatorGroup->setCoordinator(null);
  442.             }
  443.         }
  444.         return $this;
  445.     }
  446.     /**
  447.      * @return Collection<int, Register>
  448.      */
  449.     public function getRegisters(): Collection
  450.     {
  451.         return $this->registers;
  452.     }
  453.     public function addRegister(Register $register): self
  454.     {
  455.         if (!$this->registers->contains($register)) {
  456.             $this->registers[] = $register;
  457.             $register->setUser($this);
  458.         }
  459.         return $this;
  460.     }
  461.     public function removeRegister(Register $register): self
  462.     {
  463.         if ($this->registers->removeElement($register)) {
  464.             // set the owning side to null (unless already changed)
  465.             if ($register->getUser() === $this) {
  466.                 $register->setUser(null);
  467.             }
  468.         }
  469.         return $this;
  470.     }
  471. }
  472. /**
  473.  * @var string
  474.  *
  475.  * @ORM\Column(name="role", type="string", length=10, nullable=false)
  476.  */
  477. // private $role;
  478. // public function getRole(): ?string
  479. // {
  480. //     return $this->role;
  481. // }
  482. // public function setRole(string $role): self
  483. // {
  484. //     $this->role = $role;
  485. //     return $this;
  486. // }