<?php
namespace App\Entity\Core\Homework;
use App\Entity\Core\Classroom\Classroom;
use App\Entity\Core\Classroom\ClassroomType;
use App\Entity\Core\Session\SessionInterface;
use App\Entity\Core\Session\SessionType;
use App\Entity\Core\TagMathproblem;
use App\Entity\Core\Topic\Topic;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use JsonSerializable;
#[ORM\Table('homework')]
#[ORM\Entity(repositoryClass: HomeworkRepository::class)]
class Homework extends SessionType implements SessionInterface, JsonSerializable
{
/**
* @var Classroom
*/
#[ORM\JoinColumn(name: 'classroom', referencedColumnName: 'id', onDelete: 'CASCADE')]
#[ORM\ManyToOne(targetEntity: Classroom::class, inversedBy: 'sessions')]
private $classroom;
#[ORM\ManyToOne(targetEntity: ClassroomType::class)]
#[ORM\JoinColumn(name: 'selected_classroom_type', referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
private ?ClassroomType $selectedClassroomType = null;
/**
* @var ArrayCollection|Topic[]
*/
#[ORM\JoinTable(name: 'homework_topic')]
#[ORM\JoinColumn(name: 'homework', referencedColumnName: 'id')]
#[ORM\InverseJoinColumn(name: 'topic', referencedColumnName: 'id')]
#[ORM\ManyToMany(targetEntity: Topic::class, inversedBy: 'sessions')]
private $topics;
/**
* @var ArrayCollection|TagMathproblem[]
*/
#[ORM\JoinTable(name: 'homework_tag')]
#[ORM\JoinColumn(name: 'homework', referencedColumnName: 'id')]
#[ORM\InverseJoinColumn(name: 'tag', referencedColumnName: 'id')]
#[ORM\ManyToMany(targetEntity: TagMathproblem::class)]
private $tags;
/**
* @var HomeworkUnit[]
*/
#[ORM\OneToMany(targetEntity: HomeworkUnit::class, 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)
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;
}
public function getSelectedClassroomType(): ?ClassroomType
{
return $this->selectedClassroomType;
}
public function setSelectedClassroomType(?ClassroomType $selectedClassroomType): self
{
$this->selectedClassroomType = $selectedClassroomType;
return $this;
}
/**
* @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;
}
public function hasManyTopics(): int
{
return $this->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->toArray()
];
}
}