<?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\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
*/
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"show_users"})
*/
private $id;
/**
* @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(type="string", length=255)
* @Groups({"show_users"})
*/
private $firstname;
/**
* @ORM\Column(type="string", length=255)
*/
private $lastname;
/**
* @ORM\Column(type="date")
*/
private $birthdate;
/**
* @ORM\Column(type="integer")
*/
private $status;
/**
* @ORM\Column(type="string", length=255)
*/
private $slug;
/**
* @ORM\Column(type="string", length=255, nullable=true,)
*
*/
private $picture;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $city;
/**
* @ORM\OneToMany(targetEntity=Activity::class, mappedBy="user")
*/
private $activities;
/**
* @ORM\OneToMany(targetEntity=Result::class, mappedBy="user")
*/
private $results;
/**
* @ORM\ManyToOne(targetEntity=Club::class, inversedBy="users")
*/
private $club;
public function __construct()
{
$this->teams = new ArrayCollection();
$this->activities = new ArrayCollection();
$this->results = 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;
}
/**
* 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;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
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 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;
}
public function getBirthdate(): ?\DateTimeInterface
{
return $this->birthdate;
}
public function setBirthdate(\DateTimeInterface $birthdate): self
{
$this->birthdate = $birthdate;
return $this;
}
public function getStatus(): ?int
{
return $this->status;
}
public function setStatus(int $status): self
{
$this->status = $status;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug): self
{
$this->slug = $slug;
return $this;
}
public function getPicture(): ?string
{
return $this->picture;
}
public function setPicture(?string $picture): self
{
$this->picture = $picture;
return $this;
}
public function getCity(): ?string
{
return $this->city;
}
public function setCity(?string $city): self
{
$this->city = $city;
return $this;
}
/**
* @return Collection<int, Activity>
*/
public function getActivities(): Collection
{
return $this->activities;
}
public function addActivity(Activity $activity): self
{
if (!$this->activities->contains($activity)) {
$this->activities[] = $activity;
$activity->setUser($this);
}
return $this;
}
public function removeActivity(Activity $activity): self
{
if ($this->activities->removeElement($activity)) {
// set the owning side to null (unless already changed)
if ($activity->getUser() === $this) {
$activity->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Result>
*/
public function getResults(): Collection
{
return $this->results;
}
public function addResult(Result $result): self
{
if (!$this->results->contains($result)) {
$this->results[] = $result;
$result->setUser($this);
}
return $this;
}
public function removeResult(Result $result): self
{
if ($this->results->removeElement($result)) {
// set the owning side to null (unless already changed)
if ($result->getUser() === $this) {
$result->setUser(null);
}
}
return $this;
}
public function getClub(): ?Club
{
return $this->club;
}
public function setClub(?Club $club): self
{
$this->club = $club;
return $this;
}
}