[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/backup/cc/cc_lib/ -> cc_assesment_truefalse.php (source)

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  /**
  17   * @package    backup-convert
  18   * @copyright  2012 Darko Miletic <[email protected]>
  19   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  20   */
  21  
  22  defined('MOODLE_INTERNAL') or die('Direct access to this script is forbidden.');
  23  
  24  require_once ('cc_asssesment.php');
  25  
  26  class cc_assesment_question_truefalse extends cc_assesment_question_proc_base {
  27      public function __construct($quiz, $questions, $manifest, $section, $question_node, $rootpath, $contextid, $outdir) {
  28          parent::__construct($quiz, $questions, $manifest, $section, $question_node, $rootpath, $contextid, $outdir);
  29          $this->qtype = cc_qti_profiletype::true_false;
  30          $this->correct_answer_node_id = $this->questions->nodeValue(
  31              'plugin_qtype_truefalse_question/truefalse/trueanswer', $this->question_node);
  32          $maximum_quiz_grade = (int)$this->quiz->nodeValue('/activity/quiz/grade');
  33          $this->total_grade_value = ($maximum_quiz_grade + 1).'.0000000';
  34      }
  35  
  36      public function on_generate_answers() {
  37          // Add responses holder.
  38          $qresponse_lid = new cc_response_lidtype();
  39          $this->qresponse_lid = $qresponse_lid;
  40          $this->qpresentation->set_response_lid($qresponse_lid);
  41          $qresponse_choice = new cc_assesment_render_choicetype();
  42          $qresponse_lid->set_render_choice($qresponse_choice);
  43          // Mark that question has only one correct answer -
  44          // which applies for multiple choice and yes/no questions.
  45          $qresponse_lid->set_rcardinality(cc_qti_values::Single);
  46          // Are we to shuffle the responses?
  47          $shuffle_answers = (int)$this->quiz->nodeValue('/activity/quiz/shuffleanswers') > 0;
  48          $qresponse_choice->enable_shuffle($shuffle_answers);
  49          $answerlist = array();
  50          $qa_responses = $this->questions->nodeList('plugin_qtype_truefalse_question/answers/answer', $this->question_node);
  51          foreach ($qa_responses as $node) {
  52              $answer_content = $this->questions->nodeValue('answertext', $node);
  53              $id = ((int)$this->questions->nodeValue('@id', $node) == $this->correct_answer_node_id);
  54              $qresponse_label = cc_assesment_helper::add_answer( $qresponse_choice,
  55                                                                  $answer_content,
  56                                                                  cc_qti_values::htmltype);
  57              $answer_ident = strtolower(trim($answer_content));
  58              $qresponse_label->set_ident($answer_ident);
  59              $feedback_ident = ($id) ? 'correct_fb' : 'incorrect_fb';
  60              if (empty($this->correct_answer_ident) && $id) {
  61                  $this->correct_answer_ident = $answer_ident;
  62              }
  63              // Add answer specific feedback if not empty.
  64              $content = $this->questions->nodeValue('feedback', $node);
  65              if (!empty($content)) {
  66                  $result = cc_helpers::process_linked_files( $content,
  67                                                              $this->manifest,
  68                                                              $this->rootpath,
  69                                                              $this->contextid,
  70                                                              $this->outdir);
  71  
  72  
  73                  cc_assesment_helper::add_feedback( $this->qitem,
  74                                                      $result[0],
  75                                                      cc_qti_values::htmltype,
  76                                                      $feedback_ident);
  77  
  78                  pkg_resource_dependencies::instance()->add($result[1]);
  79  
  80                  $answerlist[$answer_ident] = $feedback_ident;
  81              }
  82          }
  83  
  84          $this->answerlist = $answerlist;
  85  
  86      }
  87  
  88      public function on_generate_response_processing() {
  89          parent::on_generate_response_processing();
  90  
  91          // Response conditions.
  92          // General unconditional feedback must be added as a first respcondition
  93          // without any condition and just displayfeedback (if exists).
  94          if (!empty($this->general_feedback)) {
  95              $qrespcondition = new cc_assesment_respconditiontype();
  96              $qrespcondition->set_title('General feedback');
  97              $this->qresprocessing->add_respcondition($qrespcondition);
  98              $qrespcondition->enable_continue();
  99              // Define the condition for success.
 100              $qconditionvar = new cc_assignment_conditionvar();
 101              $qrespcondition->set_conditionvar($qconditionvar);
 102              $qother = new cc_assignment_conditionvar_othertype();
 103              $qconditionvar->set_other($qother);
 104              $qdisplayfeedback = new cc_assignment_displayfeedbacktype();
 105              $qrespcondition->add_displayfeedback($qdisplayfeedback);
 106              $qdisplayfeedback->set_feedbacktype(cc_qti_values::Response);
 107              $qdisplayfeedback->set_linkrefid('general_fb');
 108          }
 109  
 110          // Success condition.
 111          // For all question types outside of the Essay question, scoring is done in a
 112          // single <respcondition> with a continue flag set to No. The outcome is always
 113          // a variable named SCORE which value must be set to 100 in case of correct answer.
 114          // Partial scores (not 0 or 100) are not supported.
 115          $qrespcondition = new cc_assesment_respconditiontype();
 116          $qrespcondition->set_title('Correct');
 117          $this->qresprocessing->add_respcondition($qrespcondition);
 118          $qrespcondition->enable_continue(false);
 119          $qsetvar = new cc_assignment_setvartype(100);
 120          $qrespcondition->add_setvar($qsetvar);
 121          // Define the condition for success.
 122          $qconditionvar = new cc_assignment_conditionvar();
 123          $qrespcondition->set_conditionvar($qconditionvar);
 124          // TODO: recheck this.
 125          $qvarequal = new cc_assignment_conditionvar_varequaltype($this->correct_answer_ident);
 126          $qconditionvar->set_varequal($qvarequal);
 127          $qvarequal->set_respident($this->qresponse_lid->get_ident());
 128  
 129          if (array_key_exists($this->correct_answer_ident, $this->answerlist)) {
 130              $qdisplayfeedback = new cc_assignment_displayfeedbacktype();
 131              $qrespcondition->add_displayfeedback($qdisplayfeedback);
 132              $qdisplayfeedback->set_feedbacktype(cc_qti_values::Response);
 133              $qdisplayfeedback->set_linkrefid($this->answerlist[$this->correct_answer_ident]);
 134          }
 135  
 136          foreach ($this->correct_feedbacks as $ident) {
 137              $qdisplayfeedback = new cc_assignment_displayfeedbacktype();
 138              $qrespcondition->add_displayfeedback($qdisplayfeedback);
 139              $qdisplayfeedback->set_feedbacktype(cc_qti_values::Response);
 140              $qdisplayfeedback->set_linkrefid($ident);
 141          }
 142  
 143          // Rest of the conditions.
 144          foreach ($this->answerlist as $ident => $refid) {
 145              if ($ident == $this->correct_answer_ident) {
 146                  continue;
 147              }
 148  
 149              $qrespcondition = new cc_assesment_respconditiontype();
 150              $this->qresprocessing->add_respcondition($qrespcondition);
 151              $qsetvar = new cc_assignment_setvartype(0);
 152              $qrespcondition->add_setvar($qsetvar);
 153              // Define the condition for fail.
 154              $qconditionvar = new cc_assignment_conditionvar();
 155              $qrespcondition->set_conditionvar($qconditionvar);
 156              $qvarequal = new cc_assignment_conditionvar_varequaltype($ident);
 157              $qconditionvar->set_varequal($qvarequal);
 158              $qvarequal->set_respident($this->qresponse_lid->get_ident());
 159  
 160              $qdisplayfeedback = new cc_assignment_displayfeedbacktype();
 161              $qrespcondition->add_displayfeedback($qdisplayfeedback);
 162              $qdisplayfeedback->set_feedbacktype(cc_qti_values::Response);
 163              $qdisplayfeedback->set_linkrefid($refid);
 164  
 165              foreach ($this->incorrect_feedbacks as $ident) {
 166                  $qdisplayfeedback = new cc_assignment_displayfeedbacktype();
 167                  $qrespcondition->add_displayfeedback($qdisplayfeedback);
 168                  $qdisplayfeedback->set_feedbacktype(cc_qti_values::Response);
 169                  $qdisplayfeedback->set_linkrefid($ident);
 170              }
 171          }
 172      }
 173  }


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1