<?php
namespace App\Entity\Core\Worksheet;
use App\Entity\User\User;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Table('worksheet_unit')]
#[ORM\Entity(repositoryClass: WorksheetUnitRepository::class)]
class WorksheetUnit
{
/**
* @var int
*/
#[ORM\Column(name: 'id', type: 'integer')]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'AUTO')]
private $id;
/**
* @var WorksheetSession
*/
#[ORM\JoinColumn(name: 'worksheet_session', referencedColumnName: 'id', onDelete: 'CASCADE')]
#[ORM\ManyToOne(targetEntity: WorksheetSession::class, inversedBy: 'worksheetUnits')]
private $worksheetSession;
/**
* @var User
*/
#[ORM\JoinColumn(name: 'student', referencedColumnName: 'id')]
#[ORM\ManyToOne(targetEntity: User::class)]
private $student;
/**
* @var DateTime
*/
#[ORM\Column(name: 'deadline', type: 'datetime', nullable: true)]
private $deadline;
/**
* @var bool
*/
#[ORM\Column(name: 'finished', type: 'boolean', options: ['default' => false])]
private $finished;
/**
* @var Collection
*/
#[ORM\OneToMany(targetEntity: WorksheetSolution::class, mappedBy: 'worksheetUnit', cascade: ['persist'])]
private $worksheetSolutions;
/**
* @var DateTime
*/
#[ORM\Column(name: 'extended_deadline', type: 'datetime', nullable: true)]
private $extendedDeadline;
/**
* @var string
*/
#[ORM\Column(name: 'mathproblems_data', type: 'string', length: 2048, nullable: true)]
private $mathproblemsData;
public function __construct()
{
$this->worksheetSolutions = new ArrayCollection();
}
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @return WorksheetSession
*/
public function getWorksheetSession()
{
return $this->worksheetSession;
}
/**
* @param WorksheetSession $worksheetSession
*
* @return $this
*/
public function setWorksheetSession($worksheetSession)
{
$this->worksheetSession = $worksheetSession;
return $this;
}
/**
* @return User
*/
public function getStudent()
{
return $this->student;
}
/**
* @param User $student
*
* @return $this
*/
public function setStudent($student)
{
$this->student = $student;
return $this;
}
public function getWorksheetSolutions(): Collection
{
return $this->worksheetSolutions;
}
/**
* @return array
*/
public function getValidWorksheetSolutions()
{
$worksheetSolutions = [];
foreach ($this->worksheetSolutions as $response) {
if ($response->isValid()) {
$worksheetSolutions[] = $response;
}
}
return $worksheetSolutions;
}
public function getSortedWorksheetSolutions($problemOrder)
{
$worksheetSolutions = $this->getValidWorksheetSolutions();
if ($problemOrder && count($problemOrder) == count($worksheetSolutions)) {
$newWorksheetSolutions = [];
foreach ($worksheetSolutions as $ws) {
$newkey = array_search($ws->getProblem()->getID(), $problemOrder);
$newWorksheetSolutions[$newkey] = $ws;
}
ksort($newWorksheetSolutions);
return $newWorksheetSolutions;
} else {
return $this->getValidWorksheetSolutions();
}
}
public function isFinished(): bool
{
return $this->finished;
}
public function setFinished(bool $finished)
{
$this->finished = $finished;
}
/**
* @return DateTime | null
*/
public function getDeadline()
{
return $this->deadline;
}
public function setDeadline(?DateTime $deadline)
{
$this->deadline = $deadline;
}
public function getExtendedDeadline(): ?DateTime
{
return $this->extendedDeadline;
}
public function setExtendedDeadline(DateTime $extendedDeadline): void
{
$this->extendedDeadline = $extendedDeadline;
}
/**
* @return string|null
*/
public function getMathproblemsData()
{
return $this->mathproblemsData;
}
/**
* @param $mathproblemsData
*/
public function setMathproblemsData($mathproblemsData): void
{
$this->mathproblemsData = $mathproblemsData;
}
}