|
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 00027 defined('MOODLE_INTERNAL') || die(); 00028 00029 00040 class qbehaviour_informationitem extends question_behaviour { 00041 00042 public function is_compatible_question(question_definition $question) { 00043 return true; 00044 } 00045 00046 public function get_expected_data() { 00047 if ($this->qa->get_state() == question_state::$todo) { 00048 return array('seen' => PARAM_BOOL); 00049 } 00050 return parent::get_expected_data(); 00051 } 00052 00053 public function get_correct_response() { 00054 if ($this->qa->get_state() == question_state::$todo) { 00055 return array('seen' => 1); 00056 } 00057 return array(); 00058 } 00059 00060 public function adjust_display_options(question_display_options $options) { 00061 parent::adjust_display_options($options); 00062 00063 $options->marks = question_display_options::HIDDEN; 00064 00065 // At the moment, the code exists to process a manual comment on an 00066 // information item, but we don't display the UI unless there is already 00067 // a comment. 00068 if (!$this->qa->get_state()->is_commented()) { 00069 $options->manualcomment = question_display_options::HIDDEN; 00070 } 00071 } 00072 00073 public function get_state_string($showcorrectness) { 00074 return ''; 00075 } 00076 00077 public function process_action(question_attempt_pending_step $pendingstep) { 00078 if ($pendingstep->has_behaviour_var('comment')) { 00079 return $this->process_comment($pendingstep); 00080 } else if ($pendingstep->has_behaviour_var('finish')) { 00081 return $this->process_finish($pendingstep); 00082 } else if ($pendingstep->has_behaviour_var('seen')) { 00083 return $this->process_seen($pendingstep); 00084 } else { 00085 return question_attempt::DISCARD; 00086 } 00087 } 00088 00089 public function summarise_action(question_attempt_step $step) { 00090 if ($step->has_behaviour_var('comment')) { 00091 return $this->summarise_manual_comment($step); 00092 } else if ($step->has_behaviour_var('finish')) { 00093 return $this->summarise_finish($step); 00094 } else if ($step->has_behaviour_var('seen')) { 00095 return get_string('seen', 'qbehaviour_informationitem'); 00096 } 00097 return $this->summarise_start($step); 00098 } 00099 00100 public function process_comment(question_attempt_pending_step $pendingstep) { 00101 if ($pendingstep->has_behaviour_var('mark')) { 00102 throw new coding_exception('Information items cannot be graded.'); 00103 } 00104 return parent::process_comment($pendingstep); 00105 } 00106 00107 public function process_finish(question_attempt_pending_step $pendingstep) { 00108 $pendingstep->set_state(question_state::$finished); 00109 return question_attempt::KEEP; 00110 } 00111 00112 public function process_seen(question_attempt_pending_step $pendingstep) { 00113 $pendingstep->set_state(question_state::$complete); 00114 return question_attempt::KEEP; 00115 } 00116 }