src/Entity/Core/Dictate/Dictate.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Core\Dictate;
  3. use App\Entity\Core\Classroom\ClassroomType;
  4. use App\Services\Core\ActivityTypeMappingService;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use JsonSerializable;
  7. #[ORM\Table('dictate')]
  8. #[ORM\Entity(repositoryClass: DictateRepository::class)]
  9. class Dictate implements JsonSerializable
  10. {
  11. private const int DEFAULT_DURATION = 15;
  12. /**
  13. * @var int
  14. */
  15. #[ORM\Column(name: 'id', type: 'integer')]
  16. #[ORM\Id]
  17. #[ORM\GeneratedValue(strategy: 'AUTO')]
  18. private $id;
  19. /**
  20. * @var string
  21. */
  22. #[ORM\Column(name: 'introduction', type: 'string', length: 255, nullable: true)]
  23. private $introduction;
  24. /**
  25. * @var string
  26. */
  27. #[ORM\Column(name: 'image', type: 'string', length: 128, nullable: true)]
  28. private $image;
  29. /**
  30. * @var string
  31. */
  32. #[ORM\Column(name: 'text', type: 'string', length: 4000, nullable: false)]
  33. private $text;
  34. /**
  35. * @var string
  36. */
  37. #[ORM\Column(name: 'sound_path', type: 'string', length: 128, nullable: true)]
  38. private $soundPath;
  39. /**
  40. * @var int
  41. */
  42. #[ORM\Column(name: 'level', type: 'integer', nullable: false)]
  43. private $level;
  44. /**
  45. * @var ClassroomType
  46. */
  47. #[ORM\JoinColumn(name: 'classroom_type', referencedColumnName: 'id')]
  48. #[ORM\ManyToOne(targetEntity: ClassroomType::class)]
  49. private $classroomType;
  50. /**
  51. * @var array
  52. */
  53. #[ORM\Column(name: 'color_wrong_count_threshold', type: 'simple_array', nullable: true)]
  54. private $colorWrongCountThreshold;
  55. /**
  56. * @var bool
  57. */
  58. #[ORM\Column(name: 'is_case_insensitive', type: 'boolean', options: ['default' => false])]
  59. private $isCaseInsensitive = false;
  60. public function getId(): int
  61. {
  62. return $this->id;
  63. }
  64. public function setId(int $id): void
  65. {
  66. $this->id = $id;
  67. }
  68. public function getIntroduction(): string
  69. {
  70. return $this->introduction;
  71. }
  72. public function setIntroduction(string $introduction): void
  73. {
  74. $this->introduction = $introduction;
  75. }
  76. public function getImage(): string
  77. {
  78. return $this->image;
  79. }
  80. public function setImage(string $image): void
  81. {
  82. $this->image = $image;
  83. }
  84. public function getText(): string
  85. {
  86. return $this->text;
  87. }
  88. public function setText(string $text): void
  89. {
  90. $this->text = $text;
  91. }
  92. public function getSoundPath(): string
  93. {
  94. return $this->soundPath;
  95. }
  96. public function setSoundPath(string $soundPath): void
  97. {
  98. $this->soundPath = $soundPath;
  99. }
  100. /**
  101. * @return int
  102. */
  103. public function getLevel()
  104. {
  105. return $this->level;
  106. }
  107. public function setLevel(int $level): void
  108. {
  109. $this->level = $level;
  110. }
  111. /**
  112. * @return ClassroomType
  113. */
  114. public function getClassroomType()
  115. {
  116. return $this->classroomType;
  117. }
  118. public function setClassroomType(ClassroomType $classroomType): void
  119. {
  120. $this->classroomType = $classroomType;
  121. }
  122. public function getColorWrongCountThreshold(): ?array
  123. {
  124. return $this->colorWrongCountThreshold;
  125. }
  126. public function setColorWrongCountThreshold(?array $colorWrongCountThreshold): self
  127. {
  128. $this->colorWrongCountThreshold = $colorWrongCountThreshold;
  129. return $this;
  130. }
  131. public function isCaseInsensitive(): bool
  132. {
  133. return $this->isCaseInsensitive;
  134. }
  135. public function setIsCaseInsensitive(bool $isCaseInsensitive): void
  136. {
  137. $this->isCaseInsensitive = $isCaseInsensitive;
  138. }
  139. public function toLightweightArray(ActivityTypeMappingService $activityTypeMappingService): array
  140. {
  141. return [
  142. 'id' => $this->getId(),
  143. 'type' => $activityTypeMappingService->getActivityTypeFromClass(Dictate::class),
  144. 'name' => $this->getIntroduction(),
  145. 'problemCount' => 1,
  146. 'classroomType' => $this->getClassroomType()?->getId(),
  147. ];
  148. }
  149. public function jsonSerialize(): array
  150. {
  151. return [
  152. 'id' => $this->getId(),
  153. 'introduction' => $this->getIntroduction(),
  154. 'level' => $this->getLevel(),
  155. 'problemCount' => 1,
  156. 'duration' => self::DEFAULT_DURATION, // Add this to have a fallback for screening upon request from Sofie, well knowing that the activity does not come with a duration as is. Perhaps it should be added at some point
  157. 'classroomType' => $this->getClassroomType()?->getId(),
  158. ];
  159. }
  160. }