src/ProfileBundle/Entity/User.php line 32

Open in your IDE?
  1. <?php
  2. namespace App\ProfileBundle\Entity;
  3. use App\CasinoBundle\Entity\Casino;
  4. use App\CasinoBundle\Entity\Country;
  5. use App\CasinoBundle\Entity\IssueReport;
  6. use App\CasinoBundle\Entity\State;
  7. use App\CasinoBundle\Entity\UserBonus;
  8. use DateTimeInterface;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Fresh\CentrifugoBundle\User\CentrifugoUserInterface;
  12. use Sonata\UserBundle\Entity\BaseUser as BaseUser;
  13. use Doctrine\ORM\Mapping as ORM;
  14. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  15. use Symfony\Component\HttpFoundation\File\UploadedFile;
  16. use Symfony\Component\Security\Core\User\UserInterface;
  17. /**
  18.  * @ORM\Table(
  19.  *     name="base_user",
  20.  *     uniqueConstraints={
  21.  *         @ORM\UniqueConstraint(name="user_username_canonical_uindex", columns={"username_canonical"}),
  22.  *         @ORM\UniqueConstraint(name="user_email_canonical_uindex", columns={"email_canonical"}),
  23.  *         @ORM\UniqueConstraint(name="user_confirmation_token_uindex", columns={"confirmation_token"})
  24.  *     }
  25.  * )
  26.  *
  27.  * @ORM\Entity(repositoryClass="App\ProfileBundle\Repository\UserRepository")
  28.  */
  29. #[UniqueEntity(fields: ['email'], message'There is already an account with this email')]
  30. class User extends BaseUser implements UserInterfaceCentrifugoUserInterface
  31. {
  32.     /**
  33.      * @ORM\Id
  34.      * @ORM\Column(type="integer", options={"unsigned":true},  nullable=true)
  35.      * @ORM\GeneratedValue(strategy="AUTO")
  36.      */
  37.     protected $id;
  38.     /**
  39.      * @return ?int
  40.      */
  41.     public function getId(): ?int
  42.     {
  43.         return $this->id;
  44.     }
  45.     /**
  46.      * @var string|null
  47.      * @ORM\Column(name="username", type="string", length=180, nullable=true)
  48.      */
  49.     protected ?string $username null;
  50.     /**
  51.      * @var string|null
  52.      * @ORM\Column(name="username_canonical", type="string", length=180, nullable=true)
  53.      */
  54.     protected ?string $usernameCanonical null;
  55.     /**
  56.      * @var string|null
  57.      * @ORM\Column(name="email", type="string", length=180, nullable=true, unique=true)
  58.      */
  59.     protected ?string $email null;
  60.     /**
  61.      * @var string|null
  62.      * @ORM\Column(name="email_canonical", type="string", length=180, nullable=true)
  63.      */
  64.     protected ?string $emailCanonical null;
  65.     /**
  66.      * @var bool
  67.      * @ORM\Column(name="enabled", type="boolean", options={"default": false})
  68.      */
  69.     protected bool $enabled false;
  70.     /**
  71.      * @var string|null
  72.      * @ORM\Column(name="salt", type="string", length=500, nullable=true)
  73.      */
  74.     protected ?string $salt null;
  75.     /**
  76.      * @var string|null
  77.      * @ORM\Column(name="password", type="string", length=500, nullable=true)
  78.      */
  79.     protected ?string $password null;
  80.     /**
  81.      * @var DateTimeInterface|null
  82.      * @ORM\Column(name="last_login", type="datetime", length=180, nullable=true)
  83.      */
  84.     protected ?DateTimeInterface $lastLogin null;
  85.     /**
  86.      * @var int
  87.      * @ORM\Column(name="login_count", type="integer", nullable=false, options={"default" : 0})
  88.      */
  89.     protected int $loginCount 0;
  90.     /**
  91.      * @var string|null
  92.      * @ORM\Column(name="confirmation_token", type="string", length=180, nullable=true)
  93.      */
  94.     protected ?string $confirmationToken null;
  95.     /**
  96.      * @var DateTimeInterface|null
  97.      * @ORM\Column(name="password_requested_at", type="datetime", length=180, nullable=true)
  98.      */
  99.     protected ?DateTimeInterface $passwordRequestedAt null;
  100.     /**
  101.      * @var array
  102.      * @ORM\Column(name="roles", type="array")
  103.      */
  104.     protected array $roles = ['ROLE_CLIENT'];
  105.     /**
  106.      * @var DateTimeInterface|null
  107.      * @ORM\Column(name="created_at", type="datetime", nullable=true)
  108.      */
  109.     protected ?DateTimeInterface $createdAt null;
  110.     /**
  111.      * @var DateTimeInterface|null
  112.      * @ORM\Column(name="updated_at", type="datetime", nullable=true)
  113.      */
  114.     protected ?DateTimeInterface $updatedAt null;
  115.     /**
  116.      * @var bool
  117.      * @ORM\Column(name="email_confirmed", type="boolean", nullable=false)
  118.      */
  119.     protected bool $emailConfirmed false;
  120.     /**
  121.      * @var ?int
  122.      * @ORM\Column(name="registration_via", type="integer", nullable=true)
  123.      */
  124.     protected ?int $registrationVia null;
  125.     /*
  126.      * @var ?string
  127.      */
  128.     private ?string $newPassword null;
  129.     /**
  130.      * @var ?string
  131.      * @ORM\Column(name="avatar", type="text", nullable=true)
  132.      */
  133.     protected ?string $avatar null;
  134.     /**
  135.      * @ORM\OneToOne(targetEntity="App\CasinoBundle\Entity\Country")
  136.      * @ORM\JoinColumn(name="country_id", referencedColumnName="id", nullable=true)
  137.      */
  138.     protected ?Country $country null;
  139.     /**
  140.      * @ORM\OneToOne(targetEntity="App\CasinoBundle\Entity\State")
  141.      * @ORM\JoinColumn(name="state_id", referencedColumnName="id", nullable=true)
  142.      */
  143.     protected ?State $state null;
  144.     /**
  145.      * @ORM\OneToMany(
  146.      *     targetEntity="App\CasinoBundle\Entity\IssueReport",
  147.      *     mappedBy="user",
  148.      * )
  149.      */
  150.     private Collection $issueReports;
  151.     /**
  152.      * @var ?string
  153.      * @ORM\Column(name="google_id", type="string", nullable=true)
  154.      */
  155.     protected ?string $googleId null;
  156.     /**
  157.      * @var ?int
  158.      * @ORM\Column(name="facebook_id", type="integer", nullable=true)
  159.      */
  160.     protected ?int $facebookId null;
  161.     /**
  162.      * @var ?string
  163.      * @ORM\Column(name="token", type="string", nullable=true)
  164.      */
  165.     protected ?string $token null;
  166.     /**
  167.      * @var ?string
  168.      * @ORM\Column(name="open_loyalty_id", type="string", nullable=true)
  169.      */
  170.     protected ?string $openLoyaltyId null;
  171.     /**
  172.      * @var int
  173.      * @ORM\Column(name="coins_balance", type="integer", nullable=false, options={"default" : 40})
  174.      */
  175.     protected int $coinsBalance 40;
  176.     /**
  177.      * @var ?DateTimeInterface
  178.      * @ORM\Column(name="last_visit", type="date", nullable=true)
  179.      */
  180.     protected ?DateTimeInterface $lastVisit null;
  181.     /**
  182.      * @var int
  183.      * @ORM\Column(name="visit_streak", type="integer", nullable=false, options={"default" : 0})
  184.      */
  185.     protected int $visitStreak 0;
  186.     /**
  187.      * @var int
  188.      * @ORM\Column(name="total_visits", type="integer", nullable=false, options={"default" : 0})
  189.      */
  190.     protected int $totalVisits 0;
  191.     /**
  192.      * @var ?UploadedFile
  193.      */
  194.     private ?UploadedFile $file null;
  195.     /**
  196.      * @var ArrayCollection
  197.      * @ORM\OneToMany(targetEntity="App\ProfileBundle\Entity\UserEvent", mappedBy="user", cascade={"persist","remove"}, orphanRemoval=true)
  198.      * @ORM\JoinColumn(nullable=false)
  199.      */
  200.     protected $userEvents;
  201.     /**
  202.      * @var DateTimeInterface|null
  203.      * @ORM\Column(name="last_brevo_update", type="datetime", nullable=true)
  204.      */
  205.     protected ?DateTimeInterface $lastBrevoUpdate null;
  206.     /**
  207.      * @var ?string
  208.      * @ORM\Column(name="utm_data", type="string", nullable=true)
  209.      */
  210.     protected ?string $utmData null;
  211.     /**
  212.      * @var ?string
  213.      * @ORM\Column(name="am_data", type="string", length=1000, nullable=true)
  214.      */
  215.     protected ?string $amData null;
  216.     /**
  217.      * @ORM\OneToMany(
  218.      *     targetEntity=UserTag::class,
  219.      *     mappedBy="user",
  220.      *     cascade={"persist"},
  221.      *     orphanRemoval=true
  222.      * )
  223.      */
  224.     private Collection $userTags;
  225.     /**
  226.      * @ORM\ManyToMany (
  227.      *     targetEntity="App\CasinoBundle\Entity\Casino",
  228.      *     inversedBy="users",
  229.      *     cascade={"persist"}
  230.      *     )
  231.      * @ORM\JoinTable(
  232.      *     name="user_casino_registration",
  233.      *     joinColumns={
  234.      *          @ORM\JoinColumn(name="user_id", referencedColumnName="id")
  235.      *     },
  236.      *     inverseJoinColumns={
  237.      *          @ORM\JoinColumn(name="casino_id", referencedColumnName="id")
  238.      *     }
  239.      * )
  240.      */
  241.     private Collection $casinos;
  242.     /**
  243.      * @ORM\OneToMany(
  244.      *     targetEntity="App\CasinoBundle\Entity\UserBonus",
  245.      *     mappedBy="user",
  246.      *     cascade={"persist", "remove"}
  247.      * )
  248.      */
  249.     private Collection $ownedBonuses;
  250.     /**
  251.      * @var bool
  252.      * @ORM\Column(name="protected", type="boolean", nullable=true)
  253.      */
  254.     protected ?bool $protected;
  255.     public function __construct()
  256.     {
  257.         $this->userEvents = new ArrayCollection();
  258.         $this->userTags = new ArrayCollection();
  259.         $this->ownedBonuses = new ArrayCollection();
  260.     }
  261.     /**
  262.      * @return string
  263.      */
  264.     public function __toString(): string
  265.     {
  266.         return $this->email ?? $this->username ??'';
  267.     }
  268.     /**
  269.      * @return Collection
  270.      */
  271.     public function getUserEvents(): Collection
  272.     {
  273.         return ($this->userEvents)
  274.             ? $this->userEvents
  275.             : new ArrayCollection();
  276.     }
  277.     /**
  278.      * @param UserEvent $userEvent
  279.      * @return $this
  280.      */
  281.     public function addUserEvent(UserEvent $userEvent): self
  282.     {
  283.         if (!$this->userEvents->contains($userEvent)) {
  284.             $this->userEvents[] = $userEvent;
  285.             $userEvent->setUser($this);
  286.         }
  287.         return $this;
  288.     }
  289.     /**
  290.      * @param UserEvent $userEvent
  291.      * @return $this
  292.      */
  293.     public function removeUserEvent(UserEvent $userEvent): self
  294.     {
  295.         if ($this->userEvents->contains($userEvent)) {
  296.             $this->userEvents->removeElement($userEvent);
  297.             $userEvent->setUser(null);
  298.         }
  299.         return $this;
  300.     }
  301.     /**
  302.      * @return ?string
  303.      */
  304.     public function getNewPassword(): ?string
  305.     {
  306.         return $this->newPassword;
  307.     }
  308.     /**
  309.      * @param ?string $newPassword
  310.      * @return ?$this
  311.      */
  312.     public function setNewPassword(?string $newPassword): ?self
  313.     {
  314.         $this->newPassword $newPassword;
  315.         return $this;
  316.     }
  317.     /**
  318.      * @return bool
  319.      */
  320.     public function getEmailConfirmed(): bool
  321.     {
  322.         return $this->emailConfirmed;
  323.     }
  324.     /**
  325.      * @param bool $emailConfirmed
  326.      * @return $this
  327.      */
  328.     public function setEmailConfirmed(bool $emailConfirmed): self
  329.     {
  330.         $this->emailConfirmed $emailConfirmed;
  331.         return $this;
  332.     }
  333.     /**
  334.      * @return ?int
  335.      */
  336.     public function getRegistrationVia(): ?int
  337.     {
  338.         return $this->registrationVia;
  339.     }
  340.     /**
  341.      * @param ?int $registrationVia
  342.      * @return $this
  343.      */
  344.     public function setRegistrationVia(?int $registrationVia): self
  345.     {
  346.         $this->registrationVia $registrationVia;
  347.         return $this;
  348.     }
  349.     /**
  350.      * @return ?Country
  351.      */
  352.     public function getCountry(): ?Country
  353.     {
  354.         return $this->country;
  355.     }
  356.     /**
  357.      * @param ?Country $country
  358.      * @return $this
  359.      */
  360.     public function setCountry(?Country $country): self
  361.     {
  362.         $this->country $country;
  363.         return $this;
  364.     }
  365.     /**
  366.      * @return ?State
  367.      */
  368.     public function getState(): ?State
  369.     {
  370.         return $this->state;
  371.     }
  372.     /**
  373.      * @param ?State $state
  374.      * @return $this
  375.      */
  376.     public function setState(?State $state): self
  377.     {
  378.         $this->state $state;
  379.         return $this;
  380.     }
  381.     /**
  382.      * @return ?string
  383.      */
  384.     public function getAvatar(): ?string
  385.     {
  386.         return $this->avatar;
  387.     }
  388.     /**
  389.      * @param ?string $avatar
  390.      * @return $this
  391.      */
  392.     public function setAvatar(?string $avatar): self
  393.     {
  394.         $this->avatar $avatar;
  395.         return $this;
  396.     }
  397.     /**
  398.      * @return ?string
  399.      */
  400.     public function getGoogleId(): ?string
  401.     {
  402.         return $this->googleId;
  403.     }
  404.     /**
  405.      * @param ?string $googleId
  406.      * @return $this
  407.      */
  408.     public function setGoogleId(?string $googleId): self
  409.     {
  410.         $this->googleId $googleId;
  411.         return $this;
  412.     }
  413.     /**
  414.      * @return ?int
  415.      */
  416.     public function getFacebookId(): ?int
  417.     {
  418.         return $this->facebookId;
  419.     }
  420.     /**
  421.      * @param ?int $facebookId
  422.      * @return $this
  423.      */
  424.     public function setFacebookId(?int $facebookId): self
  425.     {
  426.         $this->facebookId $facebookId;
  427.         return $this;
  428.     }
  429.     /**
  430.      * @return ?string
  431.      */
  432.     public function getOpenLoyaltyId(): ?string
  433.     {
  434.         return $this->openLoyaltyId;
  435.     }
  436.     /**
  437.      * @param ?string $openLoyaltyId
  438.      * @return $this
  439.      */
  440.     public function setOpenLoyaltyId(?string $openLoyaltyId): self
  441.     {
  442.         $this->openLoyaltyId $openLoyaltyId;
  443.         return $this;
  444.     }
  445.     /**
  446.      * @return ?DateTimeInterface
  447.      */
  448.     public function getLastVisit(): ?DateTimeInterface
  449.     {
  450.         return $this->lastVisit;
  451.     }
  452.     /**
  453.      * @param ?DateTimeInterface $lastVisit
  454.      * @return $this
  455.      */
  456.     public function setLastVisit(?DateTimeInterface $lastVisit): self
  457.     {
  458.         $this->lastVisit $lastVisit;
  459.         return $this;
  460.     }
  461.     /**
  462.      * @return int
  463.      */
  464.     public function getVisitStreak(): int
  465.     {
  466.         return $this->visitStreak;
  467.     }
  468.     /**
  469.      * @param int $visitStreak
  470.      * @return $this
  471.      */
  472.     public function setVisitStreak(int $visitStreak): self
  473.     {
  474.         $this->visitStreak $visitStreak;
  475.         return $this;
  476.     }
  477.     /**
  478.      * @return int
  479.      */
  480.     public function getTotalVisits(): int
  481.     {
  482.         return $this->totalVisits;
  483.     }
  484.     /**
  485.      * @param int $totalVisits
  486.      * @return $this
  487.      */
  488.     public function setTotalVisits(int $totalVisits): self
  489.     {
  490.         $this->totalVisits $totalVisits;
  491.         return $this;
  492.     }
  493.     /**
  494.      * @return int
  495.      */
  496.     public function getCoinsBalance(): int
  497.     {
  498.         return $this->coinsBalance;
  499.     }
  500.     /**
  501.      * @param int $coinsBalance
  502.      * @return $this
  503.      */
  504.     public function setCoinsBalance(int $coinsBalance): self
  505.     {
  506.         $this->coinsBalance $coinsBalance;
  507.         return $this;
  508.     }
  509.     /**
  510.      * @return array|string[]
  511.      */
  512.     public function getRoles(): array
  513.     {
  514.         $roles $this->roles;
  515.         return array_unique($roles);
  516.     }
  517.     /**
  518.      * @return string|null
  519.      */
  520.     public function getRoleAsString(): ?string
  521.     {
  522.         if (in_array('ROLE_CLIENT'$this->getRoles())) {
  523.             return 'ROLE_CLIENT';
  524.         }
  525.         if (in_array('ROLE_PARTNER'$this->getRoles())) {
  526.             return 'ROLE_PARTNER';
  527.         }
  528.         if (in_array('ROLE_ADMIN'$this->getRoles())) {
  529.             return 'ROLE_ADMIN';
  530.         }
  531.         if (in_array('ROLE_TEST_USER'$this->getRoles())) {
  532.             return 'ROLE_TEST_USER';
  533.         }
  534.         return null;
  535.     }
  536.     /**
  537.      * @param ?UploadedFile $file
  538.      * @return void
  539.      */
  540.     public function setFile(?UploadedFile $file null): void
  541.     {
  542.         $this->file $file;
  543.     }
  544.     /**
  545.      * @return ?UploadedFile
  546.      */
  547.     public function getFile(): ?UploadedFile
  548.     {
  549.         return $this->file;
  550.     }
  551.     /**
  552.      * @return ?string
  553.      */
  554.     public function getToken(): ?string
  555.     {
  556.         return $this->token;
  557.     }
  558.     /**
  559.      * @param ?string $token
  560.      * @return $this
  561.      */
  562.     public function setToken(?string $token): self
  563.     {
  564.         $this->token $token;
  565.         return $this;
  566.     }
  567.     /**
  568.      * @return int
  569.      */
  570.     public function getLoginCount(): int
  571.     {
  572.         return $this->loginCount;
  573.     }
  574.     /**
  575.      * @param int $loginCount
  576.      * @return $this
  577.      */
  578.     public function setLoginCount(int $loginCount): self
  579.     {
  580.         $this->loginCount $loginCount;
  581.         return $this;
  582.     }
  583.     /**
  584.      * @return ?string
  585.      */
  586.     public function getUtmData(): ?string
  587.     {
  588.         return $this->utmData;
  589.     }
  590.     /**
  591.      * @param string|null $utmData
  592.      * @return $this
  593.      */
  594.     public function setUtmData(?string $utmData): self
  595.     {
  596.         $this->utmData $utmData;
  597.         return $this;
  598.     }
  599.     /**
  600.      * @return string|null
  601.      */
  602.     public function getAmData(): ?string
  603.     {
  604.         return $this->amData;
  605.     }
  606.     /**
  607.      * @param string|null $amData
  608.      * @return $this
  609.      */
  610.     public function setAmData(?string $amData): self
  611.     {
  612.         $this->amData $amData;
  613.         return $this;
  614.     }
  615.     /**
  616.      * @return string|null
  617.      */
  618.     public function getEmail(): ?string
  619.     {
  620.         return $this->email;
  621.     }
  622.     /**
  623.      * @return Collection|IssueReport[]
  624.      */
  625.     public function getIssueReports(): Collection
  626.     {
  627.         return $this->issueReports;
  628.     }
  629.     /**
  630.      * @param IssueReport $issueReport
  631.      * @return $this
  632.      */
  633.     public function addIssueReport(IssueReport $issueReport): self
  634.     {
  635.         if (!$this->issueReports->contains($issueReport)) {
  636.             $this->issueReports[] = $issueReport;
  637.             $issueReport->setUser($this);
  638.         }
  639.         return $this;
  640.     }
  641.     /**
  642.      * @param IssueReport $issueReport
  643.      * @return $this
  644.      */
  645.     public function removeIssueReport(IssueReport $issueReport): self
  646.     {
  647.         if ($this->issueReports->contains($issueReport)) {
  648.             $this->issueReports->removeElement($issueReport);
  649.             $issueReport->setUser(null);
  650.         }
  651.         return $this;
  652.     }
  653.     /**
  654.      * @return Collection
  655.      */
  656.     public function getUserTags(): Collection
  657.     {
  658.         return $this->userTags;
  659.     }
  660.     /**
  661.      * @return int
  662.      */
  663.     public function getUserTagsCount(): int
  664.     {
  665.         return $this->userTags->count();
  666.     }
  667.     /**
  668.      * @param UserTag $userTag
  669.      * @return $this
  670.      */
  671.     public function addUserTag(UserTag $userTag): self
  672.     {
  673.         if (!$this->userTags->contains($userTag)) {
  674.             $this->userTags[] = $userTag;
  675.             $userTag->setUser($this);
  676.         }
  677.         return $this;
  678.     }
  679.     /**
  680.      * @param UserTag $userTag
  681.      * @return $this
  682.      */
  683.     public function removeUserTag(UserTag $userTag): self
  684.     {
  685.         if ($this->userTags->contains($userTag)) {
  686.             $this->userTags->removeElement($userTag);
  687.         }
  688.         return $this;
  689.     }
  690.     /**
  691.      * @return Collection
  692.      */
  693.     public function getCasinos(): Collection
  694.     {
  695.         return $this->casinos;
  696.     }
  697.     /**
  698.      * @param Casino $casino
  699.      * @return $this
  700.      */
  701.     public function addCasino(Casino $casino): self
  702.     {
  703.         if (!$this->casinos->contains($casino)) {
  704.             $this->casinos[] = $casino;
  705.             $casino->addUser($this);
  706.         }
  707.         return $this;
  708.     }
  709.     /**
  710.      * @param Casino $casino
  711.      * @return $this
  712.      */
  713.     public function removeCasino(Casino $casino): self
  714.     {
  715.         if ($this->casinos->contains($casino)) {
  716.             $this->casinos->removeElement($casino);
  717.             $casino->removeUser($this);
  718.         }
  719.         return $this;
  720.     }
  721.     /**
  722.      * @return string
  723.      */
  724.     public function getCentrifugoSubject(): string
  725.     {
  726.         return (string)$this->getId();
  727.     }
  728.     /**
  729.      * @return array
  730.      */
  731.     public function getCentrifugoUserInfo(): array
  732.     {
  733.         return [];
  734.     }
  735.     /**
  736.      * @return Collection
  737.      */
  738.     public function getOwnedBonuses(): Collection
  739.     {
  740.         return $this->ownedBonuses;
  741.     }
  742.     /**
  743.      * @param UserBonus $userBonus
  744.      * @return $this
  745.      */
  746.     public function addOwnedBonus(UserBonus $userBonus): self
  747.     {
  748.         if (!$this->ownedBonuses->contains($userBonus)) {
  749.             $this->ownedBonuses[] = $userBonus;
  750.             $userBonus->setUser($this);
  751.         }
  752.         return $this;
  753.     }
  754.     /**
  755.      * @param UserBonus $userBonus
  756.      * @return $this
  757.      */
  758.     public function removeOwnedBonus(UserBonus $userBonus): self
  759.     {
  760.         if ($this->ownedBonuses->removeElement($userBonus)) {
  761.             if ($userBonus->getUser() === $this) {
  762.                 $userBonus->setUser(null);
  763.             }
  764.         }
  765.         return $this;
  766.     }
  767.     /**
  768.      * @return bool|null
  769.      */
  770.     public function getProtected(): ?bool
  771.     {
  772.         return $this->protected;
  773.     }
  774.     /**
  775.      * @param null|bool $protected
  776.      * @return $this
  777.      */
  778.     public function setProtected(?bool $protected): self
  779.     {
  780.         $this->protected $protected;
  781.         return $this;
  782.     }
  783. }