<?php
namespace App\Entity;
use App\Entity\Application\Store;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @ORM\Entity
* @ORM\Table(name="users")
*/
class User implements UserInterface
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Dealer", inversedBy="users")
* @ORM\JoinTable(name="users_dealers")
*/
private $dealers;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Application\Store", inversedBy="users")
* @ORM\JoinTable(name="users_stores")
*/
private $stores;
/**
* @ORM\Column(type="string", length=180, unique=true)
*/
private $email;
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private $password;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $lastLogin;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
/**
* @ORM\Column(type="string", length=100, nullable=true)
*/
protected $firstName;
/**
* @ORM\Column(type="string", length=100, nullable=true)
*/
protected $lastName;
/**
* @var string Tokeny
* @ORM\Column(type="string", nullable=true)
*/
private $confirmToken;
/**
* @ORM\Column(type="boolean")
*/
private $isVerified = false;
public function __construct()
{
$this->dealers = new ArrayCollection();
$this->stores = new ArrayCollection();
}
/**
* Get Id
*
* @return mixed
*/
public function getId()
{
return $this->id;
}
/**
* Set Id
*
* @param mixed $id
*/
public function setId( $id )
{
$this->id = $id;
}
public function getFullName( )
{
return sprintf('%s %s',$this->getLastName(),$this->getFirstName());
}
/**
* @return Collection|Dealer[]
*/
public function getDealers(): Collection
{
return $this->dealers;
}
public function addDealer(Dealer $dealer): self
{
if (!$this->dealers->contains($dealer)) {
$this->dealers[] = $dealer;
$dealer->addUser($this);
}
return $this;
}
public function removeDealer(Dealer $dealer): self
{
if ($this->dealers->contains($dealer)) {
$this->dealers->removeElement($dealer);
$dealer->removeUser($this);
}
return $this;
}
/**
* @return Collection|Store[]
*/
public function getStores(): Collection
{
return $this->stores;
}
public function addStore(Store $store): self
{
if (!$this->stores->contains($store)) {
$this->stores[] = $store;
$store->addUser($this);
}
return $this;
}
public function removeStore(Store $store): self
{
if ($this->stores->contains($store)) {
$this->stores->removeElement($store);
$store->removeUser($this);
}
return $this;
}
/**
* Get Email
*
* @return mixed
*/
public function getEmail()
{
return $this->email;
}
/**
* Set Email
*
* @param mixed $email
*/
public function setEmail( $email )
{
$this->email = $email;
}
public function getFirstName(): ?string
{
return $this->firstName;
}
public function setFirstName(?string $firstName): self
{
$this->firstName = $firstName;
return $this;
}
public function getLastName(): ?string
{
return $this->lastName;
}
public function setLastName(?string $lastName): self
{
$this->lastName = $lastName;
return $this;
}
/**
* addRoles -
*
* @param $role
*/
public function addRoles($role)
{
$roles = $this->roles;
$roles[] = $role;
$this->setRoles(array_unique($roles));
}
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 UserInterface
*/
public function getPassword(): string
{
return (string) $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* @see UserInterface
*/
public function getSalt()
{
// not needed when using the "bcrypt" algorithm in security.yaml
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
/**
* Returns the username used to authenticate the user.
*
* @return string The username
*/
public function getUsername()
{
return $this->email;
}
/**
* Get LastLogin
*
* @return mixed
*/
public function getLastLogin()
{
return $this->lastLogin;
}
/**
* Set LastLogin
*
* @param mixed $lastLogin
*/
public function setLastLogin( $lastLogin )
{
$this->lastLogin = $lastLogin;
}
public function isVerified(): bool
{
return $this->isVerified;
}
public function setIsVerified(bool $isVerified): self
{
$this->isVerified = $isVerified;
return $this;
}
/**
* Get ConfirmToken
*
* @return string
*/
public function getConfirmToken()
{
return $this->confirmToken;
}
/**
* Set ConfirmToken
*
* @param string $confirmToken
*/
public function setConfirmToken( $confirmToken )
{
$this->confirmToken = $confirmToken;
}
}