src/CoreBundle/Entity/CrammingActivity.php line 13

Open in your IDE?
  1. <?php
  2. namespace CoreBundle\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use JsonSerializable;
  6. /**
  7. * @ORM\Table("cramming_activity")
  8. * @ORM\Entity(repositoryClass="CoreBundle\Entity\CrammingActivityRepository")
  9. */
  10. class CrammingActivity implements JsonSerializable
  11. {
  12. /**
  13. * @var int
  14. *
  15. * @ORM\Column(name="id", type="integer")
  16. * @ORM\Id
  17. * @ORM\GeneratedValue(strategy="AUTO")
  18. */
  19. protected $id;
  20. /**
  21. * @ORM\Column(type="string", nullable=true)
  22. */
  23. protected $name;
  24. /**
  25. * @var Classroom
  26. *
  27. * @ORM\ManyToOne(targetEntity="Classroom")
  28. * @ORM\JoinColumn(name="classroom", referencedColumnName="id", onDelete="CASCADE")
  29. */
  30. private $classroom;
  31. /**
  32. * @var \DateTime
  33. *
  34. * @ORM\Column(name="start_time", type="datetime", nullable=true)
  35. */
  36. protected $startTime;
  37. /**
  38. * @var \DateTime
  39. *
  40. * @ORM\Column(name="deadline", type="datetime", nullable=true)
  41. */
  42. protected $deadline;
  43. /**
  44. * @ORM\Column(type="integer", nullable=true)
  45. */
  46. protected $duration;
  47. /**
  48. * @ORM\Column(name="is_enabled", type="integer", nullable=true, options={"default"=1})
  49. */
  50. private $isEnabled = 1;
  51. /**
  52. * @ORM\Column(name="template_sets_count", type="integer")
  53. */
  54. private $templateSetsCount;
  55. /**
  56. * @var ArrayCollection|TemplateSet[]
  57. *
  58. * @ORM\ManyToMany(targetEntity="TemplateSet")
  59. * @ORM\JoinTable(name="cramming_activity_template_sets",
  60. * joinColumns={@ORM\JoinColumn(name="cramming_activity", referencedColumnName="id")},
  61. * inverseJoinColumns={@ORM\JoinColumn(name="template_set", referencedColumnName="id")})
  62. */
  63. private $templateSets;
  64. /**
  65. * @var CrammingActivityUnit[]
  66. *
  67. * @ORM\OneToMany(targetEntity="CrammingActivityUnit",
  68. * mappedBy="crammingActivity", cascade={"persist","remove"})
  69. */
  70. private $crammingActivityUnits;
  71. /**
  72. * @ORM\Column(name="show_hints", type="boolean", nullable=true, options={"default"=false})
  73. */
  74. private $showHints = false;
  75. /**
  76. * @ORM\Column(name="is_homework", type="boolean", nullable=true, options={"default"=false})
  77. */
  78. private $isHomework = false;
  79. /**
  80. * @ORM\Column(name="can_pause", type="boolean", nullable=true, options={"default"=false})
  81. */
  82. private $canPause = false;
  83. public function __construct()
  84. {
  85. $this->startTime = new \DateTime();
  86. $this->crammingActivityUnits = new ArrayCollection();
  87. $this->templateSets = new ArrayCollection();
  88. }
  89. /**
  90. * @throws \Exception
  91. */
  92. public function resetActivity(): void
  93. {
  94. $this->id = null;
  95. $this->startTime = new \DateTime();
  96. $this->crammingActivityUnits = new ArrayCollection();
  97. $this->templateSets = new ArrayCollection();
  98. }
  99. /**
  100. * @return int
  101. */
  102. public function getId(): int
  103. {
  104. return $this->id;
  105. }
  106. /**
  107. * @param int $id
  108. */
  109. public function setId(?int $id): void
  110. {
  111. $this->id = $id;
  112. }
  113. /**
  114. * @return mixed
  115. */
  116. public function getName()
  117. {
  118. return $this->name;
  119. }
  120. /**
  121. * @param mixed $name
  122. */
  123. public function setName($name): void
  124. {
  125. $this->name = $name;
  126. }
  127. /**
  128. * @return Classroom
  129. */
  130. public function getClassroom(): ?Classroom
  131. {
  132. return $this->classroom;
  133. }
  134. /**
  135. * @param Classroom $classroom
  136. */
  137. public function setClassroom(?Classroom $classroom): void
  138. {
  139. $this->classroom = $classroom;
  140. }
  141. /**
  142. * @return \DateTime
  143. */
  144. public function getStartTime(): ?\DateTime
  145. {
  146. return $this->startTime;
  147. }
  148. /**
  149. * @param \DateTime $startTime
  150. */
  151. public function setStartTime(?\DateTime $startTime): void
  152. {
  153. $this->startTime = $startTime;
  154. }
  155. /**
  156. * @return \DateTime
  157. */
  158. public function getDeadline(): ?\DateTime
  159. {
  160. return $this->deadline;
  161. }
  162. /**
  163. * @param \DateTime $deadline
  164. */
  165. public function setDeadline(?\DateTime $deadline): void
  166. {
  167. $this->deadline = $deadline;
  168. }
  169. /**
  170. * @return mixed
  171. */
  172. public function getDuration()
  173. {
  174. return $this->duration;
  175. }
  176. /**
  177. * @param mixed $duration
  178. */
  179. public function setDuration($duration): void
  180. {
  181. $this->duration = $duration;
  182. }
  183. /**
  184. * @return int
  185. */
  186. public function getIsEnabled(): int
  187. {
  188. return $this->isEnabled;
  189. }
  190. /**
  191. * @param int $isEnabled
  192. */
  193. public function setIsEnabled(int $isEnabled): void
  194. {
  195. $this->isEnabled = $isEnabled;
  196. }
  197. /**
  198. * @return mixed
  199. */
  200. public function getTemplateSetsCount()
  201. {
  202. return $this->templateSetsCount;
  203. }
  204. /**
  205. * @param mixed $templateSetsCount
  206. */
  207. public function setTemplateSetsCount($templateSetsCount): void
  208. {
  209. $this->templateSetsCount = $templateSetsCount;
  210. }
  211. /**
  212. * @return TemplateSet[]|ArrayCollection
  213. */
  214. public function getTemplateSets()
  215. {
  216. return $this->templateSets;
  217. }
  218. /**
  219. * @param TemplateSet[]|ArrayCollection $templateSets
  220. */
  221. public function setTemplateSets($templateSets): void
  222. {
  223. $this->templateSets = $templateSets;
  224. }
  225. /**
  226. * @param TemplateSet $templateSet
  227. *
  228. * @return $this
  229. */
  230. public function addTemplateSet(TemplateSet $templateSet)
  231. {
  232. $this->templateSets->add($templateSet);
  233. return $this;
  234. }
  235. public function removeTemplateSet(TemplateSet $templateSet)
  236. {
  237. $this->templateSets->removeElement($templateSet);
  238. }
  239. /**
  240. * @param TemplateSet $templateSet
  241. *
  242. * @return bool
  243. */
  244. public function removeStudent(TemplateSet $templateSet)
  245. {
  246. return $this->templateSets->removeElement($templateSet);
  247. }
  248. /**
  249. * @return CrammingActivityUnit[]|ArrayCollection
  250. */
  251. public function getCrammingActivityUnits()
  252. {
  253. return $this->crammingActivityUnits;
  254. }
  255. /**
  256. * @param CrammingActivityUnit[] $crammingActivityUnits
  257. */
  258. public function setCrammingActivityUnits(?array $crammingActivityUnits): void
  259. {
  260. $this->crammingActivityUnits = $crammingActivityUnits;
  261. }
  262. /**
  263. * @return bool
  264. */
  265. public function isShowHints(): bool
  266. {
  267. return $this->showHints;
  268. }
  269. /**
  270. * @param bool $showHints
  271. */
  272. public function setShowHints(bool $showHints): void
  273. {
  274. $this->showHints = $showHints;
  275. }
  276. /**
  277. * @return bool
  278. */
  279. public function isHomework(): bool
  280. {
  281. return $this->isHomework;
  282. }
  283. /**
  284. * @param bool $isHomework
  285. */
  286. public function setIsHomework(bool $isHomework): void
  287. {
  288. $this->isHomework = $isHomework;
  289. }
  290. /**
  291. * @return bool
  292. */
  293. public function isCanPause(): bool
  294. {
  295. return $this->canPause;
  296. }
  297. /**
  298. * @param bool $canPause
  299. */
  300. public function setCanPause(bool $canPause): void
  301. {
  302. $this->canPause = $canPause;
  303. }
  304. /**
  305. * @return bool
  306. */
  307. public function isSelfStudy():bool
  308. {
  309. return $this->classroom === null;
  310. }
  311. public function jsonSerialize(): array
  312. {
  313. return [
  314. 'id' => $this->getId(),
  315. 'name' => $this->getName(),
  316. 'deadline' => $this->getDeadline(),
  317. 'startTime' => $this->getStartTime(),
  318. 'duration' => $this->getDuration(),
  319. // Add other fields as needed
  320. ];
  321. }
  322. }