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 /** 18 * Question behaviour that is like the deferred feedback model, but with 19 * certainty based marking. That is, in addition to the other controls, there are 20 * where the student can indicate how certain they are that their answer is right. 21 * 22 * @package qbehaviour 23 * @subpackage deferredcbm 24 * @copyright 2009 The Open University 25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 26 */ 27 28 29 defined('MOODLE_INTERNAL') || die(); 30 31 require_once (__DIR__ . '/../deferredfeedback/behaviour.php'); 32 33 34 /** 35 * Question behaviour for deferred feedback with certainty based marking. 36 * 37 * The student enters their response during the attempt, along with a certainty, 38 * that is, how sure they are that they are right, and it is saved. Later, 39 * when the whole attempt is finished, their answer is graded. Their degree 40 * of certainty affects their score. 41 * 42 * @copyright 2009 The Open University 43 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 44 */ 45 class qbehaviour_deferredcbm extends qbehaviour_deferredfeedback { 46 const IS_ARCHETYPAL = true; 47 48 public function get_min_fraction() { 49 return question_cbm::adjust_fraction(0, question_cbm::HIGH); 50 } 51 52 public function get_max_fraction() { 53 return question_cbm::adjust_fraction(1, question_cbm::HIGH); 54 } 55 56 public function get_expected_data() { 57 if ($this->qa->get_state()->is_active()) { 58 return array('certainty' => PARAM_INT); 59 } 60 return parent::get_expected_data(); 61 } 62 63 public function get_right_answer_summary() { 64 $summary = parent::get_right_answer_summary(); 65 return question_cbm::summary_with_certainty($summary, question_cbm::HIGH); 66 } 67 68 public function get_correct_response() { 69 if ($this->qa->get_state()->is_active()) { 70 return array('certainty' => question_cbm::HIGH); 71 } 72 return array(); 73 } 74 75 protected function get_our_resume_data() { 76 $lastcertainty = $this->qa->get_last_behaviour_var('certainty'); 77 if ($lastcertainty) { 78 return array('-certainty' => $lastcertainty); 79 } else { 80 return array(); 81 } 82 } 83 84 protected function is_same_response(question_attempt_step $pendingstep) { 85 return parent::is_same_response($pendingstep) && 86 $this->qa->get_last_behaviour_var('certainty') == 87 $pendingstep->get_behaviour_var('certainty'); 88 } 89 90 protected function is_complete_response(question_attempt_step $pendingstep) { 91 return parent::is_complete_response($pendingstep) && 92 $pendingstep->has_behaviour_var('certainty'); 93 } 94 95 public function process_finish(question_attempt_pending_step $pendingstep) { 96 $status = parent::process_finish($pendingstep); 97 if ($status == question_attempt::KEEP) { 98 $fraction = $pendingstep->get_fraction(); 99 if ($this->qa->get_last_step()->has_behaviour_var('certainty')) { 100 $certainty = $this->qa->get_last_step()->get_behaviour_var('certainty'); 101 } else { 102 $certainty = question_cbm::default_certainty(); 103 $pendingstep->set_behaviour_var('_assumedcertainty', $certainty); 104 } 105 if (!is_null($fraction)) { 106 $pendingstep->set_behaviour_var('_rawfraction', $fraction); 107 $pendingstep->set_fraction(question_cbm::adjust_fraction($fraction, $certainty)); 108 } 109 $pendingstep->set_new_response_summary( 110 question_cbm::summary_with_certainty($pendingstep->get_new_response_summary(), 111 $this->qa->get_last_step()->get_behaviour_var('certainty'))); 112 } 113 return $status; 114 } 115 116 public function summarise_action(question_attempt_step $step) { 117 $summary = parent::summarise_action($step); 118 if ($step->has_behaviour_var('certainty')) { 119 $summary = question_cbm::summary_with_certainty($summary, 120 $step->get_behaviour_var('certainty')); 121 } 122 return $summary; 123 } 124 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body