src/CoreBundle/Entity/WorksheetUnit.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_unit")
  9. * @ORM\Entity(repositoryClass="CoreBundle\Entity\WorksheetUnitRepository")
  10. */
  11. class WorksheetUnit
  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 WorksheetSession
  23. *
  24. * @ORM\ManyToOne(targetEntity="CoreBundle\Entity\WorksheetSession", inversedBy="worksheetUnits")
  25. * @ORM\JoinColumn(name="worksheet_session", referencedColumnName="id", onDelete="CASCADE")
  26. */
  27. private $worksheetSession;
  28. /**
  29. * @var User
  30. *
  31. * @ORM\ManyToOne(targetEntity="UserBundle\Entity\User")
  32. * @ORM\JoinColumn(name="student", referencedColumnName="id")
  33. */
  34. private $student;
  35. /**
  36. * @var \DateTime
  37. * @ORM\Column(name="deadline", type="datetime", nullable=true)
  38. */
  39. private $deadline;
  40. /**
  41. * @var bool
  42. * @ORM\Column(name="finished", type="boolean", options={"default" : false})
  43. */
  44. private $finished;
  45. /**
  46. * @var Collection
  47. *
  48. * @ORM\OneToMany(targetEntity="CoreBundle\Entity\WorksheetSolution", mappedBy="worksheetUnit", cascade={"persist"})
  49. */
  50. private $worksheetSolutions;
  51. /**
  52. * @var \DateTime
  53. *
  54. * @ORM\Column(name="extended_deadline", type="datetime", nullable=true)
  55. */
  56. private $extendedDeadline;
  57. /**
  58. * @var string
  59. *
  60. * @ORM\Column(name="mathproblems_data", type="string", length=2048, nullable=true)
  61. */
  62. private $mathproblemsData;
  63. public function __construct()
  64. {
  65. $this->worksheetSolutions = new ArrayCollection();
  66. }
  67. /**
  68. * @return int
  69. */
  70. public function getId()
  71. {
  72. return $this->id;
  73. }
  74. /**
  75. * @return WorksheetSession
  76. */
  77. public function getWorksheetSession()
  78. {
  79. return $this->worksheetSession;
  80. }
  81. /**
  82. * @param WorksheetSession $worksheetSession
  83. *
  84. * @return $this
  85. */
  86. public function setWorksheetSession($worksheetSession)
  87. {
  88. $this->worksheetSession = $worksheetSession;
  89. return $this;
  90. }
  91. /**
  92. * @return User
  93. */
  94. public function getStudent()
  95. {
  96. return $this->student;
  97. }
  98. /**
  99. * @param User $student
  100. *
  101. * @return $this
  102. */
  103. public function setStudent($student)
  104. {
  105. $this->student = $student;
  106. return $this;
  107. }
  108. public function getWorksheetSolutions(): Collection
  109. {
  110. return $this->worksheetSolutions;
  111. }
  112. /**
  113. * @return array
  114. */
  115. public function getValidWorksheetSolutions()
  116. {
  117. $worksheetSolutions = [];
  118. foreach ($this->worksheetSolutions as $response) {
  119. if ($response->isValid()) {
  120. $worksheetSolutions[] = $response;
  121. }
  122. }
  123. return $worksheetSolutions;
  124. }
  125. public function getSortedWorksheetSolutions($problemOrder)
  126. {
  127. $worksheetSolutions = $this->getValidWorksheetSolutions();
  128. if ($problemOrder && count($problemOrder) == count($worksheetSolutions)) {
  129. $newWorksheetSolutions = [];
  130. foreach ($worksheetSolutions as $ws) {
  131. $newkey = array_search($ws->getProblem()->getID(), $problemOrder);
  132. $newWorksheetSolutions[$newkey] = $ws;
  133. }
  134. ksort($newWorksheetSolutions);
  135. return $newWorksheetSolutions;
  136. } else {
  137. return $this->getValidWorksheetSolutions();
  138. }
  139. }
  140. public function isFinished(): bool
  141. {
  142. return $this->finished;
  143. }
  144. public function setFinished(bool $finished)
  145. {
  146. $this->finished = $finished;
  147. }
  148. /**
  149. * @return \DateTime | null
  150. */
  151. public function getDeadline()
  152. {
  153. return $this->deadline;
  154. }
  155. /**
  156. * @param \DateTime|null $deadline
  157. */
  158. public function setDeadline(?\DateTime $deadline)
  159. {
  160. $this->deadline = $deadline;
  161. }
  162. /**
  163. * @return \DateTime|null
  164. */
  165. public function getExtendedDeadline(): ?\DateTime
  166. {
  167. return $this->extendedDeadline;
  168. }
  169. /**
  170. * @param \DateTime $extendedDeadline
  171. */
  172. public function setExtendedDeadline(\DateTime $extendedDeadline): void
  173. {
  174. $this->extendedDeadline = $extendedDeadline;
  175. }
  176. /**
  177. * @return string|null
  178. */
  179. public function getMathproblemsData()
  180. {
  181. return $this->mathproblemsData;
  182. }
  183. /**
  184. * @param $mathproblemsData
  185. */
  186. public function setMathproblemsData($mathproblemsData): void
  187. {
  188. $this->mathproblemsData = $mathproblemsData;
  189. }
  190. }