|
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 00028 defined('MOODLE_INTERNAL') || die(); 00029 00030 00040 class qbehaviour_deferredfeedback extends question_behaviour_with_save { 00041 const IS_ARCHETYPAL = true; 00042 00043 public function is_compatible_question(question_definition $question) { 00044 return $question instanceof question_automatically_gradable; 00045 } 00046 00047 public static function get_unused_display_options() { 00048 return array('correctness', 'marks', 'specificfeedback', 'generalfeedback', 00049 'rightanswer'); 00050 } 00051 00052 public function get_min_fraction() { 00053 return $this->question->get_min_fraction(); 00054 } 00055 00056 public function get_right_answer_summary() { 00057 return $this->question->get_right_answer_summary(); 00058 } 00059 00060 public function process_action(question_attempt_pending_step $pendingstep) { 00061 if ($pendingstep->has_behaviour_var('comment')) { 00062 return $this->process_comment($pendingstep); 00063 } else if ($pendingstep->has_behaviour_var('finish')) { 00064 return $this->process_finish($pendingstep); 00065 } else { 00066 return $this->process_save($pendingstep); 00067 } 00068 } 00069 00070 /* 00071 * Like the parent method, except that when a respones is gradable, but not 00072 * completely, we move it to the invalid state. 00073 * 00074 * TODO refactor, to remove the duplication. 00075 */ 00076 public function process_save(question_attempt_pending_step $pendingstep) { 00077 if ($this->qa->get_state()->is_finished()) { 00078 return question_attempt::DISCARD; 00079 } else if (!$this->qa->get_state()->is_active()) { 00080 throw new coding_exception('Question is not active, cannot process_actions.'); 00081 } 00082 00083 if ($this->is_same_response($pendingstep)) { 00084 return question_attempt::DISCARD; 00085 } 00086 00087 if ($this->is_complete_response($pendingstep)) { 00088 $pendingstep->set_state(question_state::$complete); 00089 } else if ($this->question->is_gradable_response($pendingstep->get_qt_data())) { 00090 $pendingstep->set_state(question_state::$invalid); 00091 } else { 00092 $pendingstep->set_state(question_state::$todo); 00093 } 00094 return question_attempt::KEEP; 00095 } 00096 00097 public function summarise_action(question_attempt_step $step) { 00098 if ($step->has_behaviour_var('comment')) { 00099 return $this->summarise_manual_comment($step); 00100 } else if ($step->has_behaviour_var('finish')) { 00101 return $this->summarise_finish($step); 00102 } else { 00103 return $this->summarise_save($step); 00104 } 00105 } 00106 00107 public function process_finish(question_attempt_pending_step $pendingstep) { 00108 if ($this->qa->get_state()->is_finished()) { 00109 return question_attempt::DISCARD; 00110 } 00111 00112 $response = $this->qa->get_last_step()->get_qt_data(); 00113 if (!$this->question->is_gradable_response($response)) { 00114 $pendingstep->set_state(question_state::$gaveup); 00115 } else { 00116 list($fraction, $state) = $this->question->grade_response($response); 00117 $pendingstep->set_fraction($fraction); 00118 $pendingstep->set_state($state); 00119 } 00120 $pendingstep->set_new_response_summary($this->question->summarise_response($response)); 00121 return question_attempt::KEEP; 00122 } 00123 }