<?php
namespace CoreBundle\Entity;
use CoreBundle\Session\SessionUnitInterface;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use UserBundle\Entity\User;
use JsonSerializable;
/**
* @ORM\Table("homework_unit")
* @ORM\Entity(repositoryClass="CoreBundle\Entity\HomeworkUnitRepository")
*/
class HomeworkUnit implements TopicCounterInterface, JsonSerializable, SessionUnitInterface
{
use TopicCounterTrait;
public function getParent(): Homework
{
return $this->getHomework();
}
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var int
*
* @ORM\Column(name="current_difficulty", type="integer", options={"default":3})
*/
private $currentDifficulty;
/**
* @var int
*
* @ORM\Column(name="prev_answer_correct", nullable=true, type="boolean", options={"default":false})
*/
private $prevAnswerCorrect;
/**
* @var int
*
* @ORM\Column(name="prev_difficulty", type="integer", nullable=true, options={"default":1})
*/
private $prevDifficulty;
/**
* @var Homework
*
* @ORM\ManyToOne(targetEntity="CoreBundle\Entity\Homework", inversedBy="homeworkUnits")
* @ORM\JoinColumn(name="homework", referencedColumnName="id", onDelete="CASCADE")
*/
private $homework;
/**
* @var User
*
* @ORM\ManyToOne(targetEntity="UserBundle\Entity\User", cascade={"persist","remove"})
*/
private $student;
/**
* @var HomeworkResponse[]
*
* @ORM\OneToMany(targetEntity="HomeworkResponse",
* mappedBy="homeworkUnit", cascade={"persist","remove"})
*/
private $homeworkResponses;
/**
* @var DateTime
*
* @ORM\Column(name="startTime", type="datetime", nullable=true)
*/
private $startTime;
/**
* @var DateTime
*
* @ORM\Column(name="deadline", type="datetime", nullable=true)
*/
private $deadline;
/**
* @var int
*
* @ORM\Column(name="seconds_left", type="integer", nullable=true, options={"default":0})
*/
private $secondsLeft;
/**
* @var int
*
* @ORM\Column(name="seconds_paused", type="integer", nullable=false, options={"default":0})
*/
private $secondsPaused;
/**
* @var DateTime
*
* @ORM\Column(name="time_paused", type="datetime", nullable=true)
*/
private $timePaused;
/**
* @var DateTime
*
* @ORM\Column(name="time_resumed", type="datetime", nullable=true)
*/
private $timeResumed;
/**
* @var \DateTime
*
* @ORM\Column(name="extended_deadline", type="datetime", nullable=true)
*/
private $extendedDeadline;
public function __construct()
{
$this->homeworkResponses = new ArrayCollection();
}
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @param int $id
*/
public function setId($id)
{
$this->id = $id;
}
/**
* @return int
*/
public function getCurrentDifficulty()
{
return $this->currentDifficulty;
}
/**
* @param int $currentDifficulty
*/
public function setCurrentDifficulty($currentDifficulty)
{
$this->currentDifficulty = $currentDifficulty;
}
/**
* @return int
*/
public function getPrevAnswerCorrect()
{
return $this->prevAnswerCorrect;
}
/**
* @param int $prevAnswerCorrect
*/
public function setPrevAnswerCorrect($prevAnswerCorrect)
{
$this->prevAnswerCorrect = $prevAnswerCorrect;
}
/**
* @return int
*/
public function getPrevDifficulty()
{
return $this->prevDifficulty;
}
/**
* @param int $prevDifficulty
*/
public function setPrevDifficulty($prevDifficulty)
{
$this->prevDifficulty = $prevDifficulty;
}
/**
* @return Homework
*/
public function getHomework()
{
return $this->homework;
}
/**
* @param Homework $homework
*/
public function setHomework($homework)
{
$this->homework = $homework;
}
public function getSession(): ?Homework
{
return $this->homework;
}
/**
* @return User
*/
public function getStudent()
{
return $this->student;
}
/**
* @param User $student
*/
public function setStudent($student)
{
$this->student = $student;
}
public function getStartTime(): ?DateTime
{
return $this->startTime;
}
/**
* @param DateTime $startTime
*/
public function setStartTime(?DateTime $startTime)
{
$this->startTime = $startTime;
}
/**
* @return HomeworkResponse[]
*/
public function getHomeworkResponses()
{
return $this->homeworkResponses;
}
/**
* @return array
*/
public function getValidHomeworkResponses()
{
$homeworkResponses = [];
foreach ($this->homeworkResponses as $response) {
if ($response->isValid()) {
$homeworkResponses[] = $response;
}
}
return $homeworkResponses;
}
/**
* @param HomeworkResponse[] $homeworkResponses
*/
public function setHomeworkResponses($homeworkResponses)
{
$this->homeworkResponses = $homeworkResponses;
}
/**
* @return DateTime
*/
public function getDeadline(): DateTime
{
return $this->deadline;
}
/**
* @param DateTime $deadline
* @return $this
*/
public function setDeadline($deadline)
{
$this->deadline = $deadline;
return $this;
}
public function isPaused(): bool
{
return $this->timePaused > $this->timeResumed;
}
public function getSecondsLeft(): int
{
return $this->secondsLeft;
}
public function setSecondsLeft(?int $secondsLeft)
{
$this->secondsLeft = $secondsLeft;
}
public function getSecondsPaused(): int
{
return $this->secondsPaused;
}
public function setSecondsPaused(int $secondsPaused)
{
$this->secondsPaused = $secondsPaused;
}
public function addSecondsPaused(int $secondsPaused)
{
$this->secondsPaused += $secondsPaused;
}
public function getTimePaused(): ?DateTime
{
return $this->timePaused;
}
public function setTimePaused(?DateTime $timePaused)
{
$this->timePaused = $timePaused;
}
public function getTimeResumed(): ?DateTime
{
return $this->timeResumed;
}
public function setTimeResumed(?DateTime $timeResumed)
{
$this->timeResumed = $timeResumed;
}
/**
* @return DateTime|null
*/
public function getExtendedDeadline(): ?\DateTime
{
return $this->extendedDeadline;
}
/**
* @param DateTime $extendedDeadline
*/
public function setExtendedDeadline(DateTime $extendedDeadline): void
{
$this->extendedDeadline = $extendedDeadline;
}
public function jsonSerialize(): mixed
{
return [
'id' => $this->id,
'startTime' => $this->startTime,
'deadline' => $this->deadline,
'student' => $this->student,
'currentDifficulty' => $this->currentDifficulty,
'extendedDeadline' => $this->extendedDeadline,
'prevAnswerCorrect' => $this->prevAnswerCorrect,
'prevDifficulty' => $this->prevDifficulty,
'secondsLeft' => $this->secondsLeft,
'secondsPaused' => $this->secondsPaused,
'timePaused' => $this->timePaused,
'timeResumed' => $this->timeResumed,
'currentTopicNr' => $this->currentTopicNr
];
}
}