src/Entity/User.php line 27
<?php
namespace App\Entity;
use App\Repository\UserRepository;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
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)]
#[ORM\Table(name: '`user`')]
#[UniqueEntity(
fields: ['email'],
message: 'Désolé, un compte existe déjà avec cette adresse email',
errorPath: 'email',
)]
#[UniqueEntity(
fields: ['username'],
message: 'Désolé, un compte existe déjà avec ce pseudo',
errorPath: 'username',
)]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 180, unique: true)]
private $email;
#[ORM\Column(type: 'string', length: 50, unique: true)]
private $username;
#[ORM\Column(type: 'json')]
private $roles = [];
#[ORM\Column(type: 'string')]
private $password;
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
private ?\DateTimeInterface $created = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
private ?\DateTimeInterface $updated = null;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: TheClone::class)]
private Collection $Clones;
#[ORM\Column]
private ?bool $is_newbie = null;
#[ORM\OneToOne(mappedBy: 'user', cascade: ['persist', 'remove'])]
private ?UserRanking $userRanking = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $avatar = null;
#[ORM\ManyToMany(targetEntity: SkillTree::class)]
private Collection $skills;
public function __construct()
{
$this->created = new DateTime();
$this->updated = new DateTime();
$this->Clones = new ArrayCollection();
$this->skills = new ArrayCollection();
$this->is_newbie = true;
}
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;
}
public function getUsername(): ?string
{
return $this->username;
}
public function setUsername(string $username): self
{
$this->username = $username;
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;
}
public function getCreated(): ?\DateTimeInterface
{
return $this->created;
}
public function setCreated(\DateTimeInterface $created): self
{
$this->created = $created;
return $this;
}
public function getUpdated(): ?\DateTimeInterface
{
return $this->updated;
}
public function setUpdated(\DateTimeInterface $updated): self
{
$this->updated = $updated;
return $this;
}
/**
* @return Collection<int, TheClone>
*/
public function getClones(): Collection
{
return $this->Clones;
}
public function addClone(TheClone $clone): self
{
if (!$this->Clones->contains($clone)) {
$this->Clones->add($clone);
$clone->setUser($this);
}
return $this;
}
public function removeClone(TheClone $clone): self
{
if ($this->Clones->removeElement($clone)) {
// set the owning side to null (unless already changed)
if ($clone->getUser() === $this) {
$clone->setUser(null);
}
}
return $this;
}
public function isIsNewbie(): ?bool
{
return $this->is_newbie;
}
public function setIsNewbie(bool $is_newbie): static
{
$this->is_newbie = $is_newbie;
return $this;
}
public function getUserRanking(): ?UserRanking
{
return $this->userRanking;
}
public function setUserRanking(UserRanking $userRanking): static
{
// set the owning side of the relation if necessary
if ($userRanking->getUser() !== $this) {
$userRanking->setUser($this);
}
$this->userRanking = $userRanking;
return $this;
}
public function getAvatar(): ?string
{
return $this->avatar;
}
public function setAvatar(?string $avatar): static
{
$this->avatar = $avatar;
return $this;
}
/**
* @return Collection<int, SkillTree>
*/
public function getSkills(): Collection
{
return $this->skills;
}
public function addSkill(SkillTree $skill): static
{
if (!$this->skills->contains($skill)) {
$this->skills->add($skill);
}
return $this;
}
public function removeSkill(SkillTree $skill): static
{
$this->skills->removeElement($skill);
return $this;
}
}