src/Entity/Core/Homework/Homework.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Core\Homework;
  3. use App\Entity\Core\Classroom\Classroom;
  4. use App\Entity\Core\Classroom\ClassroomType;
  5. use App\Entity\Core\Session\SessionInterface;
  6. use App\Entity\Core\Session\SessionType;
  7. use App\Entity\Core\TagMathproblem;
  8. use App\Entity\Core\Topic\Topic;
  9. use DateTime;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Doctrine\Common\Collections\Collection;
  12. use Doctrine\ORM\Mapping as ORM;
  13. use JsonSerializable;
  14. #[ORM\Table('homework')]
  15. #[ORM\Entity(repositoryClass: HomeworkRepository::class)]
  16. class Homework extends SessionType implements SessionInterface, JsonSerializable
  17. {
  18. /**
  19. * @var Classroom
  20. */
  21. #[ORM\JoinColumn(name: 'classroom', referencedColumnName: 'id', onDelete: 'CASCADE')]
  22. #[ORM\ManyToOne(targetEntity: Classroom::class, inversedBy: 'sessions')]
  23. private $classroom;
  24. #[ORM\ManyToOne(targetEntity: ClassroomType::class)]
  25. #[ORM\JoinColumn(name: 'selected_classroom_type', referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
  26. private ?ClassroomType $selectedClassroomType = null;
  27. /**
  28. * @var ArrayCollection|Topic[]
  29. */
  30. #[ORM\JoinTable(name: 'homework_topic')]
  31. #[ORM\JoinColumn(name: 'homework', referencedColumnName: 'id')]
  32. #[ORM\InverseJoinColumn(name: 'topic', referencedColumnName: 'id')]
  33. #[ORM\ManyToMany(targetEntity: Topic::class, inversedBy: 'sessions')]
  34. private $topics;
  35. /**
  36. * @var ArrayCollection|TagMathproblem[]
  37. */
  38. #[ORM\JoinTable(name: 'homework_tag')]
  39. #[ORM\JoinColumn(name: 'homework', referencedColumnName: 'id')]
  40. #[ORM\InverseJoinColumn(name: 'tag', referencedColumnName: 'id')]
  41. #[ORM\ManyToMany(targetEntity: TagMathproblem::class)]
  42. private $tags;
  43. /**
  44. * @var HomeworkUnit[]
  45. */
  46. #[ORM\OneToMany(targetEntity: HomeworkUnit::class, mappedBy: 'homework', cascade: ['persist', 'remove'])]
  47. private $homeworkUnits;
  48. #[ORM\Column(type: 'integer', nullable: true, options: ['default' => 0])]
  49. private $status = 0;
  50. #[ORM\Column(type: 'integer')]
  51. private $templateCount;
  52. #[ORM\Column(type: 'integer')]
  53. private $assistance;
  54. #[ORM\Column(type: 'boolean')]
  55. private $canPause = true;
  56. #[ORM\Column(name: 'has_many_topics', type: 'integer', nullable: true, options: ['default' => 0])] // hasManyTopics = 0 (count of topics <= 3)
  57. private $hasManyTopics = 0;
  58. #[ORM\Column(name: 'start_difficulty', type: 'integer', nullable: true)]
  59. private $startDifficulty;
  60. public function __construct()
  61. {
  62. $this->homeworkUnits = new ArrayCollection();
  63. $this->topics = new ArrayCollection();
  64. $this->tags = new ArrayCollection();
  65. $this->deadline = new DateTime("now");
  66. }
  67. /**
  68. * @return Classroom
  69. */
  70. public function getClassroom()
  71. {
  72. return $this->classroom;
  73. }
  74. /**
  75. * @param Classroom $classroom
  76. */
  77. public function setClassroom($classroom)
  78. {
  79. $this->classroom = $classroom;
  80. }
  81. public function getSelectedClassroomType(): ?ClassroomType
  82. {
  83. return $this->selectedClassroomType;
  84. }
  85. public function setSelectedClassroomType(?ClassroomType $selectedClassroomType): self
  86. {
  87. $this->selectedClassroomType = $selectedClassroomType;
  88. return $this;
  89. }
  90. /**
  91. * @return Topic[]|ArrayCollection
  92. */
  93. public function getTopics(): Collection
  94. {
  95. return $this->topics;
  96. }
  97. /**
  98. * @param Topic[]|ArrayCollection $topics
  99. */
  100. public function setTopics($topics)
  101. {
  102. $this->topics = $topics;
  103. }
  104. /**
  105. * @return TagMathproblem[]|ArrayCollection
  106. */
  107. public function getTags(): Collection
  108. {
  109. return $this->tags;
  110. }
  111. /**
  112. * @param TagMathproblem[]|ArrayCollection $tags
  113. */
  114. public function setTags($tags)
  115. {
  116. $this->tags = $tags;
  117. }
  118. /**
  119. * @return HomeworkUnit[]
  120. */
  121. public function getHomeworkUnits()
  122. {
  123. return $this->homeworkUnits;
  124. }
  125. /**
  126. * @param HomeworkUnit[] $homeworkUnits
  127. */
  128. public function setHomeworkUnits($homeworkUnits)
  129. {
  130. $this->homeworkUnits = $homeworkUnits;
  131. }
  132. /**
  133. * @return mixed
  134. */
  135. public function getStatus()
  136. {
  137. return $this->status;
  138. }
  139. /**
  140. * @param mixed $status
  141. */
  142. public function setStatus($status)
  143. {
  144. $this->status = $status;
  145. }
  146. public function getTemplateCount()
  147. {
  148. return $this->templateCount;
  149. }
  150. public function setTemplateCount($count)
  151. {
  152. $this->templateCount = $count;
  153. }
  154. public function getAssistance()
  155. {
  156. return $this->assistance;
  157. }
  158. /**
  159. * @param mixed $assistance
  160. */
  161. public function setAssistance($assistance)
  162. {
  163. $this->assistance = $assistance;
  164. }
  165. public function canPause(): bool
  166. {
  167. return $this->canPause;
  168. }
  169. /**
  170. * @param mixed $canPause
  171. * @return $this
  172. */
  173. public function setCanPause($canPause)
  174. {
  175. $this->canPause = $canPause;
  176. return $this;
  177. }
  178. public function hasManyTopics(): int
  179. {
  180. return $this->hasManyTopics;
  181. }
  182. public function setHasManyTopics(int $hasManyTopics): void
  183. {
  184. $this->hasManyTopics = $hasManyTopics;
  185. }
  186. /**
  187. * @return mixed
  188. */
  189. public function getStartDifficulty()
  190. {
  191. return $this->startDifficulty;
  192. }
  193. /**
  194. * @param mixed $startDifficulty
  195. */
  196. public function setStartDifficulty($startDifficulty): void
  197. {
  198. $this->startDifficulty = $startDifficulty;
  199. }
  200. public function jsonSerialize(): mixed
  201. {
  202. return [
  203. 'id' => $this->id,
  204. 'name' => $this->name,
  205. 'startTime' => $this->startTime,
  206. 'deadline' => $this->deadline,
  207. 'duration' => $this->duration,
  208. 'status' => $this->status,
  209. 'assistance' => $this->assistance,
  210. 'canPause' => $this->canPause,
  211. 'classroom' => $this->classroom,
  212. 'hasManyTopics' => $this->hasManyTopics,
  213. 'homeworkUnits' => $this->homeworkUnits->toArray(),
  214. 'startDifficulty' => $this->startDifficulty,
  215. 'tags' => $this->tags->toArray(),
  216. 'templateCount' => $this->templateCount,
  217. 'topics' => $this->topics->toArray()
  218. ];
  219. }
  220. }