|
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 00042 class qbehaviour_immediatefeedback extends question_behaviour_with_save { 00043 const IS_ARCHETYPAL = true; 00044 00045 public function is_compatible_question(question_definition $question) { 00046 return $question instanceof question_automatically_gradable; 00047 } 00048 00049 public function get_min_fraction() { 00050 return $this->question->get_min_fraction(); 00051 } 00052 00053 public function get_expected_data() { 00054 if ($this->qa->get_state()->is_active()) { 00055 return array( 00056 'submit' => PARAM_BOOL, 00057 ); 00058 } 00059 return parent::get_expected_data(); 00060 } 00061 00062 public function get_state_string($showcorrectness) { 00063 $state = $this->qa->get_state(); 00064 if ($state == question_state::$todo) { 00065 return get_string('notcomplete', 'qbehaviour_immediatefeedback'); 00066 } else { 00067 return parent::get_state_string($showcorrectness); 00068 } 00069 } 00070 00071 public function get_right_answer_summary() { 00072 return $this->question->get_right_answer_summary(); 00073 } 00074 00075 public function process_action(question_attempt_pending_step $pendingstep) { 00076 if ($pendingstep->has_behaviour_var('comment')) { 00077 return $this->process_comment($pendingstep); 00078 } else if ($pendingstep->has_behaviour_var('submit')) { 00079 return $this->process_submit($pendingstep); 00080 } else if ($pendingstep->has_behaviour_var('finish')) { 00081 return $this->process_finish($pendingstep); 00082 } else { 00083 return $this->process_save($pendingstep); 00084 } 00085 } 00086 00087 public function summarise_action(question_attempt_step $step) { 00088 if ($step->has_behaviour_var('comment')) { 00089 return $this->summarise_manual_comment($step); 00090 } else if ($step->has_behaviour_var('finish')) { 00091 return $this->summarise_finish($step); 00092 } else if ($step->has_behaviour_var('submit')) { 00093 return $this->summarise_submit($step); 00094 } else { 00095 return $this->summarise_save($step); 00096 } 00097 } 00098 00099 public function process_submit(question_attempt_pending_step $pendingstep) { 00100 if ($this->qa->get_state()->is_finished()) { 00101 return question_attempt::DISCARD; 00102 } 00103 00104 if (!$this->is_complete_response($pendingstep)) { 00105 $pendingstep->set_state(question_state::$invalid); 00106 00107 } else { 00108 $response = $pendingstep->get_qt_data(); 00109 list($fraction, $state) = $this->question->grade_response($response); 00110 $pendingstep->set_fraction($fraction); 00111 $pendingstep->set_state($state); 00112 $pendingstep->set_new_response_summary($this->question->summarise_response($response)); 00113 } 00114 return question_attempt::KEEP; 00115 } 00116 00117 public function process_finish(question_attempt_pending_step $pendingstep) { 00118 if ($this->qa->get_state()->is_finished()) { 00119 return question_attempt::DISCARD; 00120 } 00121 00122 $response = $this->qa->get_last_step()->get_qt_data(); 00123 if (!$this->question->is_gradable_response($response)) { 00124 $pendingstep->set_state(question_state::$gaveup); 00125 00126 } else { 00127 list($fraction, $state) = $this->question->grade_response($response); 00128 $pendingstep->set_fraction($fraction); 00129 $pendingstep->set_state($state); 00130 } 00131 $pendingstep->set_new_response_summary($this->question->summarise_response($response)); 00132 return question_attempt::KEEP; 00133 } 00134 00135 public function process_save(question_attempt_pending_step $pendingstep) { 00136 $status = parent::process_save($pendingstep); 00137 if ($status == question_attempt::KEEP && 00138 $pendingstep->get_state() == question_state::$complete) { 00139 $pendingstep->set_state(question_state::$todo); 00140 } 00141 return $status; 00142 } 00143 }