src/Entity/Core/Peer/PeerSession.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Core\Peer;
  3. use App\Entity\Core\Classroom\Classroom;
  4. use DateTime;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use JsonSerializable;
  9. #[ORM\Table('peer_session')]
  10. #[ORM\Entity(repositoryClass: PeerSessionRepository::class)]
  11. class PeerSession implements JsonSerializable
  12. {
  13. #[ORM\Column(type: 'integer')]
  14. #[ORM\Id]
  15. #[ORM\GeneratedValue(strategy: 'AUTO')]
  16. private int $id;
  17. #[ORM\Column(type: 'string', nullable: true)]
  18. protected ?string $name;
  19. #[ORM\Column(type: 'datetime', nullable: true)]
  20. private ?DateTime $startTime;
  21. #[ORM\Column(type: 'integer')]
  22. private int $durationStage1;
  23. #[ORM\Column(type: 'integer')]
  24. private int $durationStage2;
  25. #[ORM\Column(type: 'integer')]
  26. private int $durationStage3;
  27. #[ORM\JoinColumn(name: 'classroom', referencedColumnName: 'id', onDelete: 'CASCADE')]
  28. #[ORM\ManyToOne(targetEntity: Classroom::class, inversedBy: 'peerSessions')]
  29. private Classroom $classroom;
  30. #[ORM\JoinColumn(name: 'peer_theme_id', referencedColumnName: 'id')]
  31. #[ORM\ManyToOne(targetEntity: PeerTheme::class, inversedBy: 'peerSessions')]
  32. private PeerTheme $peerTheme;
  33. /**
  34. * @var Collection|ArrayCollection|PeerGroup[]
  35. */
  36. #[ORM\OneToMany(targetEntity: PeerGroup::class, mappedBy: 'peerSession', cascade: ['persist', 'remove'])]
  37. private Collection $peerGroups;
  38. #[ORM\Column(type: 'integer', nullable: false, options: ['default' => 1])]
  39. private int $isEnabled = 1;
  40. #[ORM\JoinColumn(name: 'peer_theme_class_type_id', referencedColumnName: 'id')]
  41. #[ORM\ManyToOne(targetEntity: PeerThemeClassType::class)]
  42. private PeerThemeClassType $peerThemeClassType;
  43. public function __construct()
  44. {
  45. $this->peerGroups = new ArrayCollection();
  46. }
  47. public function getName():string
  48. {
  49. return $this->name;
  50. }
  51. public function setName(string $name): void
  52. {
  53. $this->name = $name;
  54. }
  55. public function getId(): int
  56. {
  57. return $this->id;
  58. }
  59. public function getStartTime(): ?DateTime
  60. {
  61. return $this->startTime;
  62. }
  63. public function setStartTime(DateTime $startTime)
  64. {
  65. $this->startTime = $startTime;
  66. }
  67. public function getDurationStage1(): int
  68. {
  69. return $this->durationStage1;
  70. }
  71. public function setDurationStage1(int $durationStage1)
  72. {
  73. $this->durationStage1 = $durationStage1;
  74. }
  75. public function getDurationStage2(): int
  76. {
  77. return $this->durationStage2;
  78. }
  79. public function setDurationStage2(int $durationStage2)
  80. {
  81. $this->durationStage2 = $durationStage2;
  82. }
  83. public function getDurationStage3(): int
  84. {
  85. return $this->durationStage3;
  86. }
  87. public function setDurationStage3(int $durationStage3)
  88. {
  89. $this->durationStage3 = $durationStage3;
  90. }
  91. public function getClassroom(): Classroom
  92. {
  93. return $this->classroom;
  94. }
  95. public function setClassroom(Classroom $classroom)
  96. {
  97. $this->classroom = $classroom;
  98. }
  99. public function getPeerTheme(): PeerTheme
  100. {
  101. return $this->peerTheme;
  102. }
  103. public function setPeerTheme(PeerTheme $peerTheme)
  104. {
  105. $this->peerTheme = $peerTheme;
  106. }
  107. /**
  108. * @return Collection|ArrayCollection|PeerGroup[]
  109. */
  110. public function getPeerGroups(): Collection
  111. {
  112. return $this->peerGroups;
  113. }
  114. public function addPeerGroup(PeerGroup $peerGroup)
  115. {
  116. $peerGroup->setPeerSession($this);
  117. $this->peerGroups->add($peerGroup);
  118. }
  119. public function getIsEnabled(): int
  120. {
  121. return $this->isEnabled;
  122. }
  123. public function setIsEnabled(int $isEnabled)
  124. {
  125. $this->isEnabled = $isEnabled;
  126. }
  127. public function getPeerThemeClassType(): PeerThemeClassType
  128. {
  129. return $this->peerThemeClassType;
  130. }
  131. public function setPeerThemeClassType(PeerThemeClassType $peerThemeClassType)
  132. {
  133. $this->peerThemeClassType = $peerThemeClassType;
  134. }
  135. public function jsonSerialize(): mixed
  136. {
  137. $deadline = null;
  138. if ($this->getStartTime()) {
  139. $deadline = clone $this->getStartTime();
  140. $totalDuration = $this->getDurationStage1() + $this->getDurationStage2() + $this->getDurationStage3();
  141. $deadline->modify(sprintf('+%d minutes', $totalDuration));
  142. }
  143. $topics = [];
  144. if (!empty($this->getPeerTheme()->getName())) {
  145. $topics[] = ['name' => $this->getPeerTheme()->getName()];
  146. }
  147. return [
  148. "name" => $this->name,
  149. "id" => $this->getId(),
  150. "startTime" => $this->getStartTime(),
  151. "classroom" => $this->getClassroom(),
  152. "duration" => $this->getDurationStage1(),
  153. "deadline" => $deadline,
  154. "topics" => $topics,
  155. ];
  156. }
  157. }