src/CoreBundle/Entity/Homework.php line 14

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