<?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: ['name'], message: 'There is already an account with this name')]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=180, unique=true)
*/
private $name;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private $password;
/**
* @ORM\ManyToOne(targetEntity=Partner::class)
*/
private $partner;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $email;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $nameSurname;
/**
* @ORM\OneToMany(targetEntity=Partner::class, mappedBy="keeper")
*/
private $partners;
/**
* @ORM\OneToMany(targetEntity=Zamowienia::class, mappedBy="user")
*/
private $zamowienias;
/**
* @ORM\OneToMany(targetEntity=Purchaser::class, mappedBy="user")
*/
private $purchasers;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $lastLogin;
/**
* @ORM\Column(type="boolean")
*/
private $www;
public function __construct()
{
$this->partners = new ArrayCollection();
$this->zamowienias = new ArrayCollection();
$this->purchasers = new ArrayCollection();
}
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;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string) $this->name;
}
/**
* @see UserInterface
*/
public function getRoles(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER';
//dd(array_unique($roles));
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;
$this->roles = [];
}
public function __toString(): string
{
return $this->name;
}
public function getLastLogin() {
return $this->lastLogin;
}
public function getPartner(): ?Partner
{
return $this->partner;
}
public function setPartner(?Partner $partner): self
{
$this->partner = $partner;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(?string $email): self
{
$this->email = $email;
return $this;
}
public function getNameSurname(): ?string
{
return $this->nameSurname;
}
public function setNameSurname(?string $nameSurname): self
{
$this->nameSurname = $nameSurname;
return $this;
}
/**
* @return Collection<int, Partner>
*/
public function getPartners(): Collection
{
return $this->partners;
}
public function addPartner(Partner $partner): self
{
if (!$this->partners->contains($partner)) {
$this->partners[] = $partner;
$partner->setKeeper($this);
}
return $this;
}
public function removePartner(Partner $partner): self
{
if ($this->partners->removeElement($partner)) {
// set the owning side to null (unless already changed)
if ($partner->getKeeper() === $this) {
$partner->setKeeper(null);
}
}
return $this;
}
/**
* @return Collection<int, Zamowienia>
*/
public function getZamowienias(): Collection
{
return $this->zamowienias;
}
public function addZamowienia(Zamowienia $zamowienia): self
{
if (!$this->zamowienias->contains($zamowienia)) {
$this->zamowienias[] = $zamowienia;
$zamowienia->setUser($this);
}
return $this;
}
public function removeZamowienia(Zamowienia $zamowienia): self
{
if ($this->zamowienias->removeElement($zamowienia)) {
// set the owning side to null (unless already changed)
if ($zamowienia->getUser() === $this) {
$zamowienia->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Purchaser>
*/
public function getPurchasers(): Collection
{
return $this->purchasers;
}
public function addPurchaser(Purchaser $purchaser): self
{
if (!$this->purchasers->contains($purchaser)) {
$this->purchasers[] = $purchaser;
$purchaser->setUser($this);
}
return $this;
}
public function removePurchaser(Purchaser $purchaser): self
{
if ($this->purchasers->removeElement($purchaser)) {
// set the owning side to null (unless already changed)
if ($purchaser->getUser() === $this) {
$purchaser->setUser(null);
}
}
return $this;
}
public function setLastLogin(?\DateTimeInterface $lastLogin): self
{
$this->lastLogin = $lastLogin;
return $this;
}
public function isWww(): ?bool
{
return $this->www;
}
public function setWww(bool $www): self
{
$this->www = $www;
return $this;
}
}