Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/question/behaviour/immediatecbm/behaviour.php
Go to the documentation of this file.
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 
00028 defined('MOODLE_INTERNAL') || die();
00029 
00030 require_once(dirname(__FILE__) . '/../immediatefeedback/behaviour.php');
00031 
00032 
00045 class qbehaviour_immediatecbm extends qbehaviour_immediatefeedback {
00046     const IS_ARCHETYPAL = true;
00047 
00048     public function get_min_fraction() {
00049         return question_cbm::adjust_fraction(parent::get_min_fraction(), question_cbm::HIGH);
00050     }
00051 
00052     public function get_expected_data() {
00053         if ($this->qa->get_state()->is_active()) {
00054             return array(
00055                 'submit' => PARAM_BOOL,
00056                 'certainty' => PARAM_INT,
00057             );
00058         }
00059         return parent::get_expected_data();
00060     }
00061 
00062     public function get_right_answer_summary() {
00063         $summary = parent::get_right_answer_summary();
00064         return question_cbm::summary_with_certainty($summary, question_cbm::HIGH);
00065     }
00066 
00067     public function get_correct_response() {
00068         if ($this->qa->get_state()->is_active()) {
00069             return array('certainty' => question_cbm::HIGH);
00070         }
00071         return array();
00072     }
00073 
00074     protected function get_our_resume_data() {
00075         $lastcertainty = $this->qa->get_last_behaviour_var('certainty');
00076         if ($lastcertainty) {
00077             return array('-certainty' => $lastcertainty);
00078         } else {
00079             return array();
00080         }
00081     }
00082 
00083     protected function is_same_response($pendingstep) {
00084         return parent::is_same_response($pendingstep) &&
00085                 $this->qa->get_last_behaviour_var('certainty') ==
00086                         $pendingstep->get_behaviour_var('certainty');
00087     }
00088 
00089     protected function is_complete_response($pendingstep) {
00090         return parent::is_complete_response($pendingstep) &&
00091                 $pendingstep->has_behaviour_var('certainty');
00092     }
00093 
00094     public function process_submit(question_attempt_pending_step $pendingstep) {
00095         if ($this->qa->get_state()->is_finished()) {
00096             return question_attempt::DISCARD;
00097         }
00098 
00099         if (!$this->qa->get_question()->is_gradable_response($pendingstep->get_qt_data()) ||
00100                 !$pendingstep->has_behaviour_var('certainty')) {
00101             $pendingstep->set_state(question_state::$invalid);
00102             return question_attempt::KEEP;
00103         }
00104 
00105         return $this->do_grading($pendingstep, $pendingstep);
00106     }
00107 
00108     public function process_finish(question_attempt_pending_step $pendingstep) {
00109         if ($this->qa->get_state()->is_finished()) {
00110             return question_attempt::DISCARD;
00111         }
00112 
00113         $laststep = $this->qa->get_last_step();
00114         return $this->do_grading($laststep, $pendingstep);
00115     }
00116 
00117     protected function do_grading(question_attempt_step $responsesstep,
00118             question_attempt_pending_step $pendingstep) {
00119         if (!$this->question->is_gradable_response($responsesstep->get_qt_data())) {
00120             $pendingstep->set_state(question_state::$gaveup);
00121 
00122         } else {
00123             $response = $responsesstep->get_qt_data();
00124             list($fraction, $state) = $this->question->grade_response($response);
00125 
00126             if ($responsesstep->has_behaviour_var('certainty')) {
00127                 $certainty = $responsesstep->get_behaviour_var('certainty');
00128             } else {
00129                 $certainty = question_cbm::default_certainty();
00130                 $pendingstep->set_behaviour_var('_assumedcertainty', $certainty);
00131             }
00132 
00133             $pendingstep->set_behaviour_var('_rawfraction', $fraction);
00134             $pendingstep->set_fraction(question_cbm::adjust_fraction($fraction, $certainty));
00135             $pendingstep->set_state($state);
00136             $pendingstep->set_new_response_summary(question_cbm::summary_with_certainty(
00137                     $this->question->summarise_response($response),
00138                     $responsesstep->get_behaviour_var('certainty')));
00139         }
00140         return question_attempt::KEEP;
00141     }
00142 
00143     public function summarise_action(question_attempt_step $step) {
00144         $summary = parent::summarise_action($step);
00145         if ($step->has_behaviour_var('certainty')) {
00146             $summary = question_cbm::summary_with_certainty($summary,
00147                     $step->get_behaviour_var('certainty'));
00148         }
00149         return $summary;
00150     }
00151 
00152     public static function adjust_random_guess_score($fraction) {
00153         return question_cbm::adjust_fraction($fraction, question_cbm::default_certainty());
00154     }
00155 }
 All Data Structures Namespaces Files Functions Variables Enumerations