Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/question/behaviour/interactivecountback/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__) . '/../interactive/behaviour.php');
00031 
00032 
00064 class qbehaviour_interactivecountback extends qbehaviour_interactive {
00065     const IS_ARCHETYPAL = false;
00066 
00067     public function is_compatible_question(question_definition $question) {
00068         return $question instanceof question_automatically_gradable_with_countback;
00069     }
00070 
00071     protected function adjust_fraction($fraction, question_attempt_pending_step $pendingstep) {
00072         $totaltries = $this->qa->get_step(0)->get_behaviour_var('_triesleft');
00073 
00074         $responses = array();
00075         $lastsave = array();
00076         foreach ($this->qa->get_step_iterator() as $step) {
00077             if ($step->has_behaviour_var('submit') &&
00078                     $step->get_state() != question_state::$invalid) {
00079                 $responses[] = $step->get_qt_data();
00080                 $lastsave = array();
00081             } else {
00082                 $lastsave = $step->get_qt_data();
00083             }
00084         }
00085         $lastresponse = $pendingstep->get_qt_data();
00086         if (!empty($lastresponse)) {
00087             $responses[] = $lastresponse;
00088         } else if (!empty($lastsave)) {
00089             $responses[] = $lastsave;
00090         }
00091 
00092         return $this->question->compute_final_grade($responses, $totaltries);
00093     }
00094 }
 All Data Structures Namespaces Files Functions Variables Enumerations