No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Course.php 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <?php
  2. namespace Logipro\Bundle\SCORMBundle\Entity;
  3. use Doctrine\Common\Collections\Criteria;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Expr\Comparison;
  7. use Logipro\Bundle\SCORMBundle\Entity\MapCourseZipfile;
  8. use Logipro\Bundle\SCORMBundle\LearningModels\DOMSCORM;
  9. use Symfony\Component\Config\Definition\Exception\Exception;
  10. /**
  11. * Représente une activité dans le moteur SCORM.
  12. */
  13. class Course
  14. {
  15. const VERSIONING_RULE_DEFAULT = 'versioning_rule_default';
  16. const VERSIONING_RULE_RESTART = 'versioning_rule_restart';
  17. /**
  18. *
  19. * @var int
  20. */
  21. protected $courseId;
  22. /**
  23. *
  24. * @var \DateTime
  25. */
  26. protected $creationDate;
  27. /**
  28. *
  29. * @var \DateTime
  30. */
  31. protected $updateDate;
  32. /**
  33. *
  34. * @var int
  35. */
  36. protected $maxVersion = 1;
  37. /**
  38. *
  39. * @var string
  40. */
  41. protected $versionRule = self::VERSIONING_RULE_DEFAULT;
  42. /**
  43. *
  44. * @var string
  45. */
  46. protected $courseKey;
  47. /**
  48. *
  49. * @var ArrayCollection
  50. */
  51. protected $registrations;
  52. /**
  53. *
  54. * @var ArrayCollection
  55. */
  56. protected $mapCourseZipfiles;
  57. /**
  58. * Constructeur de track.
  59. */
  60. public function __construct()
  61. {
  62. $this->registrations = new ArrayCollection();
  63. }
  64. /**
  65. * Callback appelée avant la création de l'objet dans la base.
  66. */
  67. public function prePersist()
  68. {
  69. // Initialise des dates
  70. $this->creationDate = new \DateTime('now');
  71. $this->updateDate = new \DateTime('now');
  72. }
  73. /**
  74. * Callback appelée avant l'update de l'objet dans la base.
  75. */
  76. public function preUpdate()
  77. {
  78. // Change la date de mise à jour
  79. $this->updateDate = new \DateTime('now');
  80. }
  81. //GETTERS && SETTERS
  82. /**
  83. * Get the value of courseId
  84. *
  85. * @return int
  86. */
  87. public function getCourseId()
  88. {
  89. return $this->courseId;
  90. }
  91. /**
  92. * Set the value of courseId
  93. *
  94. * @param int $id
  95. *
  96. * @return Course
  97. */
  98. public function setCourseId($id)
  99. {
  100. $this->courseId = $id;
  101. return $this;
  102. }
  103. /**
  104. * Get the value of creationDate
  105. *
  106. * @return \DateTime
  107. */
  108. public function getCreationDate()
  109. {
  110. return $this->creationDate;
  111. }
  112. /**
  113. * Get the value of updateDate
  114. *
  115. * @return \DateTime
  116. */
  117. public function getUpdateDate()
  118. {
  119. return $this->updateDate;
  120. }
  121. /**
  122. * Get the value of maxVersion
  123. *
  124. * @return int
  125. */
  126. public function getMaxVersion()
  127. {
  128. return $this->maxVersion;
  129. }
  130. /**
  131. * Set the value of maxVersion
  132. *
  133. * @param int $maxVersion
  134. *
  135. * @return self
  136. */
  137. public function setMaxVersion(int $maxVersion)
  138. {
  139. $this->maxVersion = $maxVersion;
  140. return $this;
  141. }
  142. /**
  143. * Get the value of versionRule
  144. *
  145. * @return string
  146. */
  147. public function getVersionRule()
  148. {
  149. return $this->versionRule;
  150. }
  151. /**
  152. * Set the value of versionRule
  153. *
  154. * @param string $versionRule
  155. *
  156. * @return self
  157. */
  158. public function setVersionRule(string $versionRule)
  159. {
  160. $this->versionRule = $versionRule;
  161. return $this;
  162. }
  163. /**
  164. * Get the value of courseKey
  165. *
  166. * @return string
  167. */
  168. public function getCourseKey()
  169. {
  170. return $this->courseKey;
  171. }
  172. /**
  173. * Set the value of courseKey
  174. *
  175. * @param string $courseKey
  176. *
  177. * @return self
  178. */
  179. public function setCourseKey(string $courseKey)
  180. {
  181. $this->courseKey = $courseKey;
  182. return $this;
  183. }
  184. /**
  185. * Get the value of registrations
  186. *
  187. * @return array
  188. */
  189. public function getRegistrations():Collection
  190. {
  191. return $this->registrations;
  192. }
  193. /**
  194. * Set the value of registrations
  195. *
  196. * @param array $registrations
  197. *
  198. * @return self
  199. */
  200. public function setRegistrations(array $registrations)
  201. {
  202. $this->registrations = $registrations;
  203. return $this;
  204. }
  205. /**
  206. * Add MapCourseZipfile entity to collection (one to many).
  207. *
  208. * @param \Logipro\MoteurScorm\Entity\ScormEngine\MapCourseZipfile $mapCourseZipfile
  209. * @return \Logipro\MoteurScorm\Entity\ScormEngine\Scorm2004Track
  210. */
  211. public function addMapCourseZipfile(MapCourseZipfile $mapCourseZipfile)
  212. {
  213. $this->mapCourseZipfiles[] = $mapCourseZipfile;
  214. return $this;
  215. }
  216. /**
  217. * Remove MapCourseZipfile entity from collection (one to many).
  218. *
  219. * @param \Logipro\MoteurScorm\Entity\ScormEngine\MapCourseZipfile $mapCourseZipfile
  220. * @return \Logipro\MoteurScorm\Entity\ScormEngine\Scorm2004Track
  221. */
  222. public function removeMapCourseZipfile(MapCourseZipfile $mapCourseZipfile)
  223. {
  224. $this->mapCourseZipfiles->removeElement($mapCourseZipfile);
  225. return $this;
  226. }
  227. /**
  228. * Get MapCourseZipfile entity collection (one to many).
  229. *
  230. * @return \Doctrine\Common\Collections\Collection
  231. */
  232. public function getMapCourseZipfiles()
  233. {
  234. return $this->mapCourseZipfiles;
  235. }
  236. /**
  237. * renvoi le domscorm du paquet correspondant à la version
  238. *
  239. * @param integer $version
  240. * @return Logipro\SCORMEngineBundle\LearningModels\DOMSCORM
  241. */
  242. public function getDOM(int $version) : DOMSCORM
  243. {
  244. $expression = new Comparison('version', '=', $version);
  245. $critere = new Criteria();
  246. $critere->where($expression);
  247. $zips = $this->getMapCourseZipfiles()->matching($critere);
  248. if ($zips->count() == 1) {
  249. $mapZip = $zips->first();
  250. $zip = $mapZip->getZipFile();
  251. return $zip->getDOM();
  252. } else {
  253. throw new Exception('version must be unique in mapCourseZipfile');
  254. }
  255. return null;
  256. }
  257. }