src/CoreBundle/Entity/WorksheetSolution.php line 14

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. /**
  7. * @ORM\Table("worksheet_solution")
  8. * @ORM\Entity(repositoryClass="CoreBundle\Entity\WorksheetSolutionRepository")
  9. */
  10. class WorksheetSolution
  11. {
  12. /**
  13. * @var int
  14. *
  15. * @ORM\Column(name="id", type="integer")
  16. * @ORM\Id
  17. * @ORM\GeneratedValue(strategy="AUTO")
  18. */
  19. private $id;
  20. /**
  21. * @var WorksheetUnit
  22. *
  23. * @ORM\ManyToOne(targetEntity="CoreBundle\Entity\WorksheetUnit", inversedBy="worksheetSolutions")
  24. */
  25. private $worksheetUnit;
  26. /**
  27. * @var Mathproblem
  28. *
  29. * @ORM\ManyToOne(targetEntity="CoreBundle\Entity\Mathproblem")
  30. */
  31. private $problem;
  32. /**
  33. * @var string
  34. *
  35. * @ORM\Column(name="solution_text", type="text", nullable=true)
  36. */
  37. private $solutionText;
  38. /**
  39. * @var string
  40. *
  41. * @ORM\Column(name="solution_result", type="text", nullable=true)
  42. */
  43. private $solutionResult;
  44. /**
  45. * @var Collection
  46. *
  47. * @ORM\OneToMany(targetEntity="WorksheetSolutionFile", mappedBy="worksheetSolution", cascade={"persist"})
  48. */
  49. private $worksheetSolutionFiles;
  50. /**
  51. * @var int
  52. *
  53. * @ORM\Column(type="smallint", nullable=true)
  54. */
  55. private $score;
  56. /**
  57. * @var string
  58. *
  59. * @ORM\Column(type="string", length=400, nullable=true)
  60. */
  61. private $comment;
  62. /**
  63. * @ORM\Column(type="datetime", nullable=true)
  64. *
  65. * @var \DateTime
  66. */
  67. private $updatedAt;
  68. /**
  69. * @var bool
  70. *
  71. * @ORM\Column(name="is_valid", type="boolean", nullable=true, options={"default":true})
  72. */
  73. private $isValid = true;
  74. /**
  75. * @var \DateTime
  76. *
  77. * @ORM\Column(name="archived_at", type="datetime", nullable=true)
  78. */
  79. private $archivedAt;
  80. /**
  81. * @var bool
  82. *
  83. * @ORM\Column(name="is_correct", type="boolean", nullable=true)
  84. */
  85. private $isCorrect;
  86. public function __construct()
  87. {
  88. $this->worksheetSolutionFiles = new ArrayCollection();
  89. }
  90. public function getId(): int
  91. {
  92. return $this->id;
  93. }
  94. public function getWorksheetUnit(): WorksheetUnit
  95. {
  96. return $this->worksheetUnit;
  97. }
  98. public function setWorksheetUnit(WorksheetUnit $worksheetUnit)
  99. {
  100. $this->worksheetUnit = $worksheetUnit;
  101. }
  102. public function getSolutionText(): ?string
  103. {
  104. return $this->solutionText;
  105. }
  106. /**
  107. * @param string $solutionText
  108. *
  109. * @throws \Exception
  110. */
  111. public function setSolutionText(?string $solutionText)
  112. {
  113. $this->solutionText = $solutionText;
  114. $this->updatedAt = new \DateTimeImmutable('now', new \DateTimeZone('Europe/Copenhagen'));
  115. }
  116. public function hasAnswer(): bool
  117. {
  118. return (bool)strlen($this->solutionText) || !empty($this->solutionResult) || $this->solutionResult === "0" || !$this->worksheetSolutionFiles->isEmpty();
  119. }
  120. public function getUpdatedAt(): ?\DateTimeInterface
  121. {
  122. return $this->updatedAt;
  123. }
  124. public function getProblem(): Mathproblem
  125. {
  126. return $this->problem;
  127. }
  128. public function setProblem(Mathproblem $problem)
  129. {
  130. $this->problem = $problem;
  131. }
  132. public function getScore(): ?int
  133. {
  134. return $this->score;
  135. }
  136. public function setScore(?int $score)
  137. {
  138. $this->score = $score;
  139. }
  140. public function getComment(): ?string
  141. {
  142. return $this->comment;
  143. }
  144. public function setComment(?string $comment)
  145. {
  146. $this->comment = $comment;
  147. }
  148. public function addWorksheetSolutionFile(WorksheetSolutionFile $worksheetSolutionFile)
  149. {
  150. if (null !== $worksheetSolutionFile->getFile()) {
  151. $worksheetSolutionFile->setWorksheetSolution($this);
  152. $this->worksheetSolutionFiles->add($worksheetSolutionFile);
  153. }
  154. }
  155. public function removeWorksheetSolutionFile(WorksheetSolutionFile $worksheetSolutionFile)
  156. {
  157. $this->worksheetSolutionFiles->removeElement($worksheetSolutionFile);
  158. }
  159. public function getWorksheetSolutionFiles(): Collection
  160. {
  161. return $this->worksheetSolutionFiles;
  162. }
  163. /**
  164. * @return bool
  165. */
  166. public function isValid(): bool
  167. {
  168. return $this->isValid;
  169. }
  170. /**
  171. * @param bool $isValid
  172. */
  173. public function setIsValid(bool $isValid): void
  174. {
  175. $this->isValid = $isValid;
  176. }
  177. /**
  178. * @return \DateTime|null
  179. */
  180. public function getArchivedAt(): ?\DateTime
  181. {
  182. return $this->archivedAt;
  183. }
  184. /**
  185. * @param \DateTime $archivedAt
  186. */
  187. public function setArchivedAt(\DateTime $archivedAt): void
  188. {
  189. $this->archivedAt = $archivedAt;
  190. }
  191. /**
  192. * @return string
  193. */
  194. public function getSolutionResult(): ?string
  195. {
  196. return $this->solutionResult;
  197. }
  198. /**
  199. * @param string|null $solutionResult
  200. */
  201. public function setSolutionResult(?string $solutionResult): void
  202. {
  203. $this->solutionResult = $solutionResult;
  204. }
  205. /**
  206. * @return bool|null
  207. */
  208. public function isCorrect(): ?bool
  209. {
  210. return $this->isCorrect;
  211. }
  212. /**
  213. * @param bool $isCorrect
  214. */
  215. public function setIsCorrect(bool $isCorrect): void
  216. {
  217. $this->isCorrect = $isCorrect;
  218. }
  219. }