src/Entity/Core/Worksheet/WorksheetSolution.php line 18

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