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 page is the entry page into the quiz UI. Displays information about the
19 * quiz to students and teachers, and lets students see their previous attempts.
23 * @copyright 2008 Tim Hunt
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 defined('MOODLE_INTERNAL') ||
die();
32 * Admin settings class for the quiz review opitions.
34 * @copyright 2008 Tim Hunt
35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37 class mod_quiz_admin_review_setting
extends admin_setting
{
39 * @var integer should match the constants defined in {@link mod_quiz_display_options}.
40 * again, copied for performance reasons.
42 const DURING
= 0x10000;
43 const IMMEDIATELY_AFTER
= 0x01000;
44 const LATER_WHILE_OPEN
= 0x00100;
45 const AFTER_CLOSE
= 0x00010;
49 * @var boolean|null forced checked / disabled attributes for the during time.
51 protected $duringstate;
54 * This should match {@link mod_quiz_mod_form::$reviewfields} but copied
55 * here because generating the admin tree needs to be fast.
58 public static function fields() {
60 'attempt' => get_string('theattempt', 'quiz'),
61 'correctness' => get_string('whethercorrect', 'question'),
62 'marks' => get_string('marks', 'question'),
63 'specificfeedback' => get_string('specificfeedback', 'question'),
64 'generalfeedback' => get_string('generalfeedback', 'question'),
65 'rightanswer' => get_string('rightanswer', 'question'),
66 'overallfeedback' => get_string('overallfeedback', 'quiz'),
70 public function __construct($name, $visiblename, $description,
71 $defaultsetting, $duringstate = null) {
72 $this->duringstate
= $duringstate;
73 parent
::__construct($name, $visiblename, $description, $defaultsetting);
77 * @return int all times.
79 public static function all_on() {
80 return self
::DURING | self
::IMMEDIATELY_AFTER | self
::LATER_WHILE_OPEN |
84 protected static function times() {
86 self
::DURING
=> get_string('reviewduring', 'quiz'),
87 self
::IMMEDIATELY_AFTER
=> get_string('reviewimmediately', 'quiz'),
88 self
::LATER_WHILE_OPEN
=> get_string('reviewopen', 'quiz'),
89 self
::AFTER_CLOSE
=> get_string('reviewclosed', 'quiz'),
93 protected function normalise_data($data) {
94 $times = self
::times();
96 foreach ($times as $timemask => $name) {
97 if ($timemask == self
::DURING
&& !is_null($this->duringstate
)) {
98 if ($this->duringstate
) {
101 } else if (!empty($data[$timemask])) {
108 public function get_setting() {
109 return $this->config_read($this->name
);
112 public function write_setting($data) {
113 if (is_array($data) ||
empty($data)) {
114 $data = $this->normalise_data($data);
116 $this->config_write($this->name
, $data);
120 public function output_html($data, $query = '') {
121 if (is_array($data) ||
empty($data)) {
122 $data = $this->normalise_data($data);
125 $return = '<div class="group"><input type="hidden" name="' .
126 $this->get_full_name() . '[' . self
::DURING
. ']" value="0" />';
127 foreach (self
::times() as $timemask => $namestring) {
128 $id = $this->get_id(). '_' . $timemask;
130 if ($data & $timemask) {
131 $state = 'checked="checked" ';
133 if ($timemask == self
::DURING
&& !is_null($this->duringstate
)) {
134 $state = 'disabled="disabled" ';
135 if ($this->duringstate
) {
136 $state .= 'checked="checked" ';
139 $return .= '<span><input type="checkbox" name="' .
140 $this->get_full_name() . '[' . $timemask . ']" value="1" id="' . $id .
141 '" ' . $state . '/> <label for="' . $id . '">' .
142 $namestring . "</label></span>\n";
144 $return .= "</div>\n";
146 return format_admin_setting($this, $this->visiblename
, $return,
147 $this->description
, true, '', get_string('everythingon', 'quiz'), $query);
153 * Admin settings class for the quiz grading method.
155 * Just so we can lazy-load the choices.
157 * @copyright 2011 The Open University
158 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
160 class mod_quiz_admin_setting_grademethod
extends admin_setting_configselect_with_advanced
{
161 public function load_choices() {
164 if (is_array($this->choices
)) {
168 require_once($CFG->dirroot
. '/mod/quiz/locallib.php');
169 $this->choices
= quiz_get_grading_options();
177 * Admin settings class for the quiz browser security option.
179 * Just so we can lazy-load the choices.
181 * @copyright 2011 The Open University
182 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
184 class mod_quiz_admin_setting_browsersecurity
extends admin_setting_configselect_with_advanced
{
185 public function load_choices() {
188 if (is_array($this->choices
)) {
192 require_once($CFG->dirroot
. '/mod/quiz/locallib.php');
193 $this->choices
= quiz_access_manager
::get_browser_security_choices();
201 * Admin settings class for the quiz overdue attempt handling method.
203 * Just so we can lazy-load the choices.
205 * @copyright 2011 The Open University
206 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
208 class mod_quiz_admin_setting_overduehandling
extends admin_setting_configselect_with_advanced
{
209 public function load_choices() {
212 if (is_array($this->choices
)) {
216 require_once($CFG->dirroot
. '/mod/quiz/locallib.php');
217 $this->choices
= quiz_get_overdue_handling_options();