<?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\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')]
#[UniqueEntity(fields: ['slug'])]
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\Column(length: 255)]
private ?string $name = null;
#[ORM\Column(length: 255)]
private ?string $surname = null;
#[ORM\Column(length: 255)]
private ?string $country = null;
#[ORM\Column(length: 255)]
private ?string $city = null;
#[ORM\Column(length: 255)]
private ?string $address = null;
#[ORM\Column(length: 255)]
private ?string $passport = null;
#[ORM\Column(length: 255)]
private ?string $slug = null;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Visit::class)]
private Collection $visits;
#[ORM\Column(length: 255)]
private ?string $locale = null;
#[ORM\Column(type: 'boolean')]
private ?bool $isVerified = false;
#[ORM\Column(length: 255, nullable: true)]
private ?string $instagram = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $twitter = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $tiktok = null;
#[ORM\Column(options: ['default' => '1970-01-02'])]
private ?\DateTimeImmutable $signupDate = null;
#[ORM\Column]
private ?bool $isBanned = false;
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $bannedDate = null;
#[ORM\ManyToOne(targetEntity: self::class)]
private ?self $bannedBy = null;
public function __construct()
{
$this->visits = 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 hasRole(string $role): bool
{
return in_array($role, $this->getRoles());
}
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 getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getSurname(): ?string
{
return $this->surname;
}
public function setSurname(string $surname): self
{
$this->surname = $surname;
return $this;
}
public function getCountry(): ?string
{
return $this->country;
}
public function setCountry(string $country): self
{
$this->country = $country;
return $this;
}
public function getCity(): ?string
{
return $this->city;
}
public function setCity(string $city): self
{
$this->city = $city;
return $this;
}
public function getAddress(): ?string
{
return $this->address;
}
public function setAddress(string $address): self
{
$this->address = $address;
return $this;
}
public function getPassport(): ?string
{
return $this->passport;
}
public function setPassport(string $passport): self
{
$this->passport = $passport;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug): self
{
$this->slug = $slug;
return $this;
}
/**
* @return Collection<int, Visit>
*/
public function getVisits(): Collection
{
return $this->visits;
}
public function addVisit(Visit $visit): self
{
if (!$this->visits->contains($visit)) {
$this->visits->add($visit);
$visit->setUser($this);
}
return $this;
}
public function removeVisit(Visit $visit): self
{
if ($this->visits->removeElement($visit)) {
// set the owning side to null (unless already changed)
if ($visit->getUser() === $this) {
$visit->setUser(null);
}
}
return $this;
}
public function getLocale(): ?string
{
return $this->locale;
}
public function setLocale(string $locale): self
{
$this->locale = $locale;
return $this;
}
public function isVerified(): bool
{
return $this->isVerified;
}
public function setIsVerified(bool $isVerified): self
{
$this->isVerified = $isVerified;
return $this;
}
public function getInstagram(): ?string
{
return $this->instagram;
}
public function setInstagram(?string $instagram): self
{
$this->instagram = $instagram;
return $this;
}
public function getTwitter(): ?string
{
return $this->twitter;
}
public function setTwitter(?string $twitter): self
{
$this->twitter = $twitter;
return $this;
}
public function getTiktok(): ?string
{
return $this->tiktok;
}
public function setTiktok(?string $tiktok): self
{
$this->tiktok = $tiktok;
return $this;
}
public function getSignupDate(): ?\DateTimeImmutable
{
return $this->signupDate;
}
public function setSignupDate(\DateTimeImmutable $signupDate): self
{
$this->signupDate = $signupDate;
return $this;
}
public function isIsBanned(): ?bool
{
return $this->isBanned;
}
public function setIsBanned(bool $isBanned): self
{
$this->isBanned = $isBanned;
return $this;
}
public function getBannedDate(): ?\DateTimeImmutable
{
return $this->bannedDate;
}
public function setBannedDate(?\DateTimeImmutable $bannedDate): self
{
$this->bannedDate = $bannedDate;
return $this;
}
public function getBannedBy(): ?self
{
return $this->bannedBy;
}
public function setBannedBy(?self $bannedBy): self
{
$this->bannedBy = $bannedBy;
return $this;
}
public function isIsVerified(): ?bool
{
return $this->isVerified;
}
}