<?php
namespace App\Entity\Core\Session;
use App\Entity\Core\Classroom\Classroom;
use App\Entity\Core\Classroom\ClassroomType;
use App\Entity\Core\Pretest;
use App\Entity\Core\PretestResponse;
use App\Entity\Core\SelfStudy\SelfStudyTopic;
use App\Entity\Core\TagMathproblem;
use App\Entity\Core\Topic\Topic;
use App\Entity\Core\Training\TrainingUnit;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use JsonSerializable;
#[ORM\Table('session')]
#[ORM\Entity(repositoryClass: SessionRepository::class)]
class Session 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: 'session_topic')]
#[ORM\JoinColumn(name: 'session', referencedColumnName: 'id')]
#[ORM\InverseJoinColumn(name: 'topic', referencedColumnName: 'id')]
#[ORM\ManyToMany(targetEntity: Topic::class, inversedBy: 'sessions')]
private $topics;
/**
* @var ArrayCollection
*/
#[ORM\JoinTable(name: 'session_tag')]
#[ORM\JoinColumn(name: 'session', referencedColumnName: 'id')]
#[ORM\InverseJoinColumn(name: 'tag', referencedColumnName: 'id')]
#[ORM\ManyToMany(targetEntity: TagMathproblem::class)]
private $tags;
/**
* @var bool
*/
#[ORM\Column(name: 'dormant', type: 'boolean')]
private $dormant = false;
/**
* @var Pretest
*/
#[ORM\JoinColumn(name: 'pretest', referencedColumnName: 'id', nullable: true, onDelete: 'CASCADE')]
#[ORM\ManyToOne(targetEntity: Pretest::class)]
private $pretest;
#[ORM\Column(type: 'integer', nullable: true)]
private $pretestDuration;
#[ORM\Column(type: 'integer', nullable: true, options: ['default' => 1])]
private $groupSize = 1;
#[ORM\Column(type: 'boolean', nullable: true)]
private $usePretest;
#[ORM\OneToMany(targetEntity: TrainingUnit::class, mappedBy: 'session', cascade: ['persist', 'remove'])]
private Collection $TrainingUnits;
/**
* @var PretestResponse[]
*/
#[ORM\OneToMany(targetEntity: PretestResponse::class, mappedBy: 'session', cascade: ['persist', 'remove'])]
private $PretestResponses;
/**
* @var ArrayCollection|SessionStudent[]
*/
#[ORM\OneToMany(targetEntity: SessionStudent::class, mappedBy: 'session', cascade: ['persist', 'remove'])]
private $students;
#[ORM\Column(type: 'integer', nullable: true, options: ['default' => 0])]
private $status = 0;
#[ORM\Column(type: 'integer')]
private $templateCount;
// assistance = 1 (both CAS and no CAS)
#[ORM\Column(type: 'integer')]
private $assistance;
/**
* @var bool
*/
#[ORM\Column(name: 'is_self_study', type: 'boolean', nullable: true, options: ['default' => false])]
private $isSelfStudy;
// hasManyTopics = 0 (count of topics <= 3)
#[ORM\Column(name: 'has_many_topics', type: 'integer', nullable: true, options: ['default' => 0])]
private $hasManyTopics = 0;
/**
* @var SelfStudyTopic
*/
#[ORM\JoinColumn(name: 'self_study_topic', referencedColumnName: 'id')]
#[ORM\ManyToOne(targetEntity: SelfStudyTopic::class)]
private $selfStudyTopic = null;
#[ORM\Column(name: 'start_difficulty', type: 'integer', nullable: true)]
private $startDifficulty;
public function __construct()
{
$this->TrainingUnits = new ArrayCollection();
$this->PretestResponses = new ArrayCollection();
$this->topics = new ArrayCollection();
$this->tags = new ArrayCollection();
$this->students = new ArrayCollection();
}
/**
* Set classroom.
*
* @param Classroom $classroom
*
* @return Session
*/
public function setClassroom($classroom)
{
$this->classroom = $classroom;
return $this;
}
/**
* Get classroom.
*
* @return Classroom
*/
public function getClassroom()
{
return $this->classroom;
}
public function getSelectedClassroomType(): ?ClassroomType
{
return $this->selectedClassroomType;
}
public function setSelectedClassroomType(?ClassroomType $selectedClassroomType): self
{
$this->selectedClassroomType = $selectedClassroomType;
return $this;
}
/**
* @param Topic[] $topics
*/
public function setTopics(array $topics)
{
$this->topics = $topics;
}
public function getTopics(): Collection
{
return $this->topics;
}
/**
* @return Session
*/
public function addTopic(Topic $topic)
{
$this->topics->add($topic);
return $this;
}
/**
* @return bool
*/
public function removeTopic(Topic $topic)
{
return $this->topics->removeElement($topic);
}
public function getTags(): Collection
{
return $this->tags;
}
/**
* @return Session
*/
public function addTag(TagMathproblem $tag)
{
$this->tags->add($tag);
return $this;
}
/**
* @param TagMathproblem[] $tags
*/
public function setTags(array $tags)
{
$this->tags = $tags;
}
/**
* @return bool
*/
public function removeTag(TagMathproblem $tag)
{
return $this->tags->removeElement($tag);
}
public function isDormant()
{
return $this->dormant;
}
public function setDormant($dormant)
{
$this->dormant = $dormant;
}
/**
* Set pretest.
*
* @param Pretest $pretest
*
* @return Session
*/
public function setPretest($pretest)
{
$this->pretest = $pretest;
return $this;
}
/**
* Get pretest.
*
* @return Pretest
*/
public function getPretest()
{
return $this->pretest;
}
/**
* Set Duration.
*
* @param int $duration
*
* @return Session
*/
public function setDuration($duration)
{
$this->duration = $duration;
return $this;
}
/**
* Get duration.
*
* @return int
*/
public function getDuration()
{
return $this->duration;
}
/**
* Set groupSize.
*
* @param int $groupSize
*
* @return Session
*/
public function setGroupSize($groupSize)
{
$this->groupSize = $groupSize;
return $this;
}
/**
* Get groupSize.
*
* @return int
*/
public function getGroupSize()
{
return $this->groupSize;
}
/**
* Set pretestDuration.
*
* @param int $pretestDuration
*
* @return Session
*/
public function setPretestDuration($pretestDuration)
{
$this->pretestDuration = $pretestDuration;
return $this;
}
/**
* Get pretestDuration
*
* @return int
*/
public function getPretestDuration()
{
return $this->pretestDuration;
}
/**
* Set usePretest.
*
* @param int $usePretest
*
* @return Session
*/
public function setUsePretest($usePretest)
{
$this->usePretest = $usePretest;
return $this;
}
/**
* Get usePretest.
*
* @return boolean
*/
public function getUsePretest()
{
return $this->usePretest;
}
/**
* @return ArrayCollection|TrainingUnit[]
*/
public function getTrainingUnits(): Collection
{
return $this->TrainingUnits;
}
/**
* @return Session
*/
public function addTrainingUnit(TrainingUnit $TrainingUnit)
{
$TrainingUnit->setSession($this);
$this->TrainingUnits->add($TrainingUnit);
return $this;
}
/**
* @return bool
*/
public function removeTrainingUnit(TrainingUnit $TrainingUnit)
{
$TrainingUnit->setSession(null);
return $this->TrainingUnits->removeElement($TrainingUnit);
}
/**
* @return PretestResponse[]
*/
public function getPretestResponses()
{
return $this->PretestResponses;
}
/**
* @return Session
*/
public function addPretestResponse(PretestResponse $PretestResponse)
{
$PretestResponse->setSession($this);
$this->PretestResponses->add($PretestResponse);
return $this;
}
/**
* @return bool
*/
public function removePretestResponse(PretestResponse $PretestResponse)
{
$PretestResponse->setSession(null);
return $this->PretestResponses->removeElement($PretestResponse);
}
/**
* @return SessionStudent[]
*/
public function getStudents()
{
return $this->students;
}
/**
* @return Session
*/
public function addStudent(SessionStudent $student)
{
$this->students->add($student);
return $this;
}
/**
* @return bool
*/
public function removeStudent(SessionStudent $student)
{
$student->setSession(null);
return $this->students->removeElement($student);
}
public function getStatus(): ?int
{
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;
}
/**
* @return bool | null
*/
public function isSelfStudy()
{
return $this->isSelfStudy;
}
public function setIsSelfStudy(bool $isSelfStudy)
{
$this->isSelfStudy = $isSelfStudy;
}
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 getSelfStudyTopic(): ?SelfStudyTopic
{
return $this->selfStudyTopic;
}
public function setSelfStudyTopic(?SelfStudyTopic $selfStudyTopic): void
{
$this->selfStudyTopic = $selfStudyTopic;
}
public function jsonSerialize(): mixed
{
return [
"id" => $this->getId(),
"duration" => $this->getDuration(),
"tags" => $this->getTags()->toArray(),
"status" => $this->getStatus(),
"name" => $this->getName(),
"deadline" => $this->getDeadline(),
"classroom" => $this->getClassroom(),
"startTime" => $this->getStartTime(),
"assistance" => $this->getAssistance(),
"groupSize" => $this->getGroupSize(),
"pretest" => $this->getPretest(),
"pretestDuration" => $this->getPretestDuration(),
"startDifficulty" => $this->getStartDifficulty(),
"students" => $this->getStudents()->toArray(),
// "pretestResponses" => $this->getPretestResponses()->toArray(),
"templateCount" => $this->getTemplateCount(),
"topics" => $this->getTopics()->toArray(),
"trainingUnits" => $this->getTrainingUnits()->toArray(),
"usePretest" => $this->getUsePretest(),
];
}
}