<?php
namespace App\ProfileBundle\Entity;
use App\CasinoBundle\Entity\Casino;
use App\CasinoBundle\Entity\Country;
use App\CasinoBundle\Entity\IssueReport;
use App\CasinoBundle\Entity\State;
use App\CasinoBundle\Entity\UserBonus;
use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Fresh\CentrifugoBundle\User\CentrifugoUserInterface;
use Sonata\UserBundle\Entity\BaseUser as BaseUser;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @ORM\Table(
* name="base_user",
* uniqueConstraints={
* @ORM\UniqueConstraint(name="user_username_canonical_uindex", columns={"username_canonical"}),
* @ORM\UniqueConstraint(name="user_email_canonical_uindex", columns={"email_canonical"}),
* @ORM\UniqueConstraint(name="user_confirmation_token_uindex", columns={"confirmation_token"})
* }
* )
*
* @ORM\Entity(repositoryClass="App\ProfileBundle\Repository\UserRepository")
*/
#[UniqueEntity(fields: ['email'], message: 'There is already an account with this email')]
class User extends BaseUser implements UserInterface, CentrifugoUserInterface
{
/**
* @ORM\Id
* @ORM\Column(type="integer", options={"unsigned":true}, nullable=true)
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @return ?int
*/
public function getId(): ?int
{
return $this->id;
}
/**
* @var string|null
* @ORM\Column(name="username", type="string", length=180, nullable=true)
*/
protected ?string $username = null;
/**
* @var string|null
* @ORM\Column(name="username_canonical", type="string", length=180, nullable=true)
*/
protected ?string $usernameCanonical = null;
/**
* @var string|null
* @ORM\Column(name="email", type="string", length=180, nullable=true, unique=true)
*/
protected ?string $email = null;
/**
* @var string|null
* @ORM\Column(name="email_canonical", type="string", length=180, nullable=true)
*/
protected ?string $emailCanonical = null;
/**
* @var bool
* @ORM\Column(name="enabled", type="boolean", options={"default": false})
*/
protected bool $enabled = false;
/**
* @var string|null
* @ORM\Column(name="salt", type="string", length=500, nullable=true)
*/
protected ?string $salt = null;
/**
* @var string|null
* @ORM\Column(name="password", type="string", length=500, nullable=true)
*/
protected ?string $password = null;
/**
* @var DateTimeInterface|null
* @ORM\Column(name="last_login", type="datetime", length=180, nullable=true)
*/
protected ?DateTimeInterface $lastLogin = null;
/**
* @var int
* @ORM\Column(name="login_count", type="integer", nullable=false, options={"default" : 0})
*/
protected int $loginCount = 0;
/**
* @var string|null
* @ORM\Column(name="confirmation_token", type="string", length=180, nullable=true)
*/
protected ?string $confirmationToken = null;
/**
* @var DateTimeInterface|null
* @ORM\Column(name="password_requested_at", type="datetime", length=180, nullable=true)
*/
protected ?DateTimeInterface $passwordRequestedAt = null;
/**
* @var array
* @ORM\Column(name="roles", type="array")
*/
protected array $roles = ['ROLE_CLIENT'];
/**
* @var DateTimeInterface|null
* @ORM\Column(name="created_at", type="datetime", nullable=true)
*/
protected ?DateTimeInterface $createdAt = null;
/**
* @var DateTimeInterface|null
* @ORM\Column(name="updated_at", type="datetime", nullable=true)
*/
protected ?DateTimeInterface $updatedAt = null;
/**
* @var bool
* @ORM\Column(name="email_confirmed", type="boolean", nullable=false)
*/
protected bool $emailConfirmed = false;
/**
* @var ?int
* @ORM\Column(name="registration_via", type="integer", nullable=true)
*/
protected ?int $registrationVia = null;
/*
* @var ?string
*/
private ?string $newPassword = null;
/**
* @var ?string
* @ORM\Column(name="avatar", type="text", nullable=true)
*/
protected ?string $avatar = null;
/**
* @ORM\OneToOne(targetEntity="App\CasinoBundle\Entity\Country")
* @ORM\JoinColumn(name="country_id", referencedColumnName="id", nullable=true)
*/
protected ?Country $country = null;
/**
* @ORM\OneToOne(targetEntity="App\CasinoBundle\Entity\State")
* @ORM\JoinColumn(name="state_id", referencedColumnName="id", nullable=true)
*/
protected ?State $state = null;
/**
* @ORM\OneToMany(
* targetEntity="App\CasinoBundle\Entity\IssueReport",
* mappedBy="user",
* )
*/
private Collection $issueReports;
/**
* @var ?string
* @ORM\Column(name="google_id", type="string", nullable=true)
*/
protected ?string $googleId = null;
/**
* @var ?int
* @ORM\Column(name="facebook_id", type="integer", nullable=true)
*/
protected ?int $facebookId = null;
/**
* @var ?string
* @ORM\Column(name="token", type="string", nullable=true)
*/
protected ?string $token = null;
/**
* @var ?string
* @ORM\Column(name="open_loyalty_id", type="string", nullable=true)
*/
protected ?string $openLoyaltyId = null;
/**
* @var int
* @ORM\Column(name="coins_balance", type="integer", nullable=false, options={"default" : 40})
*/
protected int $coinsBalance = 40;
/**
* @var ?DateTimeInterface
* @ORM\Column(name="last_visit", type="date", nullable=true)
*/
protected ?DateTimeInterface $lastVisit = null;
/**
* @var int
* @ORM\Column(name="visit_streak", type="integer", nullable=false, options={"default" : 0})
*/
protected int $visitStreak = 0;
/**
* @var int
* @ORM\Column(name="total_visits", type="integer", nullable=false, options={"default" : 0})
*/
protected int $totalVisits = 0;
/**
* @var ?UploadedFile
*/
private ?UploadedFile $file = null;
/**
* @var ArrayCollection
* @ORM\OneToMany(targetEntity="App\ProfileBundle\Entity\UserEvent", mappedBy="user", cascade={"persist","remove"}, orphanRemoval=true)
* @ORM\JoinColumn(nullable=false)
*/
protected $userEvents;
/**
* @var DateTimeInterface|null
* @ORM\Column(name="last_brevo_update", type="datetime", nullable=true)
*/
protected ?DateTimeInterface $lastBrevoUpdate = null;
/**
* @var ?string
* @ORM\Column(name="utm_data", type="string", nullable=true)
*/
protected ?string $utmData = null;
/**
* @var ?string
* @ORM\Column(name="am_data", type="string", length=1000, nullable=true)
*/
protected ?string $amData = null;
/**
* @ORM\OneToMany(
* targetEntity=UserTag::class,
* mappedBy="user",
* cascade={"persist"},
* orphanRemoval=true
* )
*/
private Collection $userTags;
/**
* @ORM\ManyToMany (
* targetEntity="App\CasinoBundle\Entity\Casino",
* inversedBy="users",
* cascade={"persist"}
* )
* @ORM\JoinTable(
* name="user_casino_registration",
* joinColumns={
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
* },
* inverseJoinColumns={
* @ORM\JoinColumn(name="casino_id", referencedColumnName="id")
* }
* )
*/
private Collection $casinos;
/**
* @ORM\OneToMany(
* targetEntity="App\CasinoBundle\Entity\UserBonus",
* mappedBy="user",
* cascade={"persist", "remove"}
* )
*/
private Collection $ownedBonuses;
/**
* @var bool
* @ORM\Column(name="protected", type="boolean", nullable=true)
*/
protected ?bool $protected;
public function __construct()
{
$this->userEvents = new ArrayCollection();
$this->userTags = new ArrayCollection();
$this->ownedBonuses = new ArrayCollection();
}
/**
* @return string
*/
public function __toString(): string
{
return $this->email ?? $this->username ??'';
}
/**
* @return Collection
*/
public function getUserEvents(): Collection
{
return ($this->userEvents)
? $this->userEvents
: new ArrayCollection();
}
/**
* @param UserEvent $userEvent
* @return $this
*/
public function addUserEvent(UserEvent $userEvent): self
{
if (!$this->userEvents->contains($userEvent)) {
$this->userEvents[] = $userEvent;
$userEvent->setUser($this);
}
return $this;
}
/**
* @param UserEvent $userEvent
* @return $this
*/
public function removeUserEvent(UserEvent $userEvent): self
{
if ($this->userEvents->contains($userEvent)) {
$this->userEvents->removeElement($userEvent);
$userEvent->setUser(null);
}
return $this;
}
/**
* @return ?string
*/
public function getNewPassword(): ?string
{
return $this->newPassword;
}
/**
* @param ?string $newPassword
* @return ?$this
*/
public function setNewPassword(?string $newPassword): ?self
{
$this->newPassword = $newPassword;
return $this;
}
/**
* @return bool
*/
public function getEmailConfirmed(): bool
{
return $this->emailConfirmed;
}
/**
* @param bool $emailConfirmed
* @return $this
*/
public function setEmailConfirmed(bool $emailConfirmed): self
{
$this->emailConfirmed = $emailConfirmed;
return $this;
}
/**
* @return ?int
*/
public function getRegistrationVia(): ?int
{
return $this->registrationVia;
}
/**
* @param ?int $registrationVia
* @return $this
*/
public function setRegistrationVia(?int $registrationVia): self
{
$this->registrationVia = $registrationVia;
return $this;
}
/**
* @return ?Country
*/
public function getCountry(): ?Country
{
return $this->country;
}
/**
* @param ?Country $country
* @return $this
*/
public function setCountry(?Country $country): self
{
$this->country = $country;
return $this;
}
/**
* @return ?State
*/
public function getState(): ?State
{
return $this->state;
}
/**
* @param ?State $state
* @return $this
*/
public function setState(?State $state): self
{
$this->state = $state;
return $this;
}
/**
* @return ?string
*/
public function getAvatar(): ?string
{
return $this->avatar;
}
/**
* @param ?string $avatar
* @return $this
*/
public function setAvatar(?string $avatar): self
{
$this->avatar = $avatar;
return $this;
}
/**
* @return ?string
*/
public function getGoogleId(): ?string
{
return $this->googleId;
}
/**
* @param ?string $googleId
* @return $this
*/
public function setGoogleId(?string $googleId): self
{
$this->googleId = $googleId;
return $this;
}
/**
* @return ?int
*/
public function getFacebookId(): ?int
{
return $this->facebookId;
}
/**
* @param ?int $facebookId
* @return $this
*/
public function setFacebookId(?int $facebookId): self
{
$this->facebookId = $facebookId;
return $this;
}
/**
* @return ?string
*/
public function getOpenLoyaltyId(): ?string
{
return $this->openLoyaltyId;
}
/**
* @param ?string $openLoyaltyId
* @return $this
*/
public function setOpenLoyaltyId(?string $openLoyaltyId): self
{
$this->openLoyaltyId = $openLoyaltyId;
return $this;
}
/**
* @return ?DateTimeInterface
*/
public function getLastVisit(): ?DateTimeInterface
{
return $this->lastVisit;
}
/**
* @param ?DateTimeInterface $lastVisit
* @return $this
*/
public function setLastVisit(?DateTimeInterface $lastVisit): self
{
$this->lastVisit = $lastVisit;
return $this;
}
/**
* @return int
*/
public function getVisitStreak(): int
{
return $this->visitStreak;
}
/**
* @param int $visitStreak
* @return $this
*/
public function setVisitStreak(int $visitStreak): self
{
$this->visitStreak = $visitStreak;
return $this;
}
/**
* @return int
*/
public function getTotalVisits(): int
{
return $this->totalVisits;
}
/**
* @param int $totalVisits
* @return $this
*/
public function setTotalVisits(int $totalVisits): self
{
$this->totalVisits = $totalVisits;
return $this;
}
/**
* @return int
*/
public function getCoinsBalance(): int
{
return $this->coinsBalance;
}
/**
* @param int $coinsBalance
* @return $this
*/
public function setCoinsBalance(int $coinsBalance): self
{
$this->coinsBalance = $coinsBalance;
return $this;
}
/**
* @return array|string[]
*/
public function getRoles(): array
{
$roles = $this->roles;
return array_unique($roles);
}
/**
* @return string|null
*/
public function getRoleAsString(): ?string
{
if (in_array('ROLE_CLIENT', $this->getRoles())) {
return 'ROLE_CLIENT';
}
if (in_array('ROLE_PARTNER', $this->getRoles())) {
return 'ROLE_PARTNER';
}
if (in_array('ROLE_ADMIN', $this->getRoles())) {
return 'ROLE_ADMIN';
}
if (in_array('ROLE_TEST_USER', $this->getRoles())) {
return 'ROLE_TEST_USER';
}
return null;
}
/**
* @param ?UploadedFile $file
* @return void
*/
public function setFile(?UploadedFile $file = null): void
{
$this->file = $file;
}
/**
* @return ?UploadedFile
*/
public function getFile(): ?UploadedFile
{
return $this->file;
}
/**
* @return ?string
*/
public function getToken(): ?string
{
return $this->token;
}
/**
* @param ?string $token
* @return $this
*/
public function setToken(?string $token): self
{
$this->token = $token;
return $this;
}
/**
* @return int
*/
public function getLoginCount(): int
{
return $this->loginCount;
}
/**
* @param int $loginCount
* @return $this
*/
public function setLoginCount(int $loginCount): self
{
$this->loginCount = $loginCount;
return $this;
}
/**
* @return ?string
*/
public function getUtmData(): ?string
{
return $this->utmData;
}
/**
* @param string|null $utmData
* @return $this
*/
public function setUtmData(?string $utmData): self
{
$this->utmData = $utmData;
return $this;
}
/**
* @return string|null
*/
public function getAmData(): ?string
{
return $this->amData;
}
/**
* @param string|null $amData
* @return $this
*/
public function setAmData(?string $amData): self
{
$this->amData = $amData;
return $this;
}
/**
* @return string|null
*/
public function getEmail(): ?string
{
return $this->email;
}
/**
* @return Collection|IssueReport[]
*/
public function getIssueReports(): Collection
{
return $this->issueReports;
}
/**
* @param IssueReport $issueReport
* @return $this
*/
public function addIssueReport(IssueReport $issueReport): self
{
if (!$this->issueReports->contains($issueReport)) {
$this->issueReports[] = $issueReport;
$issueReport->setUser($this);
}
return $this;
}
/**
* @param IssueReport $issueReport
* @return $this
*/
public function removeIssueReport(IssueReport $issueReport): self
{
if ($this->issueReports->contains($issueReport)) {
$this->issueReports->removeElement($issueReport);
$issueReport->setUser(null);
}
return $this;
}
/**
* @return Collection
*/
public function getUserTags(): Collection
{
return $this->userTags;
}
/**
* @return int
*/
public function getUserTagsCount(): int
{
return $this->userTags->count();
}
/**
* @param UserTag $userTag
* @return $this
*/
public function addUserTag(UserTag $userTag): self
{
if (!$this->userTags->contains($userTag)) {
$this->userTags[] = $userTag;
$userTag->setUser($this);
}
return $this;
}
/**
* @param UserTag $userTag
* @return $this
*/
public function removeUserTag(UserTag $userTag): self
{
if ($this->userTags->contains($userTag)) {
$this->userTags->removeElement($userTag);
}
return $this;
}
/**
* @return Collection
*/
public function getCasinos(): Collection
{
return $this->casinos;
}
/**
* @param Casino $casino
* @return $this
*/
public function addCasino(Casino $casino): self
{
if (!$this->casinos->contains($casino)) {
$this->casinos[] = $casino;
$casino->addUser($this);
}
return $this;
}
/**
* @param Casino $casino
* @return $this
*/
public function removeCasino(Casino $casino): self
{
if ($this->casinos->contains($casino)) {
$this->casinos->removeElement($casino);
$casino->removeUser($this);
}
return $this;
}
/**
* @return string
*/
public function getCentrifugoSubject(): string
{
return (string)$this->getId();
}
/**
* @return array
*/
public function getCentrifugoUserInfo(): array
{
return [];
}
/**
* @return Collection
*/
public function getOwnedBonuses(): Collection
{
return $this->ownedBonuses;
}
/**
* @param UserBonus $userBonus
* @return $this
*/
public function addOwnedBonus(UserBonus $userBonus): self
{
if (!$this->ownedBonuses->contains($userBonus)) {
$this->ownedBonuses[] = $userBonus;
$userBonus->setUser($this);
}
return $this;
}
/**
* @param UserBonus $userBonus
* @return $this
*/
public function removeOwnedBonus(UserBonus $userBonus): self
{
if ($this->ownedBonuses->removeElement($userBonus)) {
if ($userBonus->getUser() === $this) {
$userBonus->setUser(null);
}
}
return $this;
}
/**
* @return bool|null
*/
public function getProtected(): ?bool
{
return $this->protected;
}
/**
* @param null|bool $protected
* @return $this
*/
public function setProtected(?bool $protected): self
{
$this->protected = $protected;
return $this;
}
}