src/Entity/Core/Session/Session.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Core\Session;
  3. use App\Entity\Core\Classroom\Classroom;
  4. use App\Entity\Core\Classroom\ClassroomType;
  5. use App\Entity\Core\Pretest;
  6. use App\Entity\Core\PretestResponse;
  7. use App\Entity\Core\SelfStudy\SelfStudyTopic;
  8. use App\Entity\Core\TagMathproblem;
  9. use App\Entity\Core\Topic\Topic;
  10. use App\Entity\Core\Training\TrainingUnit;
  11. use Doctrine\Common\Collections\ArrayCollection;
  12. use Doctrine\Common\Collections\Collection;
  13. use Doctrine\ORM\Mapping as ORM;
  14. use JsonSerializable;
  15. #[ORM\Table('session')]
  16. #[ORM\Entity(repositoryClass: SessionRepository::class)]
  17. class Session extends SessionType implements SessionInterface, JsonSerializable
  18. {
  19. /**
  20. * @var Classroom
  21. */
  22. #[ORM\JoinColumn(name: 'classroom', referencedColumnName: 'id', onDelete: 'CASCADE')]
  23. #[ORM\ManyToOne(targetEntity: Classroom::class, inversedBy: 'sessions')]
  24. private $classroom;
  25. #[ORM\ManyToOne(targetEntity: ClassroomType::class)]
  26. #[ORM\JoinColumn(name: 'selected_classroom_type', referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
  27. private ?ClassroomType $selectedClassroomType = null;
  28. /**
  29. * @var ArrayCollection|Topic[]
  30. */
  31. #[ORM\JoinTable(name: 'session_topic')]
  32. #[ORM\JoinColumn(name: 'session', referencedColumnName: 'id')]
  33. #[ORM\InverseJoinColumn(name: 'topic', referencedColumnName: 'id')]
  34. #[ORM\ManyToMany(targetEntity: Topic::class, inversedBy: 'sessions')]
  35. private $topics;
  36. /**
  37. * @var ArrayCollection
  38. */
  39. #[ORM\JoinTable(name: 'session_tag')]
  40. #[ORM\JoinColumn(name: 'session', referencedColumnName: 'id')]
  41. #[ORM\InverseJoinColumn(name: 'tag', referencedColumnName: 'id')]
  42. #[ORM\ManyToMany(targetEntity: TagMathproblem::class)]
  43. private $tags;
  44. /**
  45. * @var bool
  46. */
  47. #[ORM\Column(name: 'dormant', type: 'boolean')]
  48. private $dormant = false;
  49. /**
  50. * @var Pretest
  51. */
  52. #[ORM\JoinColumn(name: 'pretest', referencedColumnName: 'id', nullable: true, onDelete: 'CASCADE')]
  53. #[ORM\ManyToOne(targetEntity: Pretest::class)]
  54. private $pretest;
  55. #[ORM\Column(type: 'integer', nullable: true)]
  56. private $pretestDuration;
  57. #[ORM\Column(type: 'integer', nullable: true, options: ['default' => 1])]
  58. private $groupSize = 1;
  59. #[ORM\Column(type: 'boolean', nullable: true)]
  60. private $usePretest;
  61. #[ORM\OneToMany(targetEntity: TrainingUnit::class, mappedBy: 'session', cascade: ['persist', 'remove'])]
  62. private Collection $TrainingUnits;
  63. /**
  64. * @var PretestResponse[]
  65. */
  66. #[ORM\OneToMany(targetEntity: PretestResponse::class, mappedBy: 'session', cascade: ['persist', 'remove'])]
  67. private $PretestResponses;
  68. /**
  69. * @var ArrayCollection|SessionStudent[]
  70. */
  71. #[ORM\OneToMany(targetEntity: SessionStudent::class, mappedBy: 'session', cascade: ['persist', 'remove'])]
  72. private $students;
  73. #[ORM\Column(type: 'integer', nullable: true, options: ['default' => 0])]
  74. private $status = 0;
  75. #[ORM\Column(type: 'integer')]
  76. private $templateCount;
  77. // assistance = 1 (both CAS and no CAS)
  78. #[ORM\Column(type: 'integer')]
  79. private $assistance;
  80. /**
  81. * @var bool
  82. */
  83. #[ORM\Column(name: 'is_self_study', type: 'boolean', nullable: true, options: ['default' => false])]
  84. private $isSelfStudy;
  85. // hasManyTopics = 0 (count of topics <= 3)
  86. #[ORM\Column(name: 'has_many_topics', type: 'integer', nullable: true, options: ['default' => 0])]
  87. private $hasManyTopics = 0;
  88. /**
  89. * @var SelfStudyTopic
  90. */
  91. #[ORM\JoinColumn(name: 'self_study_topic', referencedColumnName: 'id')]
  92. #[ORM\ManyToOne(targetEntity: SelfStudyTopic::class)]
  93. private $selfStudyTopic = null;
  94. #[ORM\Column(name: 'start_difficulty', type: 'integer', nullable: true)]
  95. private $startDifficulty;
  96. public function __construct()
  97. {
  98. $this->TrainingUnits = new ArrayCollection();
  99. $this->PretestResponses = new ArrayCollection();
  100. $this->topics = new ArrayCollection();
  101. $this->tags = new ArrayCollection();
  102. $this->students = new ArrayCollection();
  103. }
  104. /**
  105. * Set classroom.
  106. *
  107. * @param Classroom $classroom
  108. *
  109. * @return Session
  110. */
  111. public function setClassroom($classroom)
  112. {
  113. $this->classroom = $classroom;
  114. return $this;
  115. }
  116. /**
  117. * Get classroom.
  118. *
  119. * @return Classroom
  120. */
  121. public function getClassroom()
  122. {
  123. return $this->classroom;
  124. }
  125. public function getSelectedClassroomType(): ?ClassroomType
  126. {
  127. return $this->selectedClassroomType;
  128. }
  129. public function setSelectedClassroomType(?ClassroomType $selectedClassroomType): self
  130. {
  131. $this->selectedClassroomType = $selectedClassroomType;
  132. return $this;
  133. }
  134. /**
  135. * @param Topic[] $topics
  136. */
  137. public function setTopics(array $topics)
  138. {
  139. $this->topics = $topics;
  140. }
  141. public function getTopics(): Collection
  142. {
  143. return $this->topics;
  144. }
  145. /**
  146. * @return Session
  147. */
  148. public function addTopic(Topic $topic)
  149. {
  150. $this->topics->add($topic);
  151. return $this;
  152. }
  153. /**
  154. * @return bool
  155. */
  156. public function removeTopic(Topic $topic)
  157. {
  158. return $this->topics->removeElement($topic);
  159. }
  160. public function getTags(): Collection
  161. {
  162. return $this->tags;
  163. }
  164. /**
  165. * @return Session
  166. */
  167. public function addTag(TagMathproblem $tag)
  168. {
  169. $this->tags->add($tag);
  170. return $this;
  171. }
  172. /**
  173. * @param TagMathproblem[] $tags
  174. */
  175. public function setTags(array $tags)
  176. {
  177. $this->tags = $tags;
  178. }
  179. /**
  180. * @return bool
  181. */
  182. public function removeTag(TagMathproblem $tag)
  183. {
  184. return $this->tags->removeElement($tag);
  185. }
  186. public function isDormant()
  187. {
  188. return $this->dormant;
  189. }
  190. public function setDormant($dormant)
  191. {
  192. $this->dormant = $dormant;
  193. }
  194. /**
  195. * Set pretest.
  196. *
  197. * @param Pretest $pretest
  198. *
  199. * @return Session
  200. */
  201. public function setPretest($pretest)
  202. {
  203. $this->pretest = $pretest;
  204. return $this;
  205. }
  206. /**
  207. * Get pretest.
  208. *
  209. * @return Pretest
  210. */
  211. public function getPretest()
  212. {
  213. return $this->pretest;
  214. }
  215. /**
  216. * Set Duration.
  217. *
  218. * @param int $duration
  219. *
  220. * @return Session
  221. */
  222. public function setDuration($duration)
  223. {
  224. $this->duration = $duration;
  225. return $this;
  226. }
  227. /**
  228. * Get duration.
  229. *
  230. * @return int
  231. */
  232. public function getDuration()
  233. {
  234. return $this->duration;
  235. }
  236. /**
  237. * Set groupSize.
  238. *
  239. * @param int $groupSize
  240. *
  241. * @return Session
  242. */
  243. public function setGroupSize($groupSize)
  244. {
  245. $this->groupSize = $groupSize;
  246. return $this;
  247. }
  248. /**
  249. * Get groupSize.
  250. *
  251. * @return int
  252. */
  253. public function getGroupSize()
  254. {
  255. return $this->groupSize;
  256. }
  257. /**
  258. * Set pretestDuration.
  259. *
  260. * @param int $pretestDuration
  261. *
  262. * @return Session
  263. */
  264. public function setPretestDuration($pretestDuration)
  265. {
  266. $this->pretestDuration = $pretestDuration;
  267. return $this;
  268. }
  269. /**
  270. * Get pretestDuration
  271. *
  272. * @return int
  273. */
  274. public function getPretestDuration()
  275. {
  276. return $this->pretestDuration;
  277. }
  278. /**
  279. * Set usePretest.
  280. *
  281. * @param int $usePretest
  282. *
  283. * @return Session
  284. */
  285. public function setUsePretest($usePretest)
  286. {
  287. $this->usePretest = $usePretest;
  288. return $this;
  289. }
  290. /**
  291. * Get usePretest.
  292. *
  293. * @return boolean
  294. */
  295. public function getUsePretest()
  296. {
  297. return $this->usePretest;
  298. }
  299. /**
  300. * @return ArrayCollection|TrainingUnit[]
  301. */
  302. public function getTrainingUnits(): Collection
  303. {
  304. return $this->TrainingUnits;
  305. }
  306. /**
  307. * @return Session
  308. */
  309. public function addTrainingUnit(TrainingUnit $TrainingUnit)
  310. {
  311. $TrainingUnit->setSession($this);
  312. $this->TrainingUnits->add($TrainingUnit);
  313. return $this;
  314. }
  315. /**
  316. * @return bool
  317. */
  318. public function removeTrainingUnit(TrainingUnit $TrainingUnit)
  319. {
  320. $TrainingUnit->setSession(null);
  321. return $this->TrainingUnits->removeElement($TrainingUnit);
  322. }
  323. /**
  324. * @return PretestResponse[]
  325. */
  326. public function getPretestResponses()
  327. {
  328. return $this->PretestResponses;
  329. }
  330. /**
  331. * @return Session
  332. */
  333. public function addPretestResponse(PretestResponse $PretestResponse)
  334. {
  335. $PretestResponse->setSession($this);
  336. $this->PretestResponses->add($PretestResponse);
  337. return $this;
  338. }
  339. /**
  340. * @return bool
  341. */
  342. public function removePretestResponse(PretestResponse $PretestResponse)
  343. {
  344. $PretestResponse->setSession(null);
  345. return $this->PretestResponses->removeElement($PretestResponse);
  346. }
  347. /**
  348. * @return SessionStudent[]
  349. */
  350. public function getStudents()
  351. {
  352. return $this->students;
  353. }
  354. /**
  355. * @return Session
  356. */
  357. public function addStudent(SessionStudent $student)
  358. {
  359. $this->students->add($student);
  360. return $this;
  361. }
  362. /**
  363. * @return bool
  364. */
  365. public function removeStudent(SessionStudent $student)
  366. {
  367. $student->setSession(null);
  368. return $this->students->removeElement($student);
  369. }
  370. public function getStatus(): ?int
  371. {
  372. return $this->status;
  373. }
  374. /**
  375. * @param mixed $status
  376. */
  377. public function setStatus($status)
  378. {
  379. $this->status = $status;
  380. }
  381. public function getTemplateCount()
  382. {
  383. return $this->templateCount;
  384. }
  385. public function setTemplateCount($count)
  386. {
  387. $this->templateCount = $count;
  388. }
  389. public function getAssistance()
  390. {
  391. return $this->assistance;
  392. }
  393. /**
  394. * @param mixed $assistance
  395. */
  396. public function setAssistance($assistance)
  397. {
  398. $this->assistance = $assistance;
  399. }
  400. /**
  401. * @return bool | null
  402. */
  403. public function isSelfStudy()
  404. {
  405. return $this->isSelfStudy;
  406. }
  407. public function setIsSelfStudy(bool $isSelfStudy)
  408. {
  409. $this->isSelfStudy = $isSelfStudy;
  410. }
  411. public function hasManyTopics(): int
  412. {
  413. return $this->hasManyTopics;
  414. }
  415. public function setHasManyTopics(int $hasManyTopics): void
  416. {
  417. $this->hasManyTopics = $hasManyTopics;
  418. }
  419. /**
  420. * @return mixed
  421. */
  422. public function getStartDifficulty()
  423. {
  424. return $this->startDifficulty;
  425. }
  426. /**
  427. * @param mixed $startDifficulty
  428. */
  429. public function setStartDifficulty($startDifficulty): void
  430. {
  431. $this->startDifficulty = $startDifficulty;
  432. }
  433. public function getSelfStudyTopic(): ?SelfStudyTopic
  434. {
  435. return $this->selfStudyTopic;
  436. }
  437. public function setSelfStudyTopic(?SelfStudyTopic $selfStudyTopic): void
  438. {
  439. $this->selfStudyTopic = $selfStudyTopic;
  440. }
  441. public function jsonSerialize(): mixed
  442. {
  443. return [
  444. "id" => $this->getId(),
  445. "duration" => $this->getDuration(),
  446. "tags" => $this->getTags()->toArray(),
  447. "status" => $this->getStatus(),
  448. "name" => $this->getName(),
  449. "deadline" => $this->getDeadline(),
  450. "classroom" => $this->getClassroom(),
  451. "startTime" => $this->getStartTime(),
  452. "assistance" => $this->getAssistance(),
  453. "groupSize" => $this->getGroupSize(),
  454. "pretest" => $this->getPretest(),
  455. "pretestDuration" => $this->getPretestDuration(),
  456. "startDifficulty" => $this->getStartDifficulty(),
  457. "students" => $this->getStudents()->toArray(),
  458. // "pretestResponses" => $this->getPretestResponses()->toArray(),
  459. "templateCount" => $this->getTemplateCount(),
  460. "topics" => $this->getTopics()->toArray(),
  461. "trainingUnits" => $this->getTrainingUnits()->toArray(),
  462. "usePretest" => $this->getUsePretest(),
  463. ];
  464. }
  465. }