src/Entity/Core/Worksheet/WorksheetUnit.php line 14

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