src/Entity/Core/SelfStudy/SelfStudyPointPool.php line 14

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