Example #1
0
 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;
     }
 }
Example #2
0
 public function convert($outdir)
 {
     $rt = new assesment11_resurce_file();
     $title = $this->doc->nodeValue('/activity/quiz/name');
     $rt->set_title($title);
     // Metadata.
     $metadata = new cc_assesment_metadata();
     $rt->set_metadata($metadata);
     $metadata->enable_feedback();
     $metadata->enable_hints();
     $metadata->enable_solutions();
     // Attempts.
     $max_attempts = (int) $this->doc->nodeValue('/activity/quiz/attempts_number');
     if ($max_attempts > 0) {
         // Qti does not support number of specific attempts bigger than 5 (??)
         if ($max_attempts > 5) {
             $max_attempts = cc_qti_values::unlimited;
         }
         $metadata->set_maxattempts($max_attempts);
     }
     // Time limit must be converted into minutes.
     $timelimit = (int) floor((int) $this->doc->nodeValue('/activity/quiz/timelimit') / 60);
     if ($timelimit > 0) {
         $metadata->set_timelimit($timelimit);
         $metadata->enable_latesubmissions(false);
     }
     $contextid = $this->doc->nodeValue('/activity/@contextid');
     $result = cc_helpers::process_linked_files($this->doc->nodeValue('/activity/quiz/intro'), $this->manifest, $this->rootpath, $contextid, $outdir);
     cc_assesment_helper::add_assesment_description($rt, $result[0], cc_qti_values::htmltype);
     // Section.
     $section = new cc_assesment_section();
     $rt->set_section($section);
     // Process the actual questions.
     $ndeps = cc_assesment_helper::process_questions($this->doc, $this->manifest, $section, $this->rootpath, $contextid, $outdir);
     if ($ndeps === false) {
         // No exportable questions in quiz or quiz has no questions
         // so just skip it.
         return true;
     }
     // Store any additional dependencies.
     $deps = array_merge($result[1], $ndeps);
     // Store everything.
     $this->store($rt, $outdir, $title, $deps);
     return true;
 }
 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;
 }
Example #4
0
 public function on_generate_response_processing()
 {
     parent::on_generate_response_processing();
     //respconditions
     /**
      * General unconditional feedback must be added as a first respcondition
      * without any condition and just displayfeedback (if exists)
      */
     cc_assesment_helper::add_respcondition($this->qresprocessing, 'General feedback', $this->general_feedback, null, true);
     //success condition
     /**
      * For all question types outside of the Essay question, scoring is done in a
      * single <respcondition> with a continue flag set to No. The outcome is always
      * a variable named SCORE which value must be set to 100 in case of correct answer.
      * Partial scores (not 0 or 100) are not supported.
      */
     $qrespcondition = new cc_assesment_respconditiontype();
     $qrespcondition->set_title('Correct');
     $this->qresprocessing->add_respcondition($qrespcondition);
     $qrespcondition->enable_continue(false);
     $qsetvar = new cc_assignment_setvartype(100);
     $qrespcondition->add_setvar($qsetvar);
     //define the condition for success
     $qconditionvar = new cc_assignment_conditionvar();
     $qrespcondition->set_conditionvar($qconditionvar);
     //create root and condition
     $qandcondition = new cc_assignment_conditionvar_andtype();
     $qconditionvar->set_and($qandcondition);
     foreach ($this->answerlist as $ident => $refid) {
         $qvarequal = new cc_assignment_conditionvar_varequaltype($ident);
         $qvarequal->enable_case();
         if ($refid[1]) {
             $qandcondition->set_varequal($qvarequal);
         } else {
             $qandcondition->set_not($qvarequal);
         }
         $qvarequal->set_respident($this->qresponse_lid->get_ident());
     }
     $qdisplayfeedback = new cc_assignment_displayfeedbacktype();
     $qrespcondition->add_displayfeedback($qdisplayfeedback);
     $qdisplayfeedback->set_feedbacktype(cc_qti_values::Response);
     //TODO: this needs to be fixed
     reset($this->correct_feedbacks);
     $ident = key($this->correct_feedbacks);
     $qdisplayfeedback->set_linkrefid($ident);
     //rest of the conditions
     foreach ($this->answerlist as $ident => $refid) {
         cc_assesment_helper::add_response_condition($this->qresprocessing, 'Incorrect feedback', $refid[0], $this->general_feedback, $this->qresponse_lid->get_ident());
     }
     //Final element for incorrect feedback
     reset($this->incorrect_feedbacks);
     $ident = key($this->incorrect_feedbacks);
     cc_assesment_helper::add_respcondition($this->qresprocessing, 'Incorrect feedback', $ident, 0);
 }
 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);
     $proc = array('correct_fb' => $correct_question_fb, 'general_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;
         } else {
             $this->incorrect_feedbacks[] = $ident;
         }
     }
 }