<?php
namespace CoreBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table("worksheet_solution")
* @ORM\Entity(repositoryClass="CoreBundle\Entity\WorksheetSolutionRepository")
*/
class WorksheetSolution
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var WorksheetUnit
*
* @ORM\ManyToOne(targetEntity="CoreBundle\Entity\WorksheetUnit", inversedBy="worksheetSolutions")
*/
private $worksheetUnit;
/**
* @var Mathproblem
*
* @ORM\ManyToOne(targetEntity="CoreBundle\Entity\Mathproblem")
*/
private $problem;
/**
* @var string
*
* @ORM\Column(name="solution_text", type="text", nullable=true)
*/
private $solutionText;
/**
* @var string
*
* @ORM\Column(name="solution_result", type="text", nullable=true)
*/
private $solutionResult;
/**
* @var Collection
*
* @ORM\OneToMany(targetEntity="WorksheetSolutionFile", mappedBy="worksheetSolution", cascade={"persist"})
*/
private $worksheetSolutionFiles;
/**
* @var int
*
* @ORM\Column(type="smallint", nullable=true)
*/
private $score;
/**
* @var string
*
* @ORM\Column(type="string", length=400, nullable=true)
*/
private $comment;
/**
* @ORM\Column(type="datetime", nullable=true)
*
* @var \DateTime
*/
private $updatedAt;
/**
* @var bool
*
* @ORM\Column(name="is_valid", type="boolean", nullable=true, options={"default":true})
*/
private $isValid = true;
/**
* @var \DateTime
*
* @ORM\Column(name="archived_at", type="datetime", nullable=true)
*/
private $archivedAt;
/**
* @var bool
*
* @ORM\Column(name="is_correct", type="boolean", nullable=true)
*/
private $isCorrect;
public function __construct()
{
$this->worksheetSolutionFiles = new ArrayCollection();
}
public function getId(): int
{
return $this->id;
}
public function getWorksheetUnit(): WorksheetUnit
{
return $this->worksheetUnit;
}
public function setWorksheetUnit(WorksheetUnit $worksheetUnit)
{
$this->worksheetUnit = $worksheetUnit;
}
public function getSolutionText(): ?string
{
return $this->solutionText;
}
/**
* @param string $solutionText
*
* @throws \Exception
*/
public function setSolutionText(?string $solutionText)
{
$this->solutionText = $solutionText;
$this->updatedAt = new \DateTimeImmutable('now', new \DateTimeZone('Europe/Copenhagen'));
}
public function hasAnswer(): bool
{
return (bool)strlen($this->solutionText) || !empty($this->solutionResult) || $this->solutionResult === "0" || !$this->worksheetSolutionFiles->isEmpty();
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function getProblem(): Mathproblem
{
return $this->problem;
}
public function setProblem(Mathproblem $problem)
{
$this->problem = $problem;
}
public function getScore(): ?int
{
return $this->score;
}
public function setScore(?int $score)
{
$this->score = $score;
}
public function getComment(): ?string
{
return $this->comment;
}
public function setComment(?string $comment)
{
$this->comment = $comment;
}
public function addWorksheetSolutionFile(WorksheetSolutionFile $worksheetSolutionFile)
{
if (null !== $worksheetSolutionFile->getFile()) {
$worksheetSolutionFile->setWorksheetSolution($this);
$this->worksheetSolutionFiles->add($worksheetSolutionFile);
}
}
public function removeWorksheetSolutionFile(WorksheetSolutionFile $worksheetSolutionFile)
{
$this->worksheetSolutionFiles->removeElement($worksheetSolutionFile);
}
public function getWorksheetSolutionFiles(): Collection
{
return $this->worksheetSolutionFiles;
}
/**
* @return bool
*/
public function isValid(): bool
{
return $this->isValid;
}
/**
* @param bool $isValid
*/
public function setIsValid(bool $isValid): void
{
$this->isValid = $isValid;
}
/**
* @return \DateTime|null
*/
public function getArchivedAt(): ?\DateTime
{
return $this->archivedAt;
}
/**
* @param \DateTime $archivedAt
*/
public function setArchivedAt(\DateTime $archivedAt): void
{
$this->archivedAt = $archivedAt;
}
/**
* @return string
*/
public function getSolutionResult(): ?string
{
return $this->solutionResult;
}
/**
* @param string|null $solutionResult
*/
public function setSolutionResult(?string $solutionResult): void
{
$this->solutionResult = $solutionResult;
}
/**
* @return bool|null
*/
public function isCorrect(): ?bool
{
return $this->isCorrect;
}
/**
* @param bool $isCorrect
*/
public function setIsCorrect(bool $isCorrect): void
{
$this->isCorrect = $isCorrect;
}
}