public function on_generate_feedbacks() { parent::on_generate_feedbacks(); // Question combined feedback. $responsenodes = $this->questions->nodeList('plugin_qtype_shortanswer_question//answer', $this->question_node); $count = 0; foreach ($responsenodes as $respnode) { $content = $this->questions->nodeValue('feedback', $respnode); if (empty($content)) { continue; } $correct = (int) $this->questions->nodeValue('fraction', $respnode) == 1; $answerid = (int) $this->questions->nodeValue('@id', $respnode); $result = cc_helpers::process_linked_files($content, $this->manifest, $this->rootpath, $this->contextid, $this->outdir); $ident = $correct ? 'correct' : 'incorrect'; $ident .= '_' . $count . '_fb'; cc_assesment_helper::add_feedback($this->qitem, $result[0], cc_qti_values::htmltype, $ident); pkg_resource_dependencies::instance()->add($result[1]); if ($correct) { $this->correct_feedbacks[$answerid] = $ident; } else { $this->incorrect_feedbacks[$answerid] = $ident; } ++$count; } }
public function on_generate_answers() { // Add responses holder. $qresponse_lid = new cc_response_lidtype(); $this->qresponse_lid = $qresponse_lid; $this->qpresentation->set_response_lid($qresponse_lid); $qresponse_choice = new cc_assesment_render_choicetype(); $qresponse_lid->set_render_choice($qresponse_choice); // Mark that question has only one correct answer - // which applies for multiple choice and yes/no questions. $qresponse_lid->set_rcardinality(cc_qti_values::Single); // Are we to shuffle the responses? $shuffle_answers = (int) $this->quiz->nodeValue('/activity/quiz/shuffleanswers') > 0; $qresponse_choice->enable_shuffle($shuffle_answers); $answerlist = array(); $qa_responses = $this->questions->nodeList('plugin_qtype_truefalse_question/answers/answer', $this->question_node); foreach ($qa_responses as $node) { $answer_content = $this->questions->nodeValue('answertext', $node); $id = (int) $this->questions->nodeValue('@id', $node) == $this->correct_answer_node_id; $qresponse_label = cc_assesment_helper::add_answer($qresponse_choice, $answer_content, cc_qti_values::htmltype); $answer_ident = strtolower(trim($answer_content)); $qresponse_label->set_ident($answer_ident); $feedback_ident = $id ? 'correct_fb' : 'incorrect_fb'; if (empty($this->correct_answer_ident) && $id) { $this->correct_answer_ident = $answer_ident; } // Add answer specific feedback if not empty. $content = $this->questions->nodeValue('feedback', $node); if (!empty($content)) { $result = cc_helpers::process_linked_files($content, $this->manifest, $this->rootpath, $this->contextid, $this->outdir); cc_assesment_helper::add_feedback($this->qitem, $result[0], cc_qti_values::htmltype, $feedback_ident); pkg_resource_dependencies::instance()->add($result[1]); $answerlist[$answer_ident] = $feedback_ident; } } $this->answerlist = $answerlist; }
/** * @return pkg_resource_dependencies */ public static function instance() { if (empty(self::$instance)) { $c = __CLASS__; self::$instance = new $c(); } return self::$instance; }
public function on_generate_feedbacks() { parent::on_generate_feedbacks(); //Question combined feedbacks $correct_question_fb = $this->questions->nodeValue('plugin_qtype_multichoice_question/multichoice/correctfeedback', $this->question_node); $incorrect_question_fb = $this->questions->nodeValue('plugin_qtype_multichoice_question/multichoice/incorrectfeedback', $this->question_node); if (empty($correct_question_fb)) { //Hardcode some text for now $correct_question_fb = 'Well done!'; } if (empty($incorrect_question_fb)) { //Hardcode some text for now $incorrect_question_fb = 'Better luck next time!'; } $proc = array('correct_fb' => $correct_question_fb, 'incorrect_fb' => $incorrect_question_fb); foreach ($proc as $ident => $content) { if (empty($content)) { continue; } $result = cc_helpers::process_linked_files($content, $this->manifest, $this->rootpath, $this->contextid, $this->outdir); cc_assesment_helper::add_feedback($this->qitem, $result[0], cc_qti_values::htmltype, $ident); pkg_resource_dependencies::instance()->add($result[1]); if ($ident == 'correct_fb') { $this->correct_feedbacks[$ident] = $ident; } else { $this->incorrect_feedbacks[$ident] = $ident; } } }