src/Entity/RankingSetting.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\RankingSettingRepository;
  4. use App\Traits\DateTrait;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use JMS\Serializer\Annotation\Groups;
  9. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. /**
  12. * @ORM\Entity(repositoryClass=RankingSettingRepository::class)
  13. * @ORM\HasLifecycleCallbacks
  14. *
  15. * @UniqueEntity(
  16. * fields={"slug"},
  17. * message="Ce slug existe déjà."
  18. * )
  19. */
  20. class RankingSetting
  21. {
  22. public CONST MODULE_NAME = 'ranking';
  23. public CONST RANKING_SETTING_TYPES_IMPORT_MANUEL = "import_manuel";
  24. public CONST RANKING_SETTING_TYPES_IMPORT_POINTS = "import_points";
  25. public CONST RANKING_SETTING_TYPES = [
  26. self::RANKING_SETTING_TYPES_IMPORT_MANUEL => "via import manuel",
  27. self::RANKING_SETTING_TYPES_IMPORT_POINTS => "via import points (automatique)",
  28. ];
  29. /**
  30. * @ORM\Id
  31. * @ORM\GeneratedValue
  32. * @ORM\Column(type="integer")
  33. * @Groups({
  34. * "ranking_setting",
  35. * })
  36. */
  37. private ?int $id = NULL;
  38. /**
  39. * @ORM\Column(type="string", length=255)
  40. * @Groups({
  41. * "ranking_setting",
  42. * })
  43. */
  44. private ?string $title = NULL;
  45. /**
  46. * @ORM\Column(type="boolean", options={"default":true})
  47. *
  48. * @Groups({
  49. * "ranking_setting",
  50. * })
  51. */
  52. private bool $enabled = TRUE;
  53. /**
  54. * @ORM\Column(type="boolean", options={"default":false})
  55. *
  56. * @Groups({
  57. * "ranking_setting",
  58. * })
  59. */
  60. private bool $provisional = FALSE;
  61. /**
  62. * @ORM\Column(type="string", length=255)
  63. *
  64. * @Assert\NotBlank(message="Le slug ne peut pas être vide.")
  65. *
  66. * @Assert\Regex(
  67. * pattern="/^[a-z0-9]+(?:-[a-z0-9]+)*$/",
  68. * message="Le slug doit contenir uniquement des lettres minuscules, chiffres et tirets."
  69. * )
  70. *
  71. * @Groups({
  72. * "ranking_setting",
  73. * })
  74. */
  75. private ?string $slug;
  76. /**
  77. * @ORM\OneToMany(targetEntity=RankingScore::class, mappedBy="rankingSetting")
  78. */
  79. private Collection $rankingScores;
  80. /**
  81. * @ORM\OneToMany(targetEntity=RankingLevel::class, mappedBy="RankingSetting", cascade={"persist", "remove"}, orphanRemoval=true)
  82. * @Assert\Valid()
  83. */
  84. private Collection $rankingLevels;
  85. /**
  86. * @ORM\Column(type="datetime", nullable=true)
  87. *
  88. * @Groups({"ranking_setting"})
  89. */
  90. private ?\DateTimeInterface $dateStart;
  91. /**
  92. * @ORM\Column(type="datetime", nullable=true)
  93. *
  94. * @Groups({"ranking_setting"})
  95. */
  96. private ?\DateTimeInterface $dateEnd;
  97. /**
  98. * @ORM\Column(type="string", length=255)
  99. * @Groups({
  100. * "ranking_setting",
  101. * })
  102. */
  103. private ?string $rankingType = NULL;
  104. use DateTrait;
  105. public function __construct()
  106. {
  107. $this->rankingScores = new ArrayCollection();
  108. $this->rankingLevels = new ArrayCollection();
  109. }
  110. public function getId(): ?int
  111. {
  112. return $this->id;
  113. }
  114. public function getTitle(): ?string
  115. {
  116. return $this->title;
  117. }
  118. public function setTitle(string $title): self
  119. {
  120. $this->title = $title;
  121. return $this;
  122. }
  123. /**
  124. * @return Collection<int, RankingScore>
  125. */
  126. public function getRankingScores(): Collection
  127. {
  128. return $this->rankingScores;
  129. }
  130. public function addRankingScore(RankingScore $rankingScore): self
  131. {
  132. if (!$this->rankingScores->contains($rankingScore)) {
  133. $this->rankingScores[] = $rankingScore;
  134. $rankingScore->setRankingSetting($this);
  135. }
  136. return $this;
  137. }
  138. public function removeRankingScore(RankingScore $rankingScore): self
  139. {
  140. if ($this->rankingScores->removeElement($rankingScore)) {
  141. // set the owning side to null (unless already changed)
  142. if ($rankingScore->getRankingSetting() === $this) {
  143. $rankingScore->setRankingSetting(null);
  144. }
  145. }
  146. return $this;
  147. }
  148. /**
  149. * @return Collection<int, RankingLevel>
  150. */
  151. public function getRankingLevels(): Collection
  152. {
  153. return $this->rankingLevels;
  154. }
  155. public function addRankingLevel(RankingLevel $rankingLevel): self
  156. {
  157. if (!$this->rankingLevels->contains($rankingLevel)) {
  158. $this->rankingLevels[] = $rankingLevel;
  159. $rankingLevel->setRankingSetting($this);
  160. }
  161. return $this;
  162. }
  163. public function removeRankingLevel(RankingLevel $rankingLevel): self
  164. {
  165. if ($this->rankingLevels->removeElement($rankingLevel)) {
  166. // set the owning side to null (unless already changed)
  167. if ($rankingLevel->getRankingSetting() === $this) {
  168. $rankingLevel->setRankingSetting(null);
  169. }
  170. }
  171. return $this;
  172. }
  173. public function getEnabled(): ?bool
  174. {
  175. return $this->enabled;
  176. }
  177. public function setEnabled( bool $enabled ): RankingSetting
  178. {
  179. $this->enabled = $enabled;
  180. return $this;
  181. }
  182. public function getSlug(): ?string
  183. {
  184. return $this->slug;
  185. }
  186. public function setSlug(string $slug): self
  187. {
  188. $this->slug = $slug;
  189. return $this;
  190. }
  191. public function getProvisional(): ?bool
  192. {
  193. return $this->provisional;
  194. }
  195. public function setProvisional( bool $provisional ): RankingSetting
  196. {
  197. $this->provisional = $provisional;
  198. return $this;
  199. }
  200. public function getDateStart(): ?\DateTimeInterface
  201. {
  202. return $this->dateStart;
  203. }
  204. public function setDateStart( ?\DateTimeInterface $dateStart ): self
  205. {
  206. $this->dateStart = $dateStart;
  207. return $this;
  208. }
  209. public function getDateEnd(): ?\DateTimeInterface
  210. {
  211. return $this->dateEnd;
  212. }
  213. public function setDateEnd( ?\DateTimeInterface $dateEnd ): self
  214. {
  215. $this->dateEnd = $dateEnd;
  216. return $this;
  217. }
  218. public function getRankingType(): ?string
  219. {
  220. return $this->rankingType;
  221. }
  222. public function setRankingType(string $rankingType): self
  223. {
  224. $this->rankingType = $rankingType;
  225. return $this;
  226. }
  227. }