src/Entity/Jackpot.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\JackpotRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. /**
  6.  * @ORM\Entity(repositoryClass=JackpotRepository::class)
  7.  * @ORM\Table(name="jackpots")
  8.  */
  9. class Jackpot
  10. {
  11.     /**
  12.      * @ORM\Id
  13.      * @ORM\GeneratedValue
  14.      * @ORM\Column(type="integer")
  15.      */
  16.     private ?int $id;
  17.     /**
  18.      * @ORM\ManyToOne(targetEntity=Club::class, inversedBy="jackpots")
  19.      * @ORM\JoinColumn(nullable=false)
  20.      */
  21.     private Club $club;
  22.     /**
  23.      * @ORM\Column(type="integer", options={"unsigned": true})
  24.      */
  25.     private int $jp_number;
  26.     /**
  27.      * @ORM\Column(type="string", length=255, nullable=true)
  28.      */
  29.     private ?string $title null;
  30.     /**
  31.      * @ORM\Column(type="bigint", options={"unsigned": true, "default": 0})
  32.      */
  33.     private int $current_value 0;
  34.     /**
  35.      * @ORM\Column(type="bigint", options={"unsigned": true, "default": 0})
  36.      */
  37.     private int $min_value 0;
  38.     /**
  39.      * @ORM\Column(type="bigint", options={"unsigned": true, "default": 9223372036854775807})
  40.      */
  41.     private int $max_value 9223372036854770;
  42.     /**
  43.      * @ORM\Column(type="float", scale=3, precision=2, options={"default": 0.00})
  44.      */
  45.     private float $percent 0.0;
  46.     /**
  47.      * @ORM\Column(type="bigint", options={"unsigned": true, "default": 0})
  48.      */
  49.     private int $min_bet 0;
  50.     /**
  51.      * @ORM\Column(type="bigint", options={"unsigned": true, "default": 9223372036854775807})
  52.      */
  53.     private int $max_bet 9223372036854770;
  54.     /**
  55.      * @ORM\Column(type="bigint", options={"unsigned": true, "default": 0})
  56.      */
  57.     private int $threshold 0;
  58.     /**
  59.      * @ORM\Column(type="boolean", options={"default": false})
  60.      */
  61.     private bool $enabled false;
  62.     /**
  63.      * Is jackpot has win
  64.      * @return bool
  65.      */
  66.     public function hasWin(): bool
  67.     {
  68.         return
  69.             $this->threshold
  70.             && $this->threshold <= $this->current_value;
  71.     }
  72.     /**
  73.      * Add bet to jackpot counter
  74.      * @param int $bet
  75.      */
  76.     public function addBetToJackpot(int $bet)
  77.     {
  78.         $this->current_value += intval($bet $this->percent 100);
  79.     }
  80.     public function regenerate(): Jackpot
  81.     {
  82.         $this->current_value 0;
  83.         $this->threshold mt_rand($this->min_value$this->max_value);
  84.         return $this;
  85.     }
  86.     public function getWin(): int
  87.     {
  88.         return $this->threshold;
  89.     }
  90.     public function getId(): ?int
  91.     {
  92.         return $this->id;
  93.     }
  94.     public function getClub(): ?Club
  95.     {
  96.         return $this->club;
  97.     }
  98.     public function setClub(Club $club): self
  99.     {
  100.         $this->club $club;
  101.         return $this;
  102.     }
  103.     public function getJpNumber(): ?int
  104.     {
  105.         return $this->jp_number;
  106.     }
  107.     public function setJpNumber(int $jp_number): self
  108.     {
  109.         $this->jp_number $jp_number;
  110.         return $this;
  111.     }
  112.     public function getTitle(): ?string
  113.     {
  114.         return $this->title;
  115.     }
  116.     public function setTitle(?string $title): self
  117.     {
  118.         $this->title $title;
  119.         return $this;
  120.     }
  121.     public function getCurrentValue(): int
  122.     {
  123.         return $this->current_value;
  124.     }
  125.     public function setCurrentValue(int $current_value): self
  126.     {
  127.         $this->current_value $current_value;
  128.         return $this;
  129.     }
  130.     public function getMinValue(): int
  131.     {
  132.         return $this->min_value;
  133.     }
  134.     public function setMinValue(int $min_value): self
  135.     {
  136.         $this->min_value $min_value;
  137.         return $this;
  138.     }
  139.     public function getMaxValue(): int
  140.     {
  141.         return $this->max_value;
  142.     }
  143.     public function setMaxValue(int $max_value): self
  144.     {
  145.         $this->max_value $max_value;
  146.         return $this;
  147.     }
  148.     public function getPercent(): float
  149.     {
  150.         return $this->percent;
  151.     }
  152.     public function setPercent(float $percent): self
  153.     {
  154.         $this->percent $percent;
  155.         return $this;
  156.     }
  157.     public function getMinBet(): int
  158.     {
  159.         return $this->min_bet;
  160.     }
  161.     public function setMinBet(int $min_bet): self
  162.     {
  163.         $this->min_bet $min_bet;
  164.         return $this;
  165.     }
  166.     public function getMaxBet(): int
  167.     {
  168.         return $this->max_bet;
  169.     }
  170.     public function setMaxBet(int $max_bet): self
  171.     {
  172.         $this->max_bet $max_bet;
  173.         return $this;
  174.     }
  175.     public function getThreshold(): int
  176.     {
  177.         return $this->threshold;
  178.     }
  179.     public function setThreshold(int $threshold): self
  180.     {
  181.         $this->threshold $threshold;
  182.         return $this;
  183.     }
  184.     public function isEnabled(): bool
  185.     {
  186.         return $this->enabled;
  187.     }
  188.     public function setEnabled(bool $enabled true): self
  189.     {
  190.         $this->enabled $enabled;
  191.         return $this;
  192.     }
  193.     public function __toString(): string
  194.     {
  195.         return sprintf(
  196.             "Jackpot{id=%s, jp_number=%d, title=%s, current_value=%d, min_value=%d, max_value=%d, percent=%s, min_bet=%d, max_bet=%d, threshold=%d, enabled=%s}",
  197.             $this->id,
  198.             $this->jp_number,
  199.             $this->title,
  200.             $this->current_value,
  201.             $this->min_value,
  202.             $this->max_value,
  203.             $this->percent,
  204.             $this->min_bet,
  205.             $this->max_bet,
  206.             $this->threshold,
  207.             strval($this->enabled)
  208.         );
  209.     }
  210. }