<?php
namespace App\Entity;
use App\Repository\UserRepository;
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)]
#[UniqueEntity(fields: ['email'], message: 'There is already an account with this email')]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
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\ManyToOne(inversedBy: 'users')]
private ?Level $level = null;
#[ORM\OneToMany(targetEntity: Review::class, mappedBy: 'user')]
private Collection $reviews;
#[ORM\OneToOne(mappedBy: 'user', cascade: ['persist', 'remove'])]
private ?Wallet $wallet = null;
#[ORM\OneToOne(mappedBy: 'user', cascade: ['persist', 'remove'])]
private ?Referral $referral = null;
#[ORM\ManyToOne(inversedBy: 'users')]
private ?Referral $referredby = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $created = null;
#[ORM\OneToMany(targetEntity: Deposit::class, mappedBy: 'user')]
private Collection $deposits;
#[ORM\OneToMany(targetEntity: Special::class, mappedBy: 'user')]
private Collection $specials;
public function __construct()
{
$this->reviews = new ArrayCollection();
$this->created = new \DateTime();
$this->deposits = new ArrayCollection();
$this->specials = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): static
{
$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): static
{
$this->roles = $roles;
return $this;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): static
{
$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(): void
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function getLevel(): ?Level
{
return $this->level;
}
public function setLevel(?Level $level): static
{
$this->level = $level;
return $this;
}
/**
* @return Collection<int, Review>
*/
public function getReviews(): Collection
{
return $this->reviews;
}
public function addReview(Review $review): static
{
if (!$this->reviews->contains($review)) {
$this->reviews->add($review);
$review->setUser($this);
}
return $this;
}
public function removeReview(Review $review): static
{
if ($this->reviews->removeElement($review)) {
// set the owning side to null (unless already changed)
if ($review->getUser() === $this) {
$review->setUser(null);
}
}
return $this;
}
function __toString()
{
return $this->getEmail();
}
public function getWallet(): ?Wallet
{
return $this->wallet;
}
public function setWallet(?Wallet $wallet): static
{
// unset the owning side of the relation if necessary
if ($wallet === null && $this->wallet !== null) {
$this->wallet->setUser(null);
}
// set the owning side of the relation if necessary
if ($wallet !== null && $wallet->getUser() !== $this) {
$wallet->setUser($this);
}
$this->wallet = $wallet;
return $this;
}
public function getReferral(): ?Referral
{
return $this->referral;
}
public function setReferral(?Referral $referral): static
{
// unset the owning side of the relation if necessary
if ($referral === null && $this->referral !== null) {
$this->referral->setUser(null);
}
// set the owning side of the relation if necessary
if ($referral !== null && $referral->getUser() !== $this) {
$referral->setUser($this);
}
$this->referral = $referral;
return $this;
}
public function getReferredby(): ?Referral
{
return $this->referredby;
}
public function setReferredby(?Referral $referredby): static
{
$this->referredby = $referredby;
return $this;
}
public function getCreated(): ?\DateTimeInterface
{
return $this->created;
}
public function setCreated(?\DateTimeInterface $created): static
{
$this->created = $created;
return $this;
}
/**
* @return Collection<int, Deposit>
*/
public function getDeposits(): Collection
{
return $this->deposits;
}
public function addDeposit(Deposit $deposit): static
{
if (!$this->deposits->contains($deposit)) {
$this->deposits->add($deposit);
$deposit->setUser($this);
}
return $this;
}
public function removeDeposit(Deposit $deposit): static
{
if ($this->deposits->removeElement($deposit)) {
// set the owning side to null (unless already changed)
if ($deposit->getUser() === $this) {
$deposit->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Special>
*/
public function getSpecials(): Collection
{
return $this->specials;
}
public function addSpecial(Special $special): static
{
if (!$this->specials->contains($special)) {
$this->specials->add($special);
$special->setUser($this);
}
return $this;
}
public function removeSpecial(Special $special): static
{
if ($this->specials->removeElement($special)) {
// set the owning side to null (unless already changed)
if ($special->getUser() === $this) {
$special->setUser(null);
}
}
return $this;
}
}