src/Entity/User.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use App\ValueObjects\BankAccounting;
  5. use App\ValueObjects\WorkingTime;
  6. use DateTime;
  7. use DateTimeInterface;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Doctrine\Common\Collections\Collection;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Symfony\Component\Security\Core\User\UserInterface;
  12. /**
  13.  * @ORM\Entity(repositoryClass=UserRepository::class)
  14.  * @ORM\Table(name="users", indexes={
  15.  *     @ORM\Index(name="idx_is_deleted", columns={"is_deleted"})
  16.  * })
  17.  */
  18. class User implements UserInterface
  19. {
  20.     /**
  21.      * @ORM\Id()
  22.      * @ORM\GeneratedValue()
  23.      * @ORM\Column(type="integer", options={"unsigned": true})
  24.      */
  25.     private ?int $id null;
  26.     /**
  27.      * @ORM\Column(type="string", length=255, unique=true)
  28.      */
  29.     private string $username '';
  30.     /**
  31.      * @ORM\Column(type="json")
  32.      */
  33.     private array $roles = [];
  34.     /**
  35.      * @ORM\Column(type="string", length=255)
  36.      */
  37.     private string $password;
  38.     /**
  39.      * @ORM\Column(type="string", length=255)
  40.      */
  41.     private string $salt "";
  42.     /**
  43.      * @ORM\Column(type="string", length=255, nullable=true)
  44.      */
  45.     private ?string $title "";
  46.     /**
  47.      * @ORM\Column(type="boolean", options={"default": false})
  48.      */
  49.     private ?bool $is_blocked false;
  50.     /**
  51.      * @ORM\Column(type="boolean", options={"default": false})
  52.      */
  53.     private ?bool $is_deleted false;
  54.     /**
  55.      * @ORM\Column(type="text", nullable=true)
  56.      */
  57.     private ?string $description "";
  58.     /**
  59.      * @ORM\ManyToMany(targetEntity=Club::class, inversedBy="users", fetch="EXTRA_LAZY")
  60.      * @ORM\JoinTable(name="users_clubs")
  61.      */
  62.     private Collection $clubs;
  63.     /**
  64.      * @ORM\Column(type="integer", options={"unsigned": true})
  65.      */
  66.     private int $type_id 0;
  67.     /**
  68.      * @ORM\Column(type="bigint", nullable=true, options={"default": 0})
  69.      */
  70.     private ?int $balance 0;
  71.     /**
  72.      * @ORM\OneToMany(targetEntity=Payment::class, mappedBy="operator")
  73.      */
  74.     private Collection $payments;
  75.     private array $allowedClubsId = [];
  76.     private array $allowedUsersId = [];
  77.     private array $allowedCashdesksId = [];
  78.     private array $allowedCashdesksIdDeleted = [];
  79.     private array $permissionsAllowedForChange = [];
  80.     /**
  81.      * @ORM\OneToMany(targetEntity=Payment::class, mappedBy="user")
  82.      */
  83.     private Collection $payments_user;
  84.     /**
  85.      * @ORM\ManyToOne(targetEntity=Club::class)
  86.      */
  87.     private ?Club $current_club;
  88.     /**
  89.      * @ORM\OneToOne(targetEntity=Cashdesk::class, inversedBy="user", cascade={"persist", "remove"})
  90.      */
  91.     private ?Cashdesk $current_cashdesk;
  92.     /**
  93.      * @ORM\Column(type="string", length=255, nullable=true)
  94.      */
  95.     private ?string $remote_client_token;
  96.     /**
  97.      * @ORM\ManyToMany(targetEntity=Cashdesk::class, inversedBy="users")
  98.      * @ORM\JoinTable(name="users_cashdesks")
  99.      */
  100.     private Collection $cashdesks;
  101.     /**
  102.      * @ORM\ManyToOne(targetEntity=Locale::class)
  103.      */
  104.     private ?Locale $locale null;
  105.     /**
  106.      * @ORM\ManyToMany(targetEntity=User::class)
  107.      * @ORM\JoinTable(name="users_users")
  108.      */
  109.     private Collection $users;
  110.     /**
  111.      * @ORM\Column(type="datetime", nullable=true, columnDefinition="TIMESTAMP DEFAULT NULL")
  112.      */
  113.     private ?DateTimeInterface $last_action_time null;
  114.     /**
  115.      * @ORM\Column(type="datetime", nullable=true, columnDefinition="TIMESTAMP DEFAULT NULL")
  116.      */
  117.     private ?DateTimeInterface $created_date null;
  118.     /**
  119.      * @ORM\OneToMany(targetEntity=Timetable::class, mappedBy="user", orphanRemoval=true)
  120.      */
  121.     private Collection $timetables;
  122.     /**
  123.      * @ORM\Column(type="boolean", nullable=true, options={"unsigned": true, "default": 1})
  124.      */
  125.     private ?bool $timetable_enabled true;
  126.     /**
  127.      * @ORM\Column(type="boolean", nullable=true, options={"unsigned": true, "default": 1})
  128.      */
  129.     private ?bool $salary_enabled true;
  130.     /**
  131.      * @ORM\Column(type="integer", nullable=true)
  132.      */
  133.     private ?int $hour_cost_0 null;
  134.     /**
  135.      * @ORM\Column(type="integer", nullable=true)
  136.      */
  137.     private ?int $hour_cost_1 null;
  138.     /**
  139.      * @ORM\Column(type="integer", nullable=true)
  140.      */
  141.     private ?int $hour_cost_2 null;
  142.     /**
  143.      * @ORM\Column(type="integer", nullable=true, options={"unsigned": true})
  144.      */
  145.     private ?int $shift_duration null;
  146.     /**
  147.      * @ORM\Column(type="integer", nullable=true, options={"unsigned": true})
  148.      */
  149.     private ?int $shift_cost null;
  150.     /**
  151.      * @ORM\Column(type="string", options={"default": ""})
  152.      */
  153.     private string $start_working_time '';
  154.     /**
  155.      * @ORM\Column(type="string", options={"default": ""})
  156.      */
  157.     private string $finish_working_time '';
  158.     /**
  159.      * @ORM\Column(type="text", nullable=true)
  160.      */
  161.     private ?string $bank_title null;
  162.     /**
  163.      * @ORM\Column(type="string", length=255, options={"default": ""})
  164.      */
  165.     private string $ban '';
  166.     /**
  167.      * @ORM\Column(type="datetime", nullable=true)
  168.      */
  169.     private ?DateTimeInterface $last_login_time null;
  170.     public function __construct()
  171.     {
  172.         $this->clubs = new ArrayCollection();
  173.         $this->payments = new ArrayCollection();
  174.         $this->payments_user = new ArrayCollection();
  175.         $this->cashdesks = new ArrayCollection();
  176.         $this->users = new ArrayCollection();
  177.         $this->timetables = new ArrayCollection();
  178.     }
  179.     public function isAllowedPaymentJackpot(): bool
  180.     {
  181.         return $this->getCurrentCashdesk()
  182.             && $this->getCurrentCashdesk()->isGranted(Roles::ROLE_CASHDESK_ALLOW_PAYING_JACKPOTS);
  183.     }
  184.     public function hasRole(string $role): bool
  185.     {
  186.         return in_array($role$this->getRoles());
  187.     }
  188.     public function setWorkingTime(WorkingTime $workingTime)
  189.     {
  190.         $this->setStartWorkingTime($workingTime->getStart());
  191.         $this->setFinishWorkingTime($workingTime->getFinish());
  192.     }
  193.     public function setBankAccounting(BankAccounting $bankAccounting)
  194.     {
  195.         $this->bank_title $bankAccounting->getBankTitle();
  196.         $this->ban $bankAccounting->getBan();
  197.     }
  198.     /**
  199.      * Allow user work in working time (if defined) only
  200.      * @return bool
  201.      */
  202.     public function isWorkingTimeNow(): bool
  203.     {
  204.         if (!$this->isTimetableEnabled()) {
  205.             return true;
  206.         }
  207.         if (empty($this->getStartWorkingTime()) || empty($this->getFinishWorkingTime())) {
  208.             return true;
  209.         }
  210.         $currentTime = (new DateTime())->format("H:i");
  211.         if ($this->getStartWorkingTime() <= $currentTime && $currentTime <= $this->getFinishWorkingTime()) {
  212.             return true;
  213.         }
  214.         return false;
  215.     }
  216.     public function releaseCurrentCashdesk(): void
  217.     {
  218.         if (!empty($this->current_cashdesk)) {
  219.             $this->current_cashdesk null;
  220.         }
  221.     }
  222.     public function isHideForAdministrator(string $permission): bool
  223.     {
  224.         if (is_null($this->getRoles())) {
  225.             return false;
  226.         }
  227.         return in_array($permission$this->getRoles());
  228.     }
  229.     /**
  230.      * Get current club id via cashdesk
  231.      * @return int|null
  232.      */
  233.     public function getCurrentClubId(): ?int
  234.     {
  235.         if ($this->getCurrentCashdesk() && $this->getCurrentCashdesk()->getClubId()) {
  236.             return $this->getCurrentCashdesk()->getClubId();
  237.         }
  238.         return null;
  239.     }
  240.     /**
  241.      * Get current affiliate id via cashdesk
  242.      * @return int
  243.      */
  244.     public function getCurrentAffiliateId(): int
  245.     {
  246.         if ($this->getCurrentCashdesk() && $this->getCurrentCashdesk()->getClubId()) {
  247.             return $this->getCurrentCashdesk()->getClub()->getAffiliateId();
  248.         }
  249.         return 0;
  250.     }
  251.     /**
  252.      * @return array<int>
  253.      */
  254.     public function getAllowedClubsId(): array
  255.     {
  256.         return $this->allowedClubsId;
  257.     }
  258.     /**
  259.      * @param array<int> $allowedClubsId
  260.      */
  261.     public function setAllowedClubsId(array $allowedClubsId): void
  262.     {
  263.         $this->allowedClubsId $allowedClubsId;
  264.     }
  265.     /**
  266.      * @return array<int>
  267.      */
  268.     public function getAllowedUsersId(): array
  269.     {
  270.         return $this->allowedUsersId;
  271.     }
  272.     /**
  273.      * @param array<int> $allowedUsersId
  274.      */
  275.     public function setAllowedUsersId(array $allowedUsersId): void
  276.     {
  277.         $this->allowedUsersId $allowedUsersId;
  278.     }
  279.     public function getId(): ?int
  280.     {
  281.         return $this->id;
  282.     }
  283.     /**
  284.      * A visual identifier that represents this user.
  285.      *
  286.      * @see UserInterface
  287.      */
  288.     public function getUsername(): string
  289.     {
  290.         return $this->username;
  291.     }
  292.     public function setUsername(string $username): self
  293.     {
  294.         $this->username $username;
  295.         return $this;
  296.     }
  297.     /**
  298.      * @see UserInterface
  299.      */
  300.     public function getRoles(): array
  301.     {
  302.         $roles $this->roles;
  303.         // guarantee every user at least has ROLE_USER
  304.         $roles[] = 'ROLE_USER';
  305.         return array_unique($roles);
  306.     }
  307.     public function setRoles(array $roles): self
  308.     {
  309.         $this->roles $roles;
  310.         return $this;
  311.     }
  312.     /**
  313.      * @see UserInterface
  314.      */
  315.     public function getPassword(): string
  316.     {
  317.         return $this->password;
  318.         // not needed for apps that do not check user passwords
  319.     }
  320.     /**
  321.      * @see UserInterface
  322.      */
  323.     public function getSalt(): string
  324.     {
  325.         return $this->salt;
  326.     }
  327.     /**
  328.      * @see UserInterface
  329.      */
  330.     public function eraseCredentials()
  331.     {
  332.         // If you store any temporary, sensitive data on the user, clear it here
  333.         // $this->plainPassword = null;
  334.     }
  335.     public function setPassword(string $password): self
  336.     {
  337.         $this->password $password;
  338.         return $this;
  339.     }
  340.     public function getTitle(): ?string
  341.     {
  342.         return $this->title;
  343.     }
  344.     public function setTitle(?string $title): self
  345.     {
  346.         $this->title $title;
  347.         return $this;
  348.     }
  349.     public function getIsBlocked(): ?bool
  350.     {
  351.         return $this->is_blocked;
  352.     }
  353.     public function setIsBlocked(?bool $is_blocked): self
  354.     {
  355.         $this->is_blocked $is_blocked;
  356.         return $this;
  357.     }
  358.     public function getIsDeleted(): ?bool
  359.     {
  360.         return $this->is_deleted;
  361.     }
  362.     public function setIsDeleted(?bool $is_deleted): self
  363.     {
  364.         $this->is_deleted $is_deleted;
  365.         return $this;
  366.     }
  367.     public function getDescription(): ?string
  368.     {
  369.         return $this->description;
  370.     }
  371.     public function setDescription(string $description): self
  372.     {
  373.         $this->description $description;
  374.         return $this;
  375.     }
  376.     /**
  377.      * @return Collection
  378.      */
  379.     public function getClubs(): Collection
  380.     {
  381.         return $this->clubs;
  382.     }
  383.     public function addClub(Club $club): self
  384.     {
  385.         if (!$this->clubs->contains($club)) {
  386.             $this->clubs[] = $club;
  387.         }
  388.         return $this;
  389.     }
  390.     public function removeClub(Club $club): self
  391.     {
  392.         if ($this->clubs->contains($club)) {
  393.             $this->clubs->removeElement($club);
  394.         }
  395.         return $this;
  396.     }
  397.     public function getTypeId(): ?int
  398.     {
  399.         return $this->type_id;
  400.     }
  401.     public function setTypeId(int $type_id): self
  402.     {
  403.         $this->type_id $type_id;
  404.         return $this;
  405.     }
  406.     public function getBalance(): ?int
  407.     {
  408.         return $this->balance;
  409.     }
  410.     public function setBalance(?int $balance): self
  411.     {
  412.         $this->balance $balance;
  413.         return $this;
  414.     }
  415.     /**
  416.      * @return Collection
  417.      */
  418.     public function getPayments(): Collection
  419.     {
  420.         return $this->payments;
  421.     }
  422.     public function addPayment(Payment $payment): self
  423.     {
  424.         if (!$this->payments->contains($payment)) {
  425.             $this->payments[] = $payment;
  426.             $payment->setOperator($this);
  427.         }
  428.         return $this;
  429.     }
  430.     public function removePayment(Payment $payment): self
  431.     {
  432.         if ($this->payments->contains($payment)) {
  433.             $this->payments->removeElement($payment);
  434.             // set the owning side to null (unless already changed)
  435.             if ($payment->getOperator() === $this) {
  436.                 $payment->setOperator(null);
  437.             }
  438.         }
  439.         return $this;
  440.     }
  441.     /**
  442.      * @return array<int>
  443.      */
  444.     public function getAllowedCashdesksId(): array
  445.     {
  446.         return $this->allowedCashdesksId;
  447.     }
  448.     /**
  449.      * @param array<int> $allowedCashdesksId
  450.      */
  451.     public function setAllowedCashdesksId(array $allowedCashdesksId): void
  452.     {
  453.         $this->allowedCashdesksId $allowedCashdesksId;
  454.     }
  455.     /**
  456.      * @return array<int>
  457.      */
  458.     public function getAllowedCashdesksIdDeleted(): array
  459.     {
  460.         return $this->allowedCashdesksIdDeleted;
  461.     }
  462.     /**
  463.      * @param array<int> $allowedCashdesksIdDeleted
  464.      */
  465.     public function setAllowedCashdesksIdDeleted(array $allowedCashdesksIdDeleted): void
  466.     {
  467.         $this->allowedCashdesksIdDeleted $allowedCashdesksIdDeleted;
  468.     }
  469.     /**
  470.      * @return Collection
  471.      */
  472.     public function getPaymentsUser(): Collection
  473.     {
  474.         return $this->payments_user;
  475.     }
  476.     public function addPaymentsUser(Payment $paymentsUser): self
  477.     {
  478.         if (!$this->payments_user->contains($paymentsUser)) {
  479.             $this->payments_user[] = $paymentsUser;
  480.             $paymentsUser->setUser($this);
  481.         }
  482.         return $this;
  483.     }
  484.     public function removePaymentsUser(Payment $paymentsUser): self
  485.     {
  486.         if ($this->payments_user->contains($paymentsUser)) {
  487.             $this->payments_user->removeElement($paymentsUser);
  488.             // set the owning side to null (unless already changed)
  489.             if ($paymentsUser->getUser() === $this) {
  490.                 $paymentsUser->setUser(null);
  491.             }
  492.         }
  493.         return $this;
  494.     }
  495.     public function getCurrentClub(): ?Club
  496.     {
  497.         return $this->current_club;
  498.     }
  499.     public function setCurrentClub(?Club $current_club): self
  500.     {
  501.         $this->current_club $current_club;
  502.         return $this;
  503.     }
  504.     public function getCurrentCashdesk(): ?Cashdesk
  505.     {
  506.         return $this->current_cashdesk;
  507.     }
  508.     public function setCurrentCashdesk(?Cashdesk $current_cashdesk): self
  509.     {
  510.         $this->current_cashdesk $current_cashdesk;
  511.         return $this;
  512.     }
  513.     public function getRemoteClientToken(): ?string
  514.     {
  515.         return $this->remote_client_token;
  516.     }
  517.     public function setRemoteClientToken(?string $remote_client_token): self
  518.     {
  519.         $this->remote_client_token $remote_client_token;
  520.         return $this;
  521.     }
  522.     /**
  523.      * @return Collection
  524.      */
  525.     public function getCashdesks(): Collection
  526.     {
  527.         return $this->cashdesks;
  528.     }
  529.     public function addCashdesk(Cashdesk $cashdesk): self
  530.     {
  531.         if (!$this->cashdesks->contains($cashdesk)) {
  532.             $this->cashdesks[] = $cashdesk;
  533.         }
  534.         return $this;
  535.     }
  536.     public function removeCashdesk(Cashdesk $cashdesk): self
  537.     {
  538.         if ($this->cashdesks->contains($cashdesk)) {
  539.             $this->cashdesks->removeElement($cashdesk);
  540.         }
  541.         return $this;
  542.     }
  543.     public function getLocale(): ?Locale
  544.     {
  545.         return $this->locale;
  546.     }
  547.     public function setLocale(?Locale $locale): self
  548.     {
  549.         $this->locale $locale;
  550.         return $this;
  551.     }
  552.     /**
  553.      * @return Collection
  554.      */
  555.     public function getUsers(): Collection
  556.     {
  557.         return $this->users;
  558.     }
  559.     public function addUser(self $user): self
  560.     {
  561.         if (!$this->users->contains($user)) {
  562.             $this->users[] = $user;
  563.         }
  564.         return $this;
  565.     }
  566.     public function removeUser(self $user): self
  567.     {
  568.         if ($this->users->contains($user)) {
  569.             $this->users->removeElement($user);
  570.         }
  571.         return $this;
  572.     }
  573.     public function getLastActionTime(): ?DateTimeInterface
  574.     {
  575.         return $this->last_action_time;
  576.     }
  577.     public function setLastActionTime(?DateTimeInterface $last_action_time): self
  578.     {
  579.         $this->last_action_time $last_action_time;
  580.         return $this;
  581.     }
  582.     public function getCreatedDate(): ?DateTimeInterface
  583.     {
  584.         return $this->created_date;
  585.     }
  586.     public function setCreatedDate(?DateTimeInterface $created_date): self
  587.     {
  588.         $this->created_date $created_date;
  589.         return $this;
  590.     }
  591.     /**
  592.      * @return Collection
  593.      */
  594.     public function getTimetables(): Collection
  595.     {
  596.         return $this->timetables;
  597.     }
  598.     public function addTimetable(Timetable $timetable): self
  599.     {
  600.         if (!$this->timetables->contains($timetable)) {
  601.             $this->timetables[] = $timetable;
  602.             $timetable->setUser($this);
  603.         }
  604.         return $this;
  605.     }
  606.     public function isTimetableEnabled(): ?bool
  607.     {
  608.         return $this->timetable_enabled;
  609.     }
  610.     public function setTimetableEnabled(?bool $timetable_enabled): self
  611.     {
  612.         $this->timetable_enabled $timetable_enabled;
  613.         return $this;
  614.     }
  615.     public function isSalaryEnabled(): ?bool
  616.     {
  617.         return $this->salary_enabled;
  618.     }
  619.     public function setSalaryEnabled(?bool $salary_enabled): self
  620.     {
  621.         $this->salary_enabled $salary_enabled;
  622.         return $this;
  623.     }
  624.     public function getShiftDuration(): ?int
  625.     {
  626.         return $this->shift_duration;
  627.     }
  628.     public function setShiftDuration(?int $shift_duration): self
  629.     {
  630.         $this->shift_duration $shift_duration;
  631.         return $this;
  632.     }
  633.     public function getShiftCost(): ?int
  634.     {
  635.         return $this->shift_cost;
  636.     }
  637.     public function setShiftCost(?int $shift_cost): self
  638.     {
  639.         $this->shift_cost $shift_cost;
  640.         return $this;
  641.     }
  642.     /**
  643.      * @return array
  644.      */
  645.     public function getPermissionsAllowedForChange(): array
  646.     {
  647.         return $this->permissionsAllowedForChange;
  648.     }
  649.     /**
  650.      * @param array $permissionsAllowedForChange
  651.      * @return User
  652.      */
  653.     public function setPermissionsAllowedForChange(array $permissionsAllowedForChange): User
  654.     {
  655.         $this->permissionsAllowedForChange $permissionsAllowedForChange;
  656.         return $this;
  657.     }
  658.     public function getStartWorkingTime(): string
  659.     {
  660.         return $this->start_working_time;
  661.     }
  662.     public function setStartWorkingTime(string $start_working_time): self
  663.     {
  664.         $this->start_working_time $start_working_time;
  665.         return $this;
  666.     }
  667.     public function getFinishWorkingTime(): string
  668.     {
  669.         return $this->finish_working_time;
  670.     }
  671.     public function setFinishWorkingTime(string $finish_working_time): self
  672.     {
  673.         $this->finish_working_time $finish_working_time;
  674.         return $this;
  675.     }
  676.     public function getHourCost_0(): ?int
  677.     {
  678.         return $this->hour_cost_0;
  679.     }
  680.     public function setHourCost_0(?int $hour_cost_0): self
  681.     {
  682.         $this->hour_cost_0 $hour_cost_0;
  683.         return $this;
  684.     }
  685.     public function getHourCost_1(): ?int
  686.     {
  687.         return $this->hour_cost_1;
  688.     }
  689.     public function setHourCost_1(?int $hour_cost_1): self
  690.     {
  691.         $this->hour_cost_1 $hour_cost_1;
  692.         return $this;
  693.     }
  694.     public function getHourCost_2(): ?int
  695.     {
  696.         return $this->hour_cost_2;
  697.     }
  698.     public function setHourCost_2(?int $hour_cost_2): self
  699.     {
  700.         $this->hour_cost_2 $hour_cost_2;
  701.         return $this;
  702.     }
  703.     /**
  704.      * @return string|null
  705.      */
  706.     public function getBankTitle(): ?string
  707.     {
  708.         return $this->bank_title;
  709.     }
  710.     /**
  711.      * @return string
  712.      */
  713.     public function getBan(): string
  714.     {
  715.         return $this->ban;
  716.     }
  717.     public function getLastLoginTime(): ?\DateTimeInterface
  718.     {
  719.         return $this->last_login_time;
  720.     }
  721.     public function setLastLoginTime(?\DateTimeInterface $last_login_time): self
  722.     {
  723.         $this->last_login_time $last_login_time;
  724.         return $this;
  725.     }
  726.     public function getUserIdentifier(): string
  727.     {
  728.         return $this->username;
  729.     }
  730. }