src/ProfileBundle/Entity/User.php line 34

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