<?php
namespace App\Entity;
use App\Entity\Contest\Team;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\UserInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
/**
* @ORM\Entity()
* @UniqueEntity(fields={"email"})
* @UniqueEntity(fields={"username"})
*/
class User implements UserInterface
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=180, unique=true)
*/
private $username;
/**
* @ORM\Column(type="string", length=180, nullable=true)
*/
private $firstname;
/**
* @ORM\Column(type="string", length=180, nullable=true)
*/
private $lastname;
/**
* @ORM\Column(type="string", length=180, unique=true)
*/
private $email;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private $password;
/**
* @ORM\Column(name="enabled", type="boolean")
*/
protected $enabled = false;
/**
* @ORM\OneToMany(targetEntity=Answear::class, mappedBy="user", orphanRemoval=true)
*/
private $answears;
public function __construct()
{
$this->answears = new ArrayCollection();
}
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;
}
/**
* @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 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;
}
/**
* @return bool
*/
public function isEnabled(): bool
{
return (bool)$this->enabled;
}
/**
* @param bool $enabled
* @return User
*/
public function setEnabled(bool $enabled): self
{
$this->enabled = $enabled;
return $this;
}
public function __toString()
{
return "".$this->getUsername();
}
/**
* @return mixed
*/
public function getUsername()
{
return $this->username;
}
/**
* @param mixed $username
* @return User
*/
public function setUsername($username)
{
$this->username = $username;
return $this;
}
/**
* @return mixed
*/
public function getFirstname()
{
return $this->firstname;
}
/**
* @param mixed $firstname
* @return User
*/
public function setFirstname($firstname)
{
$this->firstname = $firstname;
return $this;
}
/**
* @return mixed
*/
public function getLastname()
{
return $this->lastname;
}
/**
* @param mixed $lastname
* @return User
*/
public function setLastname($lastname)
{
$this->lastname = $lastname;
return $this;
}
/**
* @return Collection|Answear[]
*/
public function getAnswears(): Collection
{
return $this->answears;
}
public function addAnswear(Answear $answear): self
{
if (!$this->answears->contains($answear)) {
$this->answears[] = $answear;
$answear->setUser($this);
}
return $this;
}
public function removeAnswear(Answear $answear): self
{
if ($this->answears->removeElement($answear)) {
// set the owning side to null (unless already changed)
if ($answear->getUser() === $this) {
$answear->setUser(null);
}
}
return $this;
}
}