src/Entity/RankingLevel.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\RankingLevelRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. /**
  10. * @ORM\Entity(repositoryClass=RankingLevelRepository::class)
  11. *
  12. * @UniqueEntity(
  13. * fields={"slug"},
  14. * message="Ce slug existe déjà."
  15. * )
  16. */
  17. class RankingLevel
  18. {
  19. /**
  20. * @ORM\Id
  21. * @ORM\GeneratedValue
  22. * @ORM\Column(type="integer")
  23. */
  24. private ?int $id;
  25. /**
  26. * @ORM\Column(type="string", length=255)
  27. *
  28. */
  29. private ?string $label;
  30. /**
  31. * @ORM\Column(type="string", length=255)
  32. *
  33. * @Assert\NotBlank(message="Le slug ne peut pas être vide.")
  34. *
  35. * @Assert\Regex(
  36. * pattern="/^[a-z0-9]+(?:-[a-z0-9]+)*$/",
  37. * message="Le slug doit contenir uniquement des lettres minuscules, chiffres et tirets."
  38. * )
  39. */
  40. private ?string $slug;
  41. /**
  42. * @ORM\ManyToOne(targetEntity=RankingSetting::class, inversedBy="rankingLevels")
  43. * @ORM\JoinColumn(nullable=false)
  44. */
  45. private ?RankingSetting $RankingSetting;
  46. /**
  47. * @ORM\OneToMany(targetEntity=RankingScore::class, mappedBy="rankingLevel")
  48. */
  49. private Collection $rankingScores;
  50. /**
  51. * Rang requis pour atteindre ce palier
  52. *
  53. * @ORM\Column(type="integer")
  54. *
  55. * @Assert\PositiveOrZero
  56. */
  57. private ?int $requiredRank = NULL;
  58. /**
  59. * Pourcentage de bonus
  60. *
  61. * @ORM\Column(type="float")
  62. *
  63. * @Assert\PositiveOrZero
  64. */
  65. private ?float $percentageWhenAchieved = NULL;
  66. /**
  67. * Bonus lors de l'atteinte du rang
  68. *
  69. * @ORM\Column(type="integer", options={"default":0})
  70. *
  71. * @Assert\PositiveOrZero
  72. */
  73. private int $bonusWhenAchieved = 0;
  74. /**
  75. * Tous les users ayant atteints ce palier
  76. *
  77. * @ORM\Column(type="json", nullable=true)
  78. */
  79. private ?string $usersReachedTheLevel = NULL;
  80. public function __construct()
  81. {
  82. $this->rankingScores = new ArrayCollection();
  83. }
  84. public function getId(): ?int
  85. {
  86. return $this->id;
  87. }
  88. public function getLabel(): ?string
  89. {
  90. return $this->label;
  91. }
  92. public function setLabel(string $label): self
  93. {
  94. $this->label = $label;
  95. return $this;
  96. }
  97. public function getSlug(): ?string
  98. {
  99. return $this->slug;
  100. }
  101. public function setSlug(string $slug): self
  102. {
  103. $this->slug = $slug;
  104. return $this;
  105. }
  106. public function getRankingSetting(): ?RankingSetting
  107. {
  108. return $this->RankingSetting;
  109. }
  110. public function setRankingSetting(?RankingSetting $RankingSetting): self
  111. {
  112. $this->RankingSetting = $RankingSetting;
  113. return $this;
  114. }
  115. /**
  116. * @return Collection<int, RankingScore>
  117. */
  118. public function getRankingScores(): Collection
  119. {
  120. return $this->rankingScores;
  121. }
  122. public function addRankingScore(RankingScore $rankingScore): self
  123. {
  124. if (!$this->rankingScores->contains($rankingScore)) {
  125. $this->rankingScores[] = $rankingScore;
  126. $rankingScore->setRankingLevel($this);
  127. }
  128. return $this;
  129. }
  130. public function removeRankingScore(RankingScore $rankingScore): self
  131. {
  132. if ($this->rankingScores->removeElement($rankingScore)) {
  133. // set the owning side to null (unless already changed)
  134. if ($rankingScore->getRankingLevel() === $this) {
  135. $rankingScore->setRankingLevel(null);
  136. }
  137. }
  138. return $this;
  139. }
  140. public function getRequiredRank(): ?int
  141. {
  142. return $this->requiredRank;
  143. }
  144. public function setRequiredRank(int $requiredRank): self
  145. {
  146. $this->requiredRank = $requiredRank;
  147. return $this;
  148. }
  149. public function getPercentageWhenAchieved(): ?float
  150. {
  151. return $this->percentageWhenAchieved;
  152. }
  153. public function setPercentageWhenAchieved(float $percentageWhenAchieved): self
  154. {
  155. $this->percentageWhenAchieved = $percentageWhenAchieved;
  156. return $this;
  157. }
  158. public function getBonusWhenAchieved(): int
  159. {
  160. return $this->bonusWhenAchieved;
  161. }
  162. public function setBonusWhenAchieved(int $bonusWhenAchieved): self
  163. {
  164. $this->bonusWhenAchieved = $bonusWhenAchieved;
  165. return $this;
  166. }
  167. public function getUsersReachedTheLevelToArray(): array
  168. {
  169. if($this->usersReachedTheLevel) {
  170. return json_decode($this->usersReachedTheLevel, TRUE);
  171. }
  172. return [];
  173. }
  174. public function getUsersReachedTheLevel(): ?string
  175. {
  176. return $this->usersReachedTheLevel;
  177. }
  178. public function setUsersReachedTheLevel(?string $usersReachedTheLevel): self
  179. {
  180. $this->usersReachedTheLevel = $usersReachedTheLevel;
  181. return $this;
  182. }
  183. }