ScormAssessmentItem.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * A SCORM item. It corresponds to a single question.
  5. * This class allows export from Chamilo SCORM 1.2 format of a single question.
  6. * It is not usable as-is, but must be subclassed, to support different kinds of questions.
  7. *
  8. * Every start_*() and corresponding end_*(), as well as export_*() methods return a string.
  9. *
  10. * Attached files are NOT exported.
  11. *
  12. * @package chamilo.exercise.scorm
  13. */
  14. class ScormAssessmentItem
  15. {
  16. public $question;
  17. public $question_ident;
  18. public $answer;
  19. /**
  20. * Constructor.
  21. *
  22. * @param ScormQuestion $question the Question object we want to export
  23. */
  24. public function __construct($question)
  25. {
  26. $this->question = $question;
  27. $this->question->setAnswer();
  28. $this->questionIdent = 'QST_'.$question->id;
  29. }
  30. /**
  31. * Start the XML flow.
  32. *
  33. * This opens the <item> block, with correct attributes.
  34. */
  35. public function start_page()
  36. {
  37. $head = '';
  38. /*if ($this->standalone) {
  39. $charset = 'UTF-8';
  40. $head = '<?xml version="1.0" encoding="'.$charset.'" standalone="no"?>';
  41. $head .= '<html>';
  42. }*/
  43. return $head;
  44. }
  45. /**
  46. * End the XML flow, closing the </item> tag.
  47. */
  48. public function end_page()
  49. {
  50. /*if ($this->standalone) {
  51. return '</html>';
  52. }*/
  53. return '';
  54. }
  55. /**
  56. * Start document header.
  57. */
  58. public function start_header()
  59. {
  60. /*if ($this->standalone) {
  61. return '<head>';
  62. }*/
  63. return '';
  64. }
  65. /**
  66. * Print CSS inclusion.
  67. */
  68. public function css()
  69. {
  70. $css = '';
  71. // if ($this->standalone) {
  72. // $css = '<style type="text/css" media="screen, projection">';
  73. // $css .= '/*<![CDATA[*/'."\n";
  74. // $css .= '/*]]>*/'."\n";
  75. // $css .= '</style>'."\n";
  76. // $css .= '<style type="text/css" media="print">';
  77. // $css .= '/*<![CDATA[*/'."\n";
  78. // $css .= '/*]]>*/'."\n";
  79. // $css .= '</style>';
  80. // }
  81. return $css;
  82. }
  83. /**
  84. * End document header.
  85. */
  86. public function end_header()
  87. {
  88. // if ($this->standalone) {
  89. // return '</head>';
  90. // }
  91. return '';
  92. }
  93. /**
  94. * Start the itemBody.
  95. */
  96. public function start_js()
  97. {
  98. $js = '<script type="text/javascript" src="assets/api_wrapper.js"></script>';
  99. // if ($this->standalone) {
  100. // return '<script>';
  101. // }
  102. return $js;
  103. }
  104. /**
  105. * End the itemBody part.
  106. */
  107. public function end_js()
  108. {
  109. /*if ($this->standalone) {
  110. return '</script>';
  111. }*/
  112. return '';
  113. }
  114. /**
  115. * Start the itemBody.
  116. */
  117. public function start_body()
  118. {
  119. /*if ($this->standalone) {
  120. return '<body><form id="dokeos_scorm_form" method="post" action="">';
  121. }*/
  122. return '';
  123. }
  124. /**
  125. * End the itemBody part.
  126. */
  127. public function end_body()
  128. {
  129. /*if ($this->standalone) {
  130. return '<br /><input class="btn" type="button" id="dokeos_scorm_submit" name="dokeos_scorm_submit" value="OK" /></form></body>';
  131. }*/
  132. return '';
  133. }
  134. /**
  135. * Export the question as a SCORM Item.
  136. * This is a default behaviour, some classes may want to override this.
  137. *
  138. * @return string|array a string, the XML flow for an Item
  139. */
  140. public function export()
  141. {
  142. list($js, $html) = $this->question->export();
  143. /*if ($this->standalone) {
  144. $res = $this->start_page()
  145. .$this->start_header()
  146. .$this->css()
  147. .$this->start_js()
  148. .$this->common_js()
  149. .$js
  150. .$this->end_js()
  151. .$this->end_header()
  152. .$this->start_body()
  153. .$html
  154. .$this->end_body()
  155. .$this->end_page();
  156. return $res;
  157. } else {
  158. return [$js, $html];
  159. }*/
  160. return [$js, $html];
  161. }
  162. }