2023-01-19 16:04:55 +03:30
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Entity;
|
|
|
|
|
|
|
|
use App\Repository\UserRepository;
|
2023-01-26 19:43:53 +03:30
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
|
|
use Doctrine\Common\Collections\Collection;
|
2023-01-19 16:04:55 +03:30
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
|
|
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
|
|
|
|
use Symfony\Component\Security\Core\User\UserInterface;
|
|
|
|
|
|
|
|
#[ORM\Entity(repositoryClass: UserRepository::class)]
|
|
|
|
class User implements UserInterface, PasswordAuthenticatedUserInterface
|
|
|
|
{
|
|
|
|
#[ORM\Id]
|
|
|
|
#[ORM\GeneratedValue]
|
|
|
|
#[ORM\Column]
|
|
|
|
private ?int $id = null;
|
|
|
|
|
|
|
|
#[ORM\Column(length: 180, unique: true)]
|
|
|
|
private ?string $email = null;
|
|
|
|
|
|
|
|
#[ORM\Column]
|
|
|
|
private array $roles = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string The hashed password
|
|
|
|
*/
|
|
|
|
#[ORM\Column]
|
|
|
|
private ?string $password = null;
|
|
|
|
|
2023-01-26 19:43:53 +03:30
|
|
|
#[ORM\OneToMany(mappedBy: 'user', targetEntity: UserToken::class, orphanRemoval: true)]
|
|
|
|
private Collection $userTokens;
|
|
|
|
|
|
|
|
#[ORM\Column(length: 255)]
|
|
|
|
private ?string $fullName = null;
|
|
|
|
|
|
|
|
#[ORM\Column(length: 50)]
|
|
|
|
private ?string $dateRegister = null;
|
|
|
|
|
|
|
|
#[ORM\OneToMany(mappedBy: 'owner', targetEntity: Business::class, orphanRemoval: true)]
|
|
|
|
private Collection $businesses;
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->userTokens = new ArrayCollection();
|
|
|
|
$this->businesses = new ArrayCollection();
|
|
|
|
}
|
|
|
|
|
2023-01-19 16:04:55 +03:30
|
|
|
public function getId(): ?int
|
|
|
|
{
|
|
|
|
return $this->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getEmail(): ?string
|
|
|
|
{
|
|
|
|
return $this->email;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setEmail(string $email): self
|
|
|
|
{
|
|
|
|
$this->email = $email;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A visual identifier that represents this user.
|
|
|
|
*
|
|
|
|
* @see UserInterface
|
|
|
|
*/
|
|
|
|
public function getUserIdentifier(): 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see PasswordAuthenticatedUserInterface
|
|
|
|
*/
|
|
|
|
public function getPassword(): string
|
|
|
|
{
|
|
|
|
return $this->password;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setPassword(string $password): self
|
|
|
|
{
|
|
|
|
$this->password = $password;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see UserInterface
|
|
|
|
*/
|
|
|
|
public function eraseCredentials()
|
|
|
|
{
|
|
|
|
// If you store any temporary, sensitive data on the user, clear it here
|
|
|
|
// $this->plainPassword = null;
|
|
|
|
}
|
2023-01-26 19:43:53 +03:30
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Collection<int, UserToken>
|
|
|
|
*/
|
|
|
|
public function getUserTokens(): Collection
|
|
|
|
{
|
|
|
|
return $this->userTokens;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addUserToken(UserToken $userToken): self
|
|
|
|
{
|
|
|
|
if (!$this->userTokens->contains($userToken)) {
|
|
|
|
$this->userTokens->add($userToken);
|
|
|
|
$userToken->setUser($this);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function removeUserToken(UserToken $userToken): self
|
|
|
|
{
|
|
|
|
if ($this->userTokens->removeElement($userToken)) {
|
|
|
|
// set the owning side to null (unless already changed)
|
|
|
|
if ($userToken->getUser() === $this) {
|
|
|
|
$userToken->setUser(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getFullName(): ?string
|
|
|
|
{
|
|
|
|
return $this->fullName;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setFullName(string $fullName): self
|
|
|
|
{
|
|
|
|
$this->fullName = $fullName;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getDateRegister(): ?string
|
|
|
|
{
|
|
|
|
return $this->dateRegister;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setDateRegister(string $dateRegister): self
|
|
|
|
{
|
|
|
|
$this->dateRegister = $dateRegister;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Collection<int, Business>
|
|
|
|
*/
|
|
|
|
public function getBusinesses(): Collection
|
|
|
|
{
|
|
|
|
return $this->businesses;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addBusiness(Business $business): self
|
|
|
|
{
|
|
|
|
if (!$this->businesses->contains($business)) {
|
|
|
|
$this->businesses->add($business);
|
|
|
|
$business->setOwner($this);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function removeBusiness(Business $business): self
|
|
|
|
{
|
|
|
|
if ($this->businesses->removeElement($business)) {
|
|
|
|
// set the owning side to null (unless already changed)
|
|
|
|
if ($business->getOwner() === $this) {
|
|
|
|
$business->setOwner(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
2023-01-19 16:04:55 +03:30
|
|
|
}
|