2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * This behaviour is for information items.
21 * @subpackage informationitem
22 * @copyright 2009 The Open University
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 defined('MOODLE_INTERNAL') ||
die();
31 * Question behaviour informaiton items.
33 * For example for the 'Description' 'Question type'. There is no grade,
34 * and the question type is marked complete the first time the user navigates
35 * away from a page that contains that question.
37 * @copyright 2009 The Open University
38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
40 class qbehaviour_informationitem
extends question_behaviour
{
42 public function is_compatible_question(question_definition
$question) {
46 public function get_expected_data() {
47 if ($this->qa
->get_state() == question_state
::$todo) {
48 return array('seen' => PARAM_BOOL
);
50 return parent
::get_expected_data();
53 public function get_correct_response() {
54 if ($this->qa
->get_state() == question_state
::$todo) {
55 return array('seen' => 1);
60 public function adjust_display_options(question_display_options
$options) {
61 parent
::adjust_display_options($options);
63 $options->marks
= question_display_options
::HIDDEN
;
65 // At the moment, the code exists to process a manual comment on an
66 // information item, but we don't display the UI unless there is already
68 if (!$this->qa
->get_state()->is_commented()) {
69 $options->manualcomment
= question_display_options
::HIDDEN
;
73 public function get_state_string($showcorrectness) {
77 public function process_action(question_attempt_pending_step
$pendingstep) {
78 if ($pendingstep->has_behaviour_var('comment')) {
79 return $this->process_comment($pendingstep);
80 } else if ($pendingstep->has_behaviour_var('finish')) {
81 return $this->process_finish($pendingstep);
82 } else if ($pendingstep->has_behaviour_var('seen')) {
83 return $this->process_seen($pendingstep);
85 return question_attempt
::DISCARD
;
89 public function summarise_action(question_attempt_step
$step) {
90 if ($step->has_behaviour_var('comment')) {
91 return $this->summarise_manual_comment($step);
92 } else if ($step->has_behaviour_var('finish')) {
93 return $this->summarise_finish($step);
94 } else if ($step->has_behaviour_var('seen')) {
95 return get_string('seen', 'qbehaviour_informationitem');
97 return $this->summarise_start($step);
100 public function process_comment(question_attempt_pending_step
$pendingstep) {
101 if ($pendingstep->has_behaviour_var('mark')) {
102 throw new coding_exception('Information items cannot be graded.');
104 return parent
::process_comment($pendingstep);
107 public function process_finish(question_attempt_pending_step
$pendingstep) {
108 $pendingstep->set_state(question_state
::$finished);
109 return question_attempt
::KEEP
;
112 public function process_seen(question_attempt_pending_step
$pendingstep) {
113 $pendingstep->set_state(question_state
::$complete);
114 return question_attempt
::KEEP
;