src/CoreBundle/Entity/SelfStudyPointPool.php line 13

Open in your IDE?
  1. <?php
  2. namespace CoreBundle\Entity;
  3. use JsonSerializable;
  4. use UserBundle\Entity\User;
  5. use Doctrine\ORM\Mapping as ORM;
  6. /**
  7. * @ORM\Table("self_study_point_pool")
  8. * @ORM\Entity(repositoryClass="SelfStudyPointPoolRepository")
  9. */
  10. class SelfStudyPointPool implements JsonSerializable
  11. {
  12. private const POINT_GOAL = 450;
  13. /**
  14. * @ORM\Column(name="id", type="integer")
  15. * @ORM\Id
  16. * @ORM\GeneratedValue(strategy="AUTO")
  17. */
  18. private int $id;
  19. /**
  20. * @ORM\ManyToOne(targetEntity="UserBundle\Entity\User")
  21. * @ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="CASCADE", nullable=false)
  22. */
  23. private User $student;
  24. /**
  25. * @ORM\ManyToOne(targetEntity="Topic")
  26. * @ORM\JoinColumn(name="topic_id", referencedColumnName="id", onDelete="CASCADE", nullable=false)
  27. */
  28. private Topic $topic;
  29. /**
  30. * @ORM\Column(name="current_points")
  31. */
  32. private int $currentPoints;
  33. public function getId(): int
  34. {
  35. return $this->id;
  36. }
  37. public function setId(int $id): void
  38. {
  39. $this->id = $id;
  40. }
  41. public function getStudent(): User
  42. {
  43. return $this->student;
  44. }
  45. public function setStudent(User $student): void
  46. {
  47. $this->student = $student;
  48. }
  49. public function getTopic(): Topic
  50. {
  51. return $this->topic;
  52. }
  53. public function setTopic(Topic $topic): void
  54. {
  55. $this->topic = $topic;
  56. }
  57. public function getCurrentPoints(): int
  58. {
  59. return $this->currentPoints;
  60. }
  61. public function setCurrentPoints(int $currentPoints): void
  62. {
  63. $this->currentPoints = $currentPoints;
  64. }
  65. public function getProgressPercentage(): float
  66. {
  67. if (self::POINT_GOAL === 0)
  68. return 0.0;
  69. $progress = $this->currentPoints / self::POINT_GOAL * 100;
  70. return round($progress, 1);
  71. }
  72. public function jsonSerialize(): array
  73. {
  74. return [
  75. 'id' => $this->id,
  76. 'student' => $this->student,
  77. 'topic' => $this->topic,
  78. 'currentPoints' => $this->currentPoints,
  79. 'progressPercentage' => $this->getProgressPercentage()
  80. ];
  81. }
  82. }