src/Entity/User.php line 26
<?php
namespace App\Entity;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\UserRepository;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\ApiSubresource;
use Doctrine\Common\Collections\Collection;
use Symfony\Component\HttpFoundation\File\File;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Serializer\Annotation\Groups;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\ORM\Mapping\HasLifecycleCallbacks;
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[ApiResource(normalizationContext: ['groups' => ['user']])]
#[UniqueEntity(fields: ['email'], message: 'Un compte existe déjà avec cet email')]
#[UniqueEntity(fields: ['userName'], message: 'Ce pseudo est déjà utilisé')]
#[ORM\HasLifecycleCallbacks()]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(["user"])]
private ?int $id = null;
#[ORM\Column(length: 180, unique: true)]
private ?string $email = null;
#[ORM\Column]
private array $roles = [];
/**
* @var string The hashed password
*/
#[ORM\Column]
private ?string $password = null;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Objectif::class)]
#[Groups(["user"])]
private Collection $objectifs;
#[ORM\ManyToMany(targetEntity: Objectif::class, mappedBy: 'community')]
private Collection $joinObjectifs;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(["user"])]
private ?string $userName = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
private ?\DateTimeInterface $registerAt = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(["user"])]
private ?string $avatar = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $promesse = null;
#[ORM\Column(nullable: true)]
private ?bool $isPrivate = null;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: GameScore::class)]
private Collection $successPoints;
#[ORM\ManyToMany(targetEntity: self::class, inversedBy: 'users')]
private Collection $friends;
#[ORM\ManyToMany(targetEntity: self::class, mappedBy: 'friends')]
private Collection $users;
#[ORM\Column(nullable: true)]
private ?bool $isDailyMailEnabled = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $stripeId = null;
#[ORM\OneToOne(inversedBy: 'user', cascade: ['persist', 'remove'])]
private ?Subscription $subscription = null;
public function __construct()
{
$this->objectifs = new ArrayCollection();
$this->joinObjectifs = new ArrayCollection();
$this->successPoints = new ArrayCollection();
$this->friends = new ArrayCollection();
$this->users = new ArrayCollection();
}
#[ORM\PrePersist]
public function prePersist()
{
if (empty($this->registerAt)) {
$this->registerAt = new \DateTime();
$this->isDailyMailEnabled = 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 __toString()
{
return strtoupper($this->email);
}
/**
* 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;
}
/**
* @return Collection<int, Objectif>
*/
public function getObjectifs(): Collection
{
return $this->objectifs;
}
public function addObjectif(Objectif $objectif): self
{
if (!$this->objectifs->contains($objectif)) {
$this->objectifs->add($objectif);
$objectif->setUser($this);
}
return $this;
}
public function removeObjectif(Objectif $objectif): self
{
if ($this->objectifs->removeElement($objectif)) {
// set the owning side to null (unless already changed)
if ($objectif->getUser() === $this) {
$objectif->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Objectif>
*/
public function getJoinObjectifs(): Collection
{
return $this->joinObjectifs;
}
public function addJoinObjectif(Objectif $joinObjectif): self
{
if (!$this->joinObjectifs->contains($joinObjectif)) {
$this->joinObjectifs->add($joinObjectif);
$joinObjectif->addCommunity($this);
}
return $this;
}
public function removeJoinObjectif(Objectif $joinObjectif): self
{
if ($this->joinObjectifs->removeElement($joinObjectif)) {
$joinObjectif->removeCommunity($this);
}
return $this;
}
public function getUserName(): ?string
{
return $this->userName;
}
public function setUserName(?string $userName): self
{
$this->userName = $userName;
return $this;
}
public function getRegisterAt(): ?\DateTimeInterface
{
return $this->registerAt;
}
public function setRegisterAt(\DateTimeInterface $registerAt): self
{
$this->registerAt = $registerAt;
return $this;
}
public function getAvatar(): ?string
{
return $this->avatar;
}
public function setAvatar(?string $avatar): self
{
$this->avatar = $avatar;
return $this;
}
public function getPromesse(): ?string
{
return $this->promesse;
}
public function setPromesse(?string $promesse): self
{
$this->promesse = $promesse;
return $this;
}
public function isIsPrivate(): ?bool
{
return $this->isPrivate;
}
public function setIsPrivate(?bool $isPrivate): self
{
$this->isPrivate = $isPrivate;
return $this;
}
/**
* @return Collection<int, GameScore>
*/
public function getSuccessPoints(): Collection
{
return $this->successPoints;
}
public function addSuccessPoint(GameScore $successPoint): self
{
if (!$this->successPoints->contains($successPoint)) {
$this->successPoints->add($successPoint);
$successPoint->setUser($this);
}
return $this;
}
public function removeSuccessPoint(GameScore $successPoint): self
{
if ($this->successPoints->removeElement($successPoint)) {
// set the owning side to null (unless already changed)
if ($successPoint->getUser() === $this) {
$successPoint->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, self>
*/
public function getFriends(): Collection
{
return $this->friends;
}
public function addFriend(self $friend): self
{
if (!$this->friends->contains($friend)) {
$this->friends->add($friend);
}
return $this;
}
public function removeFriend(self $friend): self
{
$this->friends->removeElement($friend);
return $this;
}
/**
* @return Collection<int, self>
*/
public function getUsers(): Collection
{
return $this->users;
}
public function addUser(self $user): self
{
if (!$this->users->contains($user)) {
$this->users->add($user);
$user->addFriend($this);
}
return $this;
}
public function removeUser(self $user): self
{
if ($this->users->removeElement($user)) {
$user->removeFriend($this);
}
return $this;
}
public function isIsDailyMailEnabled(): ?bool
{
return $this->isDailyMailEnabled;
}
public function setIsDailyMailEnabled(?bool $isDailyMailEnabled): self
{
$this->isDailyMailEnabled = $isDailyMailEnabled;
return $this;
}
public function getStripeId(): ?string
{
return $this->stripeId;
}
public function setStripeId(?string $stripeId): self
{
$this->stripeId = $stripeId;
return $this;
}
public function getSubscription(): ?Subscription
{
return $this->subscription;
}
public function setSubscription(?Subscription $subscription): self
{
$this->subscription = $subscription;
return $this;
}
}