<?php
namespace App\Entity;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
* @UniqueEntity(fields={"email"}, message="There is already an account with this email")
* // @UniqueEntity(fields={"dni"}, message="There is already an account with this dni")
*/
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
/** @var Array List of available roles for users. Used on forms of user */
private const ROLES_AVAILABLE = [
'user' => 'USER',
'office' => 'OFFICE',
'admin' => 'ADMIN',
];
// public const PRUEBA_NUMEROS = [
// 'Prueba [cod]' => "1a",
// 'Pruebaa' => "2",
// 'Pruebaaa' => "3",
// 'Pruebaaaa' => "4",
// ];
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=50, nullable=true)
*/
private $name = '';
/**
* @var string
*
* @ORM\Column(name="surname", type="string", length=100, nullable=true)
*/
private $surname = '';
/**
* @ORM\Column(type="string", length=180, unique=true)
*/
private $email;
/**
* @var string
*
* @ORM\Column(name="hash_aux", type="string", length=100, nullable=true)
*/
private $hashAux;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
/**
* @ORM\Column(type="string", length=10, nullable=true)
*/
private $role_bank;
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private $password;
/**
* @var int
*
* @ORM\Column(name="active", type="integer", nullable=false)
*/
private $active = '0';
/**
* @ORM\Column(type="boolean")
*/
private $isVerified = false;
/**
* @ORM\Column(type="boolean")
*/
private $isBanned = false;
/**
* @var string
* @ORM\Column(type="string", nullable=false, unique=true)
*/
private $dni;
/**
* @var string
* @ORM\Column(type="string", nullable=true)
*/
private $telephone;
/**
* @var string
* @ORM\Column(type="string", nullable=true)
*/
private $address;
/**
* @var string
* @ORM\Column(type="string", nullable=true)
*/
private $city;
/**
* @var string
* @ORM\Column(type="string", nullable=true)
*/
private $province;
/**
* @var string
* @ORM\Column(type="string", nullable=true)
*/
private $country;
/**
* @var string
* @ORM\Column(type="string", nullable=true)
*/
private $zip_code;
/**
* @var string
* @ORM\Column(type="string", nullable=true)
*/
private $category;
/**
* @ORM\ManyToOne(targetEntity=Institution::class, inversedBy="users")
* @ORM\JoinColumn(nullable=true)
*/
private $institution;
/**
* @ORM\OneToOne(targetEntity=Ringer::class, inversedBy="user", cascade={"persist", "remove"}, fetch="EAGER")
*/
private $ringer;
/**
* @ORM\OneToMany(targetEntity=GroupUser::class, mappedBy="user_id", orphanRemoval=true, fetch="EAGER")
*/
private $groupUsers;
/**
* @ORM\OneToMany(targetEntity=Group::class, mappedBy="coordinator")
*/
private $coordinator_groups;
/**
* @ORM\OneToMany(targetEntity=Register::class, mappedBy="user")
*/
private $registers;
public function __construct()
{
$this->roles = ['ROLE_RINGER'];
$this->groupUsers = new ArrayCollection();
$this->coordinator_groups = new ArrayCollection();
$this->registers = new ArrayCollection();
}
public function __toString()
{
return $this->email;
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getSurname(): ?string
{
return $this->surname;
}
public function setSurname(string $surname): self
{
$this->surname = $surname;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function getHashAux(): ?string
{
return $this->hashAux;
}
public function setHashAux(string $hashAux): self
{
$this->hashAux = $hashAux;
return $this;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string) $this->email;
}
/**
* @deprecated since Symfony 5.3, use getUserIdentifier instead
*/
public function getUsername(): string
{
return (string) $this->email;
}
/**
* @see UserInterface
*/
public function getRoles(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER';
return array_unique($roles);
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
public function getRoleBank(): string
{
return $this->role_bank;
}
public function setRoleBank(?string $role_bank): self
{
$this->role_bank = $role_bank;
return $this;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
public function getActive(): ?int
{
return $this->active;
}
public function setActive(int $active): self
{
$this->active = $active;
return $this;
}
public function getDni(): string
{
return $this->dni;
}
public function setDni(string $dni): self
{
$this->dni = $dni;
return $this;
}
public function getTelephone(): ?string
{
return $this->telephone;
}
public function setTelephone(string $telephone): self
{
$this->telephone = $telephone;
return $this;
}
public function getAddress(): ?string
{
return $this->address;
}
public function setAddress(string $address): self
{
$this->address = $address;
return $this;
}
public function getCity(): ?string
{
return $this->city;
}
public function setCity(string $city): self
{
$this->city = $city;
return $this;
}
public function getProvince(): ?string
{
return $this->province;
}
public function setProvince(string $province): self
{
$this->province = $province;
return $this;
}
public function getCountry(): ?string
{
return $this->country;
}
public function setCountry(string $country): self
{
$this->country = $country;
return $this;
}
public function getZipcode(): ?string
{
return $this->zip_code;
}
public function setZipcode(string $zip_code): self
{
$this->zip_code = $zip_code;
return $this;
}
// public function getPrueba(): string
// {
// return $this->prueba;
// }
// public function setPrueba(string $prueba): self
// {
// $this->prueba = $prueba;
// return $this;
// }
public function getCategory(): ?string
{
return $this->category;
}
public function setCategory(string $category): self
{
$this->category = $category;
return $this;
}
/**
* Returning a salt is only needed, if you are not using a modern
* hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
*
* @see UserInterface
*/
public function getSalt(): ?string
{
return null;
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function isVerified(): bool
{
return $this->isVerified;
}
public function setIsVerified(bool $isVerified): self
{
$this->isVerified = $isVerified;
return $this;
}
public function isBanned(): bool
{
return $this->isBanned;
}
public function setIsBanned(bool $isBanned): self
{
$this->isBanned = $isBanned;
return $this;
}
public function getRolesAvailables()
{
return self::ROLES_AVAILABLE;
}
public function getInstitution(): ?Institution
{
return $this->institution;
}
public function setInstitution(?Institution $institution): self
{
$this->institution = $institution;
return $this;
}
public function getRinger(): ?Ringer
{
return $this->ringer;
}
public function setRinger(?Ringer $ringer): self
{
$this->ringer = $ringer;
return $this;
}
/**
* @return Collection<int, GroupUser>
*/
public function getGroupUsers(): Collection
{
return $this->groupUsers;
}
public function addGroupUser(GroupUser $groupUser): self
{
if (!$this->groupUsers->contains($groupUser)) {
$this->groupUsers[] = $groupUser;
$groupUser->setUserId($this);
}
return $this;
}
public function removeGroupUser(GroupUser $groupUser): self
{
if ($this->groupUsers->removeElement($groupUser)) {
// set the owning side to null (unless already changed)
if ($groupUser->getUserId() === $this) {
$groupUser->setUserId(null);
}
}
return $this;
}
/**
* @return Collection<int, Group>
*/
public function getCoordinatorGroups(): Collection
{
return $this->coordinator_groups;
}
public function addCoordinatorGroup(Group $coordinatorGroup): self
{
if (!$this->coordinator_groups->contains($coordinatorGroup)) {
$this->coordinator_groups[] = $coordinatorGroup;
$coordinatorGroup->setCoordinator($this);
}
return $this;
}
public function removeCoordinatorGroup(Group $coordinatorGroup): self
{
if ($this->coordinator_groups->removeElement($coordinatorGroup)) {
// set the owning side to null (unless already changed)
if ($coordinatorGroup->getCoordinator() === $this) {
$coordinatorGroup->setCoordinator(null);
}
}
return $this;
}
/**
* @return Collection<int, Register>
*/
public function getRegisters(): Collection
{
return $this->registers;
}
public function addRegister(Register $register): self
{
if (!$this->registers->contains($register)) {
$this->registers[] = $register;
$register->setUser($this);
}
return $this;
}
public function removeRegister(Register $register): self
{
if ($this->registers->removeElement($register)) {
// set the owning side to null (unless already changed)
if ($register->getUser() === $this) {
$register->setUser(null);
}
}
return $this;
}
}
/**
* @var string
*
* @ORM\Column(name="role", type="string", length=10, nullable=false)
*/
// private $role;
// public function getRole(): ?string
// {
// return $this->role;
// }
// public function setRole(string $role): self
// {
// $this->role = $role;
// return $this;
// }