123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- <?php
- /* For licensing terms, see /license.txt */
- /**
- * The ScormQuestion class is a gateway to getting the answers exported
- * (the question is just an HTML text, while the answers are the most important).
- * It is important to note that the SCORM export process is done in two parts.
- * First, the HTML part (which is the presentation), and second the JavaScript
- * part (the process).
- * The two bits are separate to allow for a one-big-javascript and a one-big-html
- * files to be built. Each export function thus returns an array of HTML+JS.
- *
- *
- * @author Claro Team <cvs@claroline.net>
- * @author Yannick Warnier <yannick.warnier@beeznest.com>
- *
- * @package chamilo.exercise.scorm
- */
- class ScormQuestion extends Question
- {
- public $js_id;
- public $answer;
- /**
- * ScormQuestion constructor.
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * Returns the HTML + JS flow corresponding to one question.
- *
- * @param int $questionId The question ID
- * @param bool $standalone (ie including XML tag, DTD declaration, etc)
- * @param int $jsId The JavaScript ID for this question.
- * Due to the nature of interactions, we must have a natural sequence for
- * questions in the generated JavaScript.
- *
- * @return string|array
- */
- public function exportQuestionToScorm(
- $questionId,
- $jsId
- ) {
- $question = self::read($questionId);
- if (!$question) {
- return '';
- }
- $this->id = $question->id;
- $this->js_id = $jsId;
- $this->type = $question->type;
- $this->question = $question->question;
- $this->description = $question->description;
- $this->weighting = $question->weighting;
- $this->position = $question->position;
- $this->picture = $question->picture;
- $assessmentItem = new ScormAssessmentItem($this);
- return $assessmentItem->export();
- }
- /**
- * Include the correct answer class and create answer.
- */
- public function setAnswer()
- {
- switch ($this->type) {
- case MCUA:
- $this->answer = new ScormAnswerMultipleChoice($this->id);
- $this->answer->questionJSId = $this->js_id;
- break;
- case MCMA:
- case GLOBAL_MULTIPLE_ANSWER:
- $this->answer = new ScormAnswerMultipleChoice($this->id);
- $this->answer->questionJSId = $this->js_id;
- break;
- case TF:
- $this->answer = new ScormAnswerTrueFalse($this->id);
- $this->answer->questionJSId = $this->js_id;
- break;
- case FIB:
- $this->answer = new ScormAnswerFillInBlanks($this->id);
- $this->answer->questionJSId = $this->js_id;
- break;
- case MATCHING:
- case MATCHING_DRAGGABLE:
- case DRAGGABLE:
- $this->answer = new ScormAnswerMatching($this->id);
- $this->answer->questionJSId = $this->js_id;
- break;
- case ORAL_EXPRESSION:
- case FREE_ANSWER:
- $this->answer = new ScormAnswerFree($this->id);
- $this->answer->questionJSId = $this->js_id;
- break;
- case HOT_SPOT:
- $this->answer = new ScormAnswerHotspot($this->id);
- $this->answer->questionJSId = $this->js_id;
- break;
- case MULTIPLE_ANSWER_COMBINATION:
- $this->answer = new ScormAnswerMultipleChoice($this->id);
- $this->answer->questionJSId = $this->js_id;
- break;
- case HOT_SPOT_ORDER:
- $this->answer = new ScormAnswerHotspot($this->id);
- $this->answer->questionJSId = $this->js_id;
- break;
- case HOT_SPOT_DELINEATION:
- $this->answer = new ScormAnswerHotspot($this->id);
- $this->answer->questionJSId = $this->js_id;
- break;
- // not supported
- case UNIQUE_ANSWER_NO_OPTION:
- case MULTIPLE_ANSWER_TRUE_FALSE:
- case MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE:
- case UNIQUE_ANSWER_IMAGE:
- case CALCULATED_ANSWER:
- $this->answer = new ScormAnswerMultipleChoice($this->id);
- $this->answer->questionJSId = $this->js_id;
- break;
- default:
- $this->answer = new stdClass();
- $this->answer->questionJSId = $this->js_id;
- break;
- }
- return true;
- }
- /**
- * @throws Exception
- *
- * @return array
- */
- public function export()
- {
- $html = $this->getQuestionHTML();
- $js = $this->getQuestionJS();
- if (is_object($this->answer) && $this->answer instanceof Answer) {
- list($js2, $html2) = $this->answer->export();
- $js .= $js2;
- $html .= $html2;
- } else {
- throw new \Exception('Question not supported. Exercise: '.$this->selectTitle());
- }
- return [$js, $html];
- }
- /**
- * {@inheritdoc}
- */
- public function createAnswersForm($form)
- {
- return true;
- }
- /**
- * {@inheritdoc}
- */
- public function processAnswersCreation($form, $exercise)
- {
- return true;
- }
- /**
- * Returns an HTML-formatted question.
- */
- public function getQuestionHTML()
- {
- $title = $this->selectTitle();
- $description = $this->selectDescription();
- $cols = 2;
- $s = '<tr>
- <td colspan="'.$cols.'" id="question_'.$this->id.'_title" valign="middle" style="background-color:#d6d6d6;">
- '.$title.'
- </td>
- </tr>
- <tr>
- <td valign="top" colspan="'.$cols.'">
- <i>'.$description.'</i>
- </td>
- </tr>';
- return $s;
- }
- /**
- * Return the JavaScript code bound to the question.
- */
- public function getQuestionJS()
- {
- $weight = $this->selectWeighting();
- $js = '
- questions.push('.$this->js_id.');
- $(function() {
- if (exerciseInfo.randomAnswers == true) {
- $("#question_'.$this->js_id.'").shuffleRows();
- }
- });';
- $js .= "\n";
- switch ($this->type) {
- case ORAL_EXPRESSION:
- /*$script = file_get_contents(api_get_path(LIBRARY_PATH) . 'javascript/rtc/RecordRTC.js');
- $script .= file_get_contents(api_get_path(LIBRARY_PATH) . 'wami-recorder/recorder.js');
- $script .= file_get_contents(api_get_path(LIBRARY_PATH) . 'wami-recorder/gui.js');
- $js .= $script;*/
- break;
- case HOT_SPOT:
- //put the max score to 0 to avoid discounting the points of
- //non-exported quiz types in the SCORM
- $weight = 0;
- break;
- }
- $js .= 'questions_score_max['.$this->js_id.'] = '.$weight.";";
- return $js;
- }
- }
|