<?php
namespace CoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use JsonSerializable;
/**
* @ORM\Table("homework")
* @ORM\Entity(repositoryClass="CoreBundle\Entity\HomeworkRepository")
*/
class Homework extends SessionType implements SessionInterface, JsonSerializable
{
/**
* @var Classroom
*
* @ORM\ManyToOne(targetEntity="Classroom", inversedBy="sessions")
* @ORM\JoinColumn(name="classroom", referencedColumnName="id", onDelete="CASCADE")
*/
private $classroom;
/**
* @var ArrayCollection|Topic[]
*
* @ORM\ManyToMany(targetEntity="Topic", inversedBy="sessions")
* @ORM\JoinTable(name="homework_topic",
* joinColumns={@ORM\JoinColumn(name="homework", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="topic", referencedColumnName="id")})
*/
private $topics;
/**
* @var ArrayCollection|TagMathproblem[]
*
* @ORM\ManyToMany(targetEntity="TagMathproblem")
* @ORM\JoinTable(name="homework_tag",
* joinColumns={@ORM\JoinColumn(name="homework", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="tag", referencedColumnName="id")})
*/
private $tags;
/**
* @var HomeworkUnit[]
*
* @ORM\OneToMany(targetEntity="HomeworkUnit",
* mappedBy="homework", cascade={"persist","remove"})
*/
private $homeworkUnits;
/**
* @ORM\Column(type="integer", nullable=true, options={"default"=0})
*/
private $status = 0;
/**
* @ORM\Column(type="integer")
*/
private $templateCount;
/**
* @ORM\Column(type="integer")
*/
private $assistance;
/**
* @ORM\Column(type="boolean")
*/
private $canPause = true;
/**
* @ORM\Column(name="has_many_topics", type="integer", nullable=true, options={"default"=0})
*
* hasManyTopics = 0 (count of topics <= 3)
* hasManyTopics = 1 (count of topics > 3)
*/
private $hasManyTopics = 0;
/**
* @ORM\Column(name="start_difficulty", type="integer", nullable=true)
*/
private $startDifficulty;
public function __construct()
{
$this->homeworkUnits = new ArrayCollection();
$this->topics = new ArrayCollection();
$this->tags = new ArrayCollection();
$this->deadline = new \DateTime("now");
}
/**
* @return Classroom
*/
public function getClassroom()
{
return $this->classroom;
}
/**
* @param Classroom $classroom
*/
public function setClassroom($classroom)
{
$this->classroom = $classroom;
}
/**
* @return Topic[]|ArrayCollection
*/
public function getTopics(): Collection
{
return $this->topics;
}
/**
* @param Topic[]|ArrayCollection $topics
*/
public function setTopics($topics)
{
$this->topics = $topics;
}
/**
* @return TagMathproblem[]|ArrayCollection
*/
public function getTags(): Collection
{
return $this->tags;
}
/**
* @param TagMathproblem[]|ArrayCollection $tags
*/
public function setTags($tags)
{
$this->tags = $tags;
}
/**
* @return HomeworkUnit[]
*/
public function getHomeworkUnits()
{
return $this->homeworkUnits;
}
/**
* @param HomeworkUnit[] $homeworkUnits
*/
public function setHomeworkUnits($homeworkUnits)
{
$this->homeworkUnits = $homeworkUnits;
}
/**
* @return mixed
*/
public function getStatus()
{
return $this->status;
}
/**
* @param mixed $status
*/
public function setStatus($status)
{
$this->status = $status;
}
public function getTemplateCount()
{
return $this->templateCount;
}
public function setTemplateCount($count)
{
$this->templateCount = $count;
}
public function getAssistance()
{
return $this->assistance;
}
/**
* @param mixed $assistance
*/
public function setAssistance($assistance)
{
$this->assistance = $assistance;
}
public function canPause(): bool
{
return $this->canPause;
}
/**
* @param mixed $canPause
* @return $this
*/
public function setCanPause($canPause)
{
$this->canPause = $canPause;
return $this;
}
/**
* @return int
*/
public function hasManyTopics(): int
{
return $this->hasManyTopics;
}
/**
* @param int $hasManyTopics
*/
public function setHasManyTopics(int $hasManyTopics): void
{
$this->hasManyTopics = $hasManyTopics;
}
/**
* @return mixed
*/
public function getStartDifficulty()
{
return $this->startDifficulty;
}
/**
* @param mixed $startDifficulty
*/
public function setStartDifficulty($startDifficulty): void
{
$this->startDifficulty = $startDifficulty;
}
public function jsonSerialize(): mixed
{
return [
'id' => $this->id,
'name' => $this->name,
'startTime' => $this->startTime,
'deadline' => $this->deadline,
'duration' => $this->duration,
'status' => $this->status,
'assistance' => $this->assistance,
'canPause' => $this->canPause,
'classroom' => $this->classroom,
'hasManyTopics' => $this->hasManyTopics,
'homeworkUnits' => $this->homeworkUnits->toArray(),
'startDifficulty' => $this->startDifficulty,
'tags' => $this->tags->toArray(),
'templateCount' => $this->templateCount,
'topics' => $this->topics
];
}
}