src/CoreBundle/Entity/GamificationProfile.php line 15

Open in your IDE?
  1. <?php
  2. namespace CoreBundle\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use JsonSerializable;
  7. use UserBundle\Entity\User;
  8. /**
  9. * @ORM\Table("gamification_profile")
  10. * @ORM\Entity(repositoryClass="CoreBundle\Entity\GamificationProfileRepository")
  11. */
  12. class GamificationProfile implements JsonSerializable
  13. {
  14. /**
  15. * @ORM\Column(name="id", type="integer")
  16. * @ORM\Id
  17. * @ORM\GeneratedValue(strategy="AUTO")
  18. */
  19. private int $id;
  20. /**
  21. * @ORM\ManyToOne(targetEntity="UserBundle\Entity\User")
  22. * @ORM\JoinColumn(name="student", referencedColumnName="id", onDelete="CASCADE")
  23. */
  24. private User $student;
  25. /**
  26. * @ORM\Column(name="current_points", type="integer", options={"default":0})
  27. */
  28. private int $currentPoints = 0;
  29. /**
  30. * @ORM\Column(name="spent_points", type="integer", options={"default":0})
  31. */
  32. private int $spentPoints = 0;
  33. /**
  34. * @ORM\OneToMany(targetEntity="KvikCustomizationBuy", mappedBy="gamificationProfile", cascade={"persist"})
  35. */
  36. private Collection $kvikCustomizationBuys;
  37. /**
  38. * @ORM\ManyToMany(targetEntity="CoreBundle\Entity\KvikCustomization")
  39. * @ORM\JoinTable(name="kvik_customization_selection",
  40. * joinColumns={@ORM\JoinColumn(name="gamification_profile", referencedColumnName="id")},
  41. * inverseJoinColumns={@ORM\JoinColumn(name="kvik_customization", referencedColumnName="id")})
  42. */
  43. private Collection $selectedKvikCustomizations;
  44. public function __construct()
  45. {
  46. $this->selectedKvikCustomizations = new ArrayCollection();
  47. $this->kvikCustomizationBuys = new ArrayCollection();
  48. }
  49. public function getId(): int
  50. {
  51. return $this->id;
  52. }
  53. public function setId(int $id): void
  54. {
  55. $this->id = $id;
  56. }
  57. public function getStudent(): User
  58. {
  59. return $this->student;
  60. }
  61. public function setStudent(User $student): void
  62. {
  63. $this->student = $student;
  64. }
  65. public function getCurrentPoints(): int
  66. {
  67. return $this->currentPoints;
  68. }
  69. public function setCurrentPoints(int $currentPoints): void
  70. {
  71. $this->currentPoints = $currentPoints;
  72. }
  73. public function getSpentPoints(): int
  74. {
  75. return $this->spentPoints;
  76. }
  77. public function setSpentPoints(int $spentPoints): void
  78. {
  79. $this->spentPoints = $spentPoints;
  80. }
  81. public function getKvikCustomizationBuys(): Collection
  82. {
  83. return $this->kvikCustomizationBuys;
  84. }
  85. public function setKvikCustomizationBuys(Collection $kvikCustomizationBuys): void
  86. {
  87. $this->kvikCustomizationBuys = $kvikCustomizationBuys;
  88. }
  89. public function getSelectedKvikCustomizations(): Collection
  90. {
  91. return $this->selectedKvikCustomizations;
  92. }
  93. public function setSelectedKvikCustomizations(Collection $selectedKvikCustomizations): void
  94. {
  95. $this->selectedKvikCustomizations = $selectedKvikCustomizations;
  96. }
  97. public function spendPoints(int $points): void
  98. {
  99. if ($points > $this->currentPoints)
  100. return;
  101. $this->currentPoints -= $points;
  102. $this->spentPoints += $points;
  103. }
  104. public function jsonSerialize(): array
  105. {
  106. return [
  107. 'id' => $this->id,
  108. 'student' => $this->student,
  109. 'currentPoints' => $this->currentPoints,
  110. 'spentPoints' => $this->spentPoints,
  111. 'selectedKvikCustomizations' => $this->selectedKvikCustomizations->toArray()
  112. ];
  113. }
  114. }