<?php
namespace App\Entity\Core\Worksheet;
use App\Entity\Core\Mathproblem;
use DateTime;
use DateTimeImmutable;
use DateTimeInterface;
use DateTimeZone;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Exception;
#[ORM\Table('worksheet_solution')]
#[ORM\Entity(repositoryClass: WorksheetSolutionRepository::class)]
class WorksheetSolution
{
/**
* @var int
*/
#[ORM\Column(name: 'id', type: 'integer')]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
private $id;
/**
* @var WorksheetUnit
*/
#[ORM\ManyToOne(targetEntity: WorksheetUnit::class, inversedBy: 'worksheetSolutions')]
private $worksheetUnit;
/**
* @var Mathproblem
*/
#[ORM\ManyToOne(targetEntity: Mathproblem::class)]
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::class, 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;
/**
* @var DateTime
*/
#[ORM\Column(type: 'datetime', nullable: true)]
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;
}
public function isValid(): bool
{
return $this->isValid;
}
public function setIsValid(bool $isValid): void
{
$this->isValid = $isValid;
}
public function getArchivedAt(): ?DateTime
{
return $this->archivedAt;
}
public function setArchivedAt(DateTime $archivedAt): void
{
$this->archivedAt = $archivedAt;
}
/**
* @return string
*/
public function getSolutionResult(): ?string
{
return $this->solutionResult;
}
public function setSolutionResult(?string $solutionResult): void
{
$this->solutionResult = $solutionResult;
}
public function isCorrect(): ?bool
{
return $this->isCorrect;
}
public function setIsCorrect(bool $isCorrect): void
{
$this->isCorrect = $isCorrect;
}
}