src/CoreBundle/Entity/Worksheet.php line 15

Open in your IDE?
  1. <?php
  2. namespace CoreBundle\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use UserBundle\Entity\User;
  7. /**
  8. * @ORM\Table("worksheet")
  9. * @ORM\Entity(repositoryClass="CoreBundle\Entity\WorksheetRepository")
  10. */
  11. class Worksheet
  12. {
  13. /**
  14. * @var int
  15. *
  16. * @ORM\Column(name="id", type="integer")
  17. * @ORM\Id
  18. * @ORM\GeneratedValue(strategy="AUTO")
  19. */
  20. private $id;
  21. /**
  22. * @var int
  23. *
  24. * @ORM\Column(type="integer", nullable=false, options={"default":0})
  25. */
  26. private $duration;
  27. /**
  28. * @var string
  29. *
  30. * @ORM\Column(name="name", type="string", length=255, nullable=true)
  31. */
  32. private $name;
  33. /**
  34. * @var Collection
  35. *
  36. * @ORM\ManyToMany(targetEntity="Mathproblem")
  37. * @ORM\JoinTable(name="worksheet_problem",
  38. * joinColumns={@ORM\JoinColumn(name="worksheet_id", referencedColumnName="id")},
  39. * inverseJoinColumns={@ORM\JoinColumn(name="mathproblem_id", referencedColumnName="id")})
  40. */
  41. private $problems;
  42. /**
  43. * @var array
  44. *
  45. * @ORM\Column(name="problem_order", type="simple_array", nullable=true)
  46. */
  47. private $problemOrder;
  48. /**
  49. * @var bool
  50. *
  51. * @ORM\Column(name="reusable", type="boolean", nullable=false)
  52. */
  53. private $reusable;
  54. /**
  55. * @var bool
  56. *
  57. * @ORM\Column(name="abacus", type="boolean", nullable=true, options={"default":0})
  58. */
  59. private $abacus;
  60. /**
  61. * @var bool
  62. *
  63. * @ORM\Column(name="target_student", type="boolean", nullable=true, options={"default":0})
  64. */
  65. private $targetStudent;
  66. /**
  67. * @var \DateTimeImmutable
  68. *
  69. * @ORM\Column(name="created_at", type="datetime_immutable", nullable=false)
  70. */
  71. private $createdAt;
  72. /**
  73. * @var User
  74. *
  75. * @ORM\ManyToOne(targetEntity="UserBundle\Entity\User")
  76. * @ORM\JoinColumn(name="created_by", referencedColumnName="id")
  77. */
  78. private $createdBy;
  79. /**
  80. * @var User[]
  81. *
  82. * @ORM\ManyToMany(targetEntity="UserBundle\Entity\User")
  83. * @ORM\JoinTable(name="worksheet_teacher",
  84. * joinColumns={@ORM\JoinColumn(name="worksheet_id", referencedColumnName="id")},
  85. * inverseJoinColumns={@ORM\JoinColumn(name="teacher_id", referencedColumnName="id")})
  86. */
  87. private $teachers;
  88. /**
  89. * @var WorksheetSession[]
  90. *
  91. * @ORM\OneToMany(targetEntity="CoreBundle\Entity\WorksheetSession", mappedBy="worksheet", cascade={"persist"})
  92. */
  93. private $worksheetSessions;
  94. /**
  95. * @var ClassroomType
  96. *
  97. * @ORM\ManyToOne(targetEntity="CoreBundle\Entity\ClassroomType")
  98. * @ORM\JoinColumn(name="level", referencedColumnName="id", nullable=true)
  99. */
  100. private $level;
  101. /**
  102. * @var array
  103. *
  104. * @ORM\Column(name="mathproblems_for_templates", type="simple_array", nullable=true)
  105. */
  106. private $mathproblemsForTemplates;
  107. public function __construct()
  108. {
  109. $this->problems = new ArrayCollection();
  110. $this->teachers = new ArrayCollection();
  111. $this->worksheetSessions = new ArrayCollection();
  112. $this->createdAt = new \DateTimeImmutable('now', new \DateTimeZone('Europe/Copenhagen'));
  113. }
  114. /**
  115. * Get id.
  116. *
  117. * @return int
  118. */
  119. public function getId()
  120. {
  121. return $this->id;
  122. }
  123. /**
  124. * @return mixed
  125. */
  126. public function getName()
  127. {
  128. return $this->name;
  129. }
  130. /**
  131. * @param string $name
  132. *
  133. * @return $this
  134. */
  135. public function setName($name)
  136. {
  137. $this->name = $name;
  138. return $this;
  139. }
  140. /**
  141. * Set duration.
  142. *
  143. * @param int $duration
  144. *
  145. * @return $this
  146. */
  147. public function setDuration($duration)
  148. {
  149. $this->duration = $duration;
  150. return $this;
  151. }
  152. /**
  153. * Get duration.
  154. *
  155. * @return int
  156. */
  157. public function getDuration()
  158. {
  159. return $this->duration;
  160. }
  161. public function getProblems()
  162. {
  163. return $this->problems;
  164. }
  165. public function getSortedProblems($problemOrder = -1)
  166. {
  167. if ($problemOrder == -1) {
  168. $problemOrder = $this->problemOrder;
  169. }
  170. $problems = $this->problems;
  171. if ($problemOrder && count($problemOrder) == count($problems)) {
  172. $newmathproblems = [];
  173. foreach ($problems as $mp) {
  174. $newkey = array_search($mp->getID(), $problemOrder);
  175. $newmathproblems[$newkey] = $mp;
  176. }
  177. ksort($newmathproblems);
  178. $problems = $newmathproblems;
  179. return $problems;
  180. } else {
  181. return $this->problems->toArray(); // fallback
  182. }
  183. }
  184. /**
  185. * @param Mathproblem[]
  186. *
  187. * @return $this
  188. */
  189. public function setProblems($problems)
  190. {
  191. $this->problems = $problems;
  192. return $this;
  193. }
  194. /**
  195. * @param Mathproblem
  196. *
  197. * @return $this
  198. */
  199. public function addProblem($problem)
  200. {
  201. $this->problems->add($problem);
  202. return $this;
  203. }
  204. /**
  205. * @return bool
  206. */
  207. public function getReusable()
  208. {
  209. return $this->reusable;
  210. }
  211. /**
  212. * @param bool $reusable
  213. *
  214. * @return $this
  215. */
  216. public function setReusable($reusable)
  217. {
  218. $this->reusable = $reusable;
  219. return $this;
  220. }
  221. public function getCreatedAt(): \DateTimeImmutable
  222. {
  223. return $this->createdAt;
  224. }
  225. public function getCreatedBy(): User
  226. {
  227. return $this->createdBy;
  228. }
  229. /**
  230. * @param User $createdBy
  231. *
  232. * @return $this
  233. */
  234. public function setCreatedBy($createdBy)
  235. {
  236. $this->createdBy = $createdBy;
  237. return $this;
  238. }
  239. public function getTeachers()
  240. {
  241. return $this->teachers;
  242. }
  243. public function addTeacher(User $teacher)
  244. {
  245. $this->teachers->add($teacher);
  246. return $this;
  247. }
  248. public function getWorksheetSessions(): Collection
  249. {
  250. return $this->worksheetSessions;
  251. }
  252. public function addWorksheetSession(WorksheetSession $worksheetSession)
  253. {
  254. $this->worksheetSessions->add($worksheetSession);
  255. $worksheetSession->setWorksheet($this);
  256. return $this;
  257. }
  258. /**
  259. * @return bool
  260. */
  261. public function isAbacus()
  262. {
  263. return $this->abacus;
  264. }
  265. /**
  266. * @param bool $abacus
  267. */
  268. public function setAbacus($abacus)
  269. {
  270. $this->abacus = $abacus;
  271. }
  272. /**
  273. * @return bool | null
  274. */
  275. public function isTargetStudent()
  276. {
  277. return $this->targetStudent;
  278. }
  279. /**
  280. * @param bool $targetStudent
  281. */
  282. public function setTargetStudent(bool $targetStudent)
  283. {
  284. $this->targetStudent = $targetStudent;
  285. }
  286. public function getLevel(): ?ClassroomType
  287. {
  288. return $this->level;
  289. }
  290. public function setLevel(?ClassroomType $level): void
  291. {
  292. $this->level = $level;
  293. }
  294. public function getProblemOrder(): ?array
  295. {
  296. return $this->problemOrder;
  297. }
  298. public function setProblemOrder(array $problemOrder)
  299. {
  300. $this->problemOrder = $problemOrder;
  301. }
  302. /**
  303. * @return array|null
  304. */
  305. public function getMathproblemsForTemplates()
  306. {
  307. return $this->mathproblemsForTemplates;
  308. }
  309. /**
  310. * @param $mathproblemsForTemplates
  311. */
  312. public function setMathproblemsForTemplates($mathproblemsForTemplates): void
  313. {
  314. $this->mathproblemsForTemplates = $mathproblemsForTemplates;
  315. }
  316. }