|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00016 00029 defined('MOODLE_INTERNAL') || die(); 00030 00031 require_once(dirname(__FILE__) . '/../deferredfeedback/behaviour.php'); 00032 00033 00045 class qbehaviour_deferredcbm extends qbehaviour_deferredfeedback { 00046 const IS_ARCHETYPAL = true; 00047 00048 public static function get_unused_display_options() { 00049 return array('correctness', 'marks', 'specificfeedback', 'generalfeedback', 00050 'rightanswer'); 00051 } 00052 00053 public function get_min_fraction() { 00054 return question_cbm::adjust_fraction(parent::get_min_fraction(), question_cbm::HIGH); 00055 } 00056 00057 public function get_expected_data() { 00058 if ($this->qa->get_state()->is_active()) { 00059 return array('certainty' => PARAM_INT); 00060 } 00061 return parent::get_expected_data(); 00062 } 00063 00064 public function get_right_answer_summary() { 00065 $summary = parent::get_right_answer_summary(); 00066 return $summary . ' [' . question_cbm::get_string(question_cbm::HIGH) . ']'; 00067 } 00068 00069 public function get_correct_response() { 00070 if ($this->qa->get_state()->is_active()) { 00071 return array('certainty' => question_cbm::HIGH); 00072 } 00073 return array(); 00074 } 00075 00076 protected function get_our_resume_data() { 00077 $lastcertainty = $this->qa->get_last_behaviour_var('certainty'); 00078 if ($lastcertainty) { 00079 return array('-certainty' => $lastcertainty); 00080 } else { 00081 return array(); 00082 } 00083 } 00084 00085 protected function is_same_response($pendingstep) { 00086 return parent::is_same_response($pendingstep) && 00087 $this->qa->get_last_behaviour_var('certainty') == 00088 $pendingstep->get_behaviour_var('certainty'); 00089 } 00090 00091 protected function is_complete_response($pendingstep) { 00092 return parent::is_complete_response($pendingstep) && 00093 $pendingstep->has_behaviour_var('certainty'); 00094 } 00095 00096 public function process_finish(question_attempt_pending_step $pendingstep) { 00097 $status = parent::process_finish($pendingstep); 00098 if ($status == question_attempt::KEEP) { 00099 $fraction = $pendingstep->get_fraction(); 00100 if ($this->qa->get_last_step()->has_behaviour_var('certainty')) { 00101 $certainty = $this->qa->get_last_step()->get_behaviour_var('certainty'); 00102 } else { 00103 $certainty = question_cbm::default_certainty(); 00104 $pendingstep->set_behaviour_var('_assumedcertainty', $certainty); 00105 } 00106 if (!is_null($fraction)) { 00107 $pendingstep->set_behaviour_var('_rawfraction', $fraction); 00108 $pendingstep->set_fraction(question_cbm::adjust_fraction($fraction, $certainty)); 00109 } 00110 $pendingstep->set_new_response_summary( 00111 question_cbm::summary_with_certainty($pendingstep->get_new_response_summary(), 00112 $this->qa->get_last_step()->get_behaviour_var('certainty'))); 00113 } 00114 return $status; 00115 } 00116 00117 public function summarise_action(question_attempt_step $step) { 00118 $summary = parent::summarise_action($step); 00119 if ($step->has_behaviour_var('certainty')) { 00120 $summary = question_cbm::summary_with_certainty($summary, 00121 $step->get_behaviour_var('certainty')); 00122 } 00123 return $summary; 00124 } 00125 00126 public static function adjust_random_guess_score($fraction) { 00127 return question_cbm::adjust_fraction($fraction, question_cbm::default_certainty()); 00128 } 00129 }