<?php
namespace CoreBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use UserBundle\Entity\User;
/**
* @ORM\Table("worksheet_unit")
* @ORM\Entity(repositoryClass="CoreBundle\Entity\WorksheetUnitRepository")
*/
class WorksheetUnit
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var WorksheetSession
*
* @ORM\ManyToOne(targetEntity="CoreBundle\Entity\WorksheetSession", inversedBy="worksheetUnits")
* @ORM\JoinColumn(name="worksheet_session", referencedColumnName="id", onDelete="CASCADE")
*/
private $worksheetSession;
/**
* @var User
*
* @ORM\ManyToOne(targetEntity="UserBundle\Entity\User")
* @ORM\JoinColumn(name="student", referencedColumnName="id")
*/
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="CoreBundle\Entity\WorksheetSolution", 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;
}
/**
* @param \DateTime|null $deadline
*/
public function setDeadline(?\DateTime $deadline)
{
$this->deadline = $deadline;
}
/**
* @return \DateTime|null
*/
public function getExtendedDeadline(): ?\DateTime
{
return $this->extendedDeadline;
}
/**
* @param \DateTime $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;
}
}