weekly release 4.0dev
[moodle.git] / question / behaviour / manualgraded / behaviour.php
CommitLineData
d1b7e03d 1<?php
d1b7e03d
TH
2// This file is part of Moodle - http://moodle.org/
3//
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.
8//
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.
13//
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/>.
16
d1b7e03d
TH
17/**
18 * Question behaviour for questions that can only be graded manually.
19 *
017bc1d9
TH
20 * @package qbehaviour
21 * @subpackage manualgraded
22 * @copyright 2009 The Open University
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
d1b7e03d
TH
24 */
25
26
a17b297d
TH
27defined('MOODLE_INTERNAL') || die();
28
29
d1b7e03d
TH
30/**
31 * Question behaviour for questions that can only be graded manually.
32 *
33 * The student enters their response during the attempt, and it is saved. Later,
34 * when the whole attempt is finished, the attempt goes into the NEEDS_GRADING
35 * state, and the teacher must grade it manually.
36 *
017bc1d9
TH
37 * @copyright 2009 The Open University
38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
d1b7e03d
TH
39 */
40class qbehaviour_manualgraded extends question_behaviour_with_save {
d1b7e03d 41
06616f4b
TH
42 public function is_compatible_question(question_definition $question) {
43 return $question instanceof question_with_responses;
44 }
45
d1b7e03d
TH
46 public function adjust_display_options(question_display_options $options) {
47 parent::adjust_display_options($options);
48
49 if ($this->qa->get_state()->is_finished()) {
50 // Hide all feedback except genfeedback and manualcomment.
51 $save = clone($options);
52 $options->hide_all_feedback();
53 $options->generalfeedback = $save->generalfeedback;
54 $options->manualcomment = $save->manualcomment;
55 }
56 }
57
58 public function process_action(question_attempt_pending_step $pendingstep) {
59 if ($pendingstep->has_behaviour_var('comment')) {
60 return $this->process_comment($pendingstep);
61 } else if ($pendingstep->has_behaviour_var('finish')) {
62 return $this->process_finish($pendingstep);
63 } else {
64 return $this->process_save($pendingstep);
65 }
66 }
67
94cb5a66
LB
68 /**
69 * Like the parent method, except that when a response is gradable, but not
70 * completely, we move it to the invalid state.
71 * @param question_attempt_pending_step $pendingstep a partially initialised step
72 * containing all the information about the action that is being performed.
73 * @return bool either {@link question_attempt::KEEP} or {@link question_attempt::DISCARD}
74 */
75 public function process_save(question_attempt_pending_step $pendingstep) {
76 if ($this->qa->get_state()->is_finished()) {
77 return question_attempt::DISCARD;
78 } else if (!$this->qa->get_state()->is_active()) {
79 throw new coding_exception('Question is not active, cannot process_actions.');
80 }
81
82 if ($this->is_same_response($pendingstep)) {
83 return question_attempt::DISCARD;
84 }
85
86 if ($this->is_complete_response($pendingstep)) {
87 $pendingstep->set_state(question_state::$complete);
88 } else if ($this->question->is_gradable_response($pendingstep->get_qt_data())) {
89 $pendingstep->set_state(question_state::$invalid);
90 } else {
91 $pendingstep->set_state(question_state::$todo);
92 }
93 return question_attempt::KEEP;
94 }
95
d1b7e03d
TH
96 public function summarise_action(question_attempt_step $step) {
97 if ($step->has_behaviour_var('comment')) {
98 return $this->summarise_manual_comment($step);
99 } else if ($step->has_behaviour_var('finish')) {
100 return $this->summarise_finish($step);
101 } else {
102 return $this->summarise_save($step);
103 }
104 }
105
106 public function process_finish(question_attempt_pending_step $pendingstep) {
107 if ($this->qa->get_state()->is_finished()) {
108 return question_attempt::DISCARD;
109 }
110
111 $response = $this->qa->get_last_step()->get_qt_data();
94cb5a66 112 if (!$this->question->is_gradable_response($response)) {
d1b7e03d
TH
113 $pendingstep->set_state(question_state::$gaveup);
114 } else {
115 $pendingstep->set_state(question_state::$needsgrading);
116 }
117 $pendingstep->set_new_response_summary($this->question->summarise_response($response));
118 return question_attempt::KEEP;
119 }
120}