MDL-32322 quiz reports: extract a mod_quiz_attempt_report_options class.

More clean-ups are possible in the reports after this, but I am committing now, having got the code back to a working state.
This commit is contained in:
Tim Hunt 2012-04-05 13:58:54 +01:00
parent 303aa3b8d0
commit dcd65f1b4f
9 changed files with 434 additions and 146 deletions

View File

@ -98,31 +98,6 @@ abstract class quiz_attempt_report extends quiz_default_report {
array('id' => $this->context->instanceid, 'mode' => $this->mode));
}
/**
* Should the grades be displayed in this report. That depends on the quiz
* display options, and whether the quiz is graded.
* @param object $quiz the quiz settings.
* @return bool
*/
protected function should_show_grades($quiz) {
if (!is_null($this->showgrades)) {
return $this->showgrades;
}
if ($quiz->timeclose && time() > $quiz->timeclose) {
$when = mod_quiz_display_options::AFTER_CLOSE;
} else {
$when = mod_quiz_display_options::LATER_WHILE_OPEN;
}
$reviewoptions = mod_quiz_display_options::make_from_quiz($quiz, $when);
$this->showgrades = quiz_has_grades($quiz) &&
($reviewoptions->marks >= question_display_options::MARK_AND_MAX ||
has_capability('moodle/grade:viewhidden', $this->context));
return $this->showgrades;
}
/**
* Get information about which students to show in the report.
* @param object $cm the coures module.
@ -165,33 +140,6 @@ abstract class quiz_attempt_report extends quiz_default_report {
return array($currentgroup, $students, $groupstudents, $groupstudents);
}
/**
* Alters $attemptsmode and $pagesize if the current values are inappropriate.
* @param int $attemptsmode what sort of attempts to display (may be updated)
* @param int $pagesize number of records to display per page (may be updated)
* @param object $course the course settings.
* @param int $currentgroup the currently selected group. 0 for none.
*/
protected function validate_common_options(&$attemptsmode, &$pagesize, $course, $currentgroup) {
if ($currentgroup) {
// Default for when a group is selected.
if ($attemptsmode === null || $attemptsmode == self::ALL_ATTEMPTS) {
$attemptsmode = self::STUDENTS_WITH;
}
} else if (!$currentgroup && $course->id == SITEID) {
// Force report on front page to show all, unless a group is selected.
$attemptsmode = self::ALL_ATTEMPTS;
} else if ($attemptsmode === null) {
$attemptsmode = self::ALL_ATTEMPTS;
}
if ($pagesize < 1) {
$pagesize = self::DEFAULT_PAGE_SIZE;
}
}
/**
* Add all the user-related columns to the $columns and $headers arrays.
* @param table_sql $table the table being constructed.
@ -275,7 +223,7 @@ abstract class quiz_attempt_report extends quiz_default_report {
* @param bool $includefeedback whether to include the feedbacktext columns
*/
protected function add_grade_columns($quiz, &$columns, &$headers, $includefeedback = true) {
if ($this->should_show_grades($quiz)) {
if (quiz_report_should_show_grades($quiz)) {
$columns[] = 'sumgrades';
$headers[] = get_string('grade', 'quiz') . '/' .
quiz_format_grade($quiz, $quiz->grade);

View File

@ -0,0 +1,190 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Base class for the options that control what is visible in an {@link quiz_attempt_report}.
*
* @package mod_quiz
* @copyright 2012 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir . '/formslib.php');
/**
* Base class for the options that control what is visible in an {@link quiz_attempt_report}.
*
* @copyright 2012 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_quiz_attempt_report_options {
/** @var object the settings for the quiz being reported on. */
public $quiz;
/** @var object the course module objects for the quiz being reported on. */
public $cm;
/** @var object the course settings for the course the quiz is in. */
public $course;
/**
* @var string quiz_attempt_report:: constants.
*/
public $attempts = quiz_attempt_report::STUDENTS_WITH;
/**
* @var int the currently selected group. 0 if no group is selected.
*/
public $group = 0;
/**
* @var bool wether to show all finished attmepts, or just the one that gave
* the final grade for the user.
*/
public $onlygraded = false;
/**
* @var int Number of attempts to show per page.
*/
public $pagesize = quiz_attempt_report::DEFAULT_PAGE_SIZE;
/**
* @var string whether the data should be downloaded in some format, or '' to display it.
*/
public $download = '';
/**
* Constructor.
* @param object $quiz the settings for the quiz being reported on.
* @param object $cm the course module objects for the quiz being reported on.
*/
public function __construct($quiz, $cm, $course) {
$this->quiz = $quiz;
$this->cm = $cm;
$this->course = $course;
}
/**
* Process the data we get when the settings form is submitted. This includes
* updating the fields of this class, and updating the user preferences
* where appropriate.
* @param object $fromform The data from $mform->get_data() from the settings form.
*/
public function process_settings_from_form($fromform) {
$this->setup_from_form_data($fromform);
$this->resolve_dependencies();
$this->update_user_preferences();
}
/**
* Set up this preferences object using optional_param (using user_preferences
* to set anything not specified by the params.
*/
public function process_settings_from_params() {
$this->setup_from_user_preferences();
$this->setup_from_params();
$this->resolve_dependencies();
}
/**
* Get the current value of the settings to pass to the settings form.
*/
public function get_initial_form_data() {
$toform = new stdClass();
$toform->attemptsmode = $this->attempts;
$toform->qmfilter = $this->onlygraded;
$toform->pagesize = $this->pagesize;
return $toform;
}
/**
* Set the fields of this object from the form data.
* @param object $fromform The data from $mform->get_data() from the settings form.
*/
public function setup_from_form_data($fromform) {
$this->attempts = $fromform->attemptsmode;
$this->group = groups_get_activity_group($this->cm, true);
$this->onlygraded = !empty($fromform->qmfilter);
$this->pagesize = $fromform->pagesize;
}
/**
* Set the fields of this object from the user's preferences.
*/
public function setup_from_params() {
$this->attempts = optional_param('attemptsmode', $this->attempts, PARAM_ALPHAEXT);
$this->group = groups_get_activity_group($this->cm, true);
$this->onlygraded = optional_param('qmfilter', $this->onlygraded, PARAM_BOOL);
$this->pagesize = optional_param('pagesize', $this->pagesize, PARAM_INT);
$this->download = optional_param('download', $this->download, PARAM_ALPHA);
}
/**
* Set the fields of this object from the user's preferences.
* (For those settings that are backed by user-preferences).
*/
public function setup_from_user_preferences() {
$this->pagesize = get_user_preferences('quiz_report_pagesize', $this->pagesize);
}
/**
* Update the user preferences so they match the settings in this object.
* (For those settings that are backed by user-preferences).
*/
public function update_user_preferences() {
set_user_preference('quiz_report_pagesize', $this->pagesize);
}
/**
* Check the settings, and remove any 'impossible' combinations.
*/
public function resolve_dependencies() {
if ($this->group) {
// Default for when a group is selected.
if ($this->attempts === null || $this->attempts == quiz_attempt_report::ALL_ATTEMPTS) {
$this->attempts = quiz_attempt_report::STUDENTS_WITH;
}
} else if (!$this->group && $this->course->id == SITEID) {
// Force report on front page to show all, unless a group is selected.
$this->attempts = quiz_attempt_report::ALL_ATTEMPTS;
} else if ($this->attempts === null) {
$this->attempts = quiz_attempt_report::ALL_ATTEMPTS;
}
if ($this->pagesize < 1) {
$this->pagesize = quiz_attempt_report::DEFAULT_PAGE_SIZE;
}
if (!quiz_report_qm_filter_select($this->quiz)) {
// A grading mode like 'average' has been selected, so we cannot do
// the show the attempt that gave the final grade thing.
$this->onlygraded = false;
}
if ($this->attempts == quiz_attempt_report::STUDENTS_WITH_NO) {
$this->onlygraded = false;
}
}
}

View File

@ -0,0 +1,86 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Class to store the options for a {@link quiz_overview_report}.
*
* @package quiz_overview
* @copyright 2012 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/mod/quiz/report/attemptsreport_options.php');
/**
* Class to store the options for a {@link quiz_overview_report}.
*
* @copyright 2012 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class quiz_overview_options extends mod_quiz_attempt_report_options {
/** @var bool whether to show only attempt that need regrading. */
public $onlyregraded = false;
/** @var bool whether to show marks for each question (slot). */
public $slotmarks = true;
public function get_initial_form_data() {
$toform = parent::get_initial_form_data();
$toform->regradefilter = $this->onlyregraded;
$toform->detailedmarks = $this->slotmarks;
return $toform;
}
public function setup_from_form_data($fromform) {
parent::setup_from_form_data($fromform);
$this->onlyregraded = !empty($fromform->regradefilter);
$this->slotmarks = $fromform->detailedmarks;
}
public function setup_from_params() {
parent::setup_from_params();
$this->onlyregraded = optional_param('regradefilter', $this->onlyregraded, PARAM_BOOL);
$this->slotmarks = optional_param('detailedmarks', $this->slotmarks, PARAM_BOOL);
}
public function setup_from_user_preferences() {
parent::setup_from_user_preferences();
$this->slotmarks = get_user_preferences('quiz_report_overview_detailedmarks', $this->slotmarks);
}
public function update_user_preferences() {
parent::update_user_preferences();
set_user_preference('quiz_overview_slotmarks', $this->slotmarks);
}
public function resolve_dependencies() {
parent::resolve_dependencies();
if (!quiz_report_should_show_grades($this->quiz)) {
$this->slotmarks = false;
}
}
}

View File

@ -26,7 +26,8 @@
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/mod/quiz/report/attemptsreport.php');
require_once($CFG->dirroot . '/mod/quiz/report/overview/overviewsettings_form.php');
require_once($CFG->dirroot . '/mod/quiz/report/overview/overview_options.php');
require_once($CFG->dirroot . '/mod/quiz/report/overview/overview_form.php');
require_once($CFG->dirroot . '/mod/quiz/report/overview/overview_table.php');
@ -43,58 +44,29 @@ class quiz_overview_report extends quiz_attempt_report {
list($currentgroup, $students, $groupstudents, $allowed) =
$this->init('overview', 'quiz_overview_settings_form', $quiz, $cm, $course);
$options = new quiz_overview_options($quiz, $cm, $course);
if ($fromform = $this->form->get_data()) {
$regradeall = false;
$regradealldry = false;
$regradealldrydo = false;
$attemptsmode = $fromform->attemptsmode;
if ($this->qmsubselect) {
$qmfilter = $fromform->qmfilter;
} else {
$qmfilter = 0;
}
$regradefilter = !empty($fromform->regradefilter);
set_user_preference('quiz_report_overview_detailedmarks', $fromform->detailedmarks);
set_user_preference('quiz_report_pagesize', $fromform->pagesize);
$detailedmarks = $fromform->detailedmarks;
$pagesize = $fromform->pagesize;
$options->process_settings_from_form($fromform);
} else {
$regradeall = optional_param('regradeall', 0, PARAM_BOOL);
$regradealldry = optional_param('regradealldry', 0, PARAM_BOOL);
$regradealldrydo = optional_param('regradealldrydo', 0, PARAM_BOOL);
$attemptsmode = optional_param('attemptsmode', null, PARAM_INT);
if ($this->qmsubselect) {
$qmfilter = optional_param('qmfilter', 0, PARAM_INT);
} else {
$qmfilter = 0;
}
$regradefilter = optional_param('regradefilter', 0, PARAM_INT);
$detailedmarks = get_user_preferences('quiz_report_overview_detailedmarks', 1);
$pagesize = get_user_preferences('quiz_report_pagesize', 0);
$options->process_settings_from_params();
}
$this->validate_common_options($attemptsmode, $pagesize, $course, $currentgroup);
$displayoptions = array();
$displayoptions['attemptsmode'] = $attemptsmode;
$displayoptions['qmfilter'] = $qmfilter;
$displayoptions['regradefilter'] = $regradefilter;
$displayoptions['attemptsmode'] = $options->attempts;
$displayoptions['qmfilter'] = $options->onlygraded;
$displayoptions['regradefilter'] = $options->onlyregraded;
$this->form->set_data($displayoptions +
array('detailedmarks' => $detailedmarks, 'pagesize' => $pagesize));
if (!$this->should_show_grades($quiz)) {
$detailedmarks = 0;
}
$this->form->set_data($options->get_initial_form_data());
// We only want to show the checkbox to delete attempts
// if the user has permissions and if the report mode is showing attempts.
$includecheckboxes = has_any_capability(
array('mod/quiz:regrade', 'mod/quiz:deleteattempts'), $this->context)
&& ($attemptsmode != self::STUDENTS_WITH_NO);
&& ($options->attempts != self::STUDENTS_WITH_NO);
if ($attemptsmode == self::ALL_ATTEMPTS) {
if ($options->attempts == self::ALL_ATTEMPTS) {
// This option is only available to users who can access all groups in
// groups mode, so setting allowed to empty (which means all quiz attempts
// are accessible, is not a security porblem.
@ -108,11 +80,11 @@ class quiz_overview_report extends quiz_attempt_report {
$courseshortname = format_string($course->shortname, true,
array('context' => context_course::instance($course->id)));
$table = new quiz_overview_table($quiz, $this->context, $this->qmsubselect,
$qmfilter, $attemptsmode, $groupstudents, $students, $detailedmarks,
$options->onlygraded, $options->attempts, $groupstudents, $students, $options->slotmarks,
$questions, $includecheckboxes, $this->get_base_url(), $displayoptions);
$filename = quiz_report_download_filename(get_string('overviewfilename', 'quiz_overview'),
$courseshortname, $quiz->name);
$table->is_downloading(optional_param('download', '', PARAM_ALPHA), $filename,
$table->is_downloading($options->download, $filename,
$courseshortname . ' ' . format_string($quiz->name, true));
if ($table->is_downloading()) {
raise_memory_limit(MEMORY_EXTRA);
@ -136,6 +108,9 @@ class quiz_overview_report extends quiz_attempt_report {
}
}
$regradeall = optional_param('regradeall', 0, PARAM_BOOL);
$regradealldry = optional_param('regradealldry', 0, PARAM_BOOL);
$regradealldrydo = optional_param('regradealldrydo', 0, PARAM_BOOL);
if ($regradeall && confirm_sesskey()) {
require_capability('mod/quiz:regrade', $this->context);
$this->regrade_attempts($quiz, false, $groupstudents);
@ -188,7 +163,7 @@ class quiz_overview_report extends quiz_attempt_report {
}
$hasstudents = $students && (!$currentgroup || $groupstudents);
if ($hasquestions && ($hasstudents || $attemptsmode == self::ALL_ATTEMPTS)) {
if ($hasquestions && ($hasstudents || $options->attempts == self::ALL_ATTEMPTS)) {
// Construct the SQL.
$fields = $DB->sql_concat('u.id', "'#'", 'COALESCE(quiza.attempt, 0)') .
' AS uniqueid, ';
@ -210,7 +185,7 @@ class quiz_overview_report extends quiz_attempt_report {
FROM {quiz_overview_regrades} qqr
WHERE qqr.questionusageid = quiza.uniqueid
), -1) AS regraded";
if ($regradefilter) {
if ($options->onlyregraded) {
$where .= " AND COALESCE((
SELECT MAX(qqr.regraded)
FROM {quiz_overview_regrades} qqr
@ -262,7 +237,7 @@ class quiz_overview_report extends quiz_attempt_report {
}
// Print information on the grading method.
if ($strattempthighlight = quiz_report_highlighting_grading_method(
$quiz, $this->qmsubselect, $qmfilter)) {
$quiz, $this->qmsubselect, $options->onlygraded)) {
echo '<div class="quizattemptcounts">' . $strattempthighlight . '</div>';
}
}
@ -280,7 +255,7 @@ class quiz_overview_report extends quiz_attempt_report {
$this->add_time_columns($columns, $headers);
if ($detailedmarks) {
if ($options->slotmarks) {
foreach ($questions as $slot => $question) {
// Ignore questions of zero length.
$columns[] = 'qsgrade' . $slot;
@ -307,10 +282,10 @@ class quiz_overview_report extends quiz_attempt_report {
$table, $columns, $headers, $this->get_base_url(), $displayoptions, false);
$table->set_attribute('class', 'generaltable generalbox grades');
$table->out($pagesize, true);
$table->out($options->pagesize, true);
}
if (!$table->is_downloading() && $this->should_show_grades($quiz)) {
if (!$table->is_downloading() && quiz_report_should_show_grades($quiz)) {
if ($currentgroup && $groupstudents) {
list($usql, $params) = $DB->get_in_or_equal($groupstudents);
$params[] = $quiz->id;

View File

@ -387,3 +387,22 @@ function quiz_no_questions_message($quiz, $cm, $context) {
return $output;
}
/**
* Should the grades be displayed in this report. That depends on the quiz
* display options, and whether the quiz is graded.
* @param object $quiz the quiz settings.
* @return bool
*/
function quiz_report_should_show_grades($quiz) {
if ($quiz->timeclose && time() > $quiz->timeclose) {
$when = mod_quiz_display_options::AFTER_CLOSE;
} else {
$when = mod_quiz_display_options::LATER_WHILE_OPEN;
}
$reviewoptions = mod_quiz_display_options::make_from_quiz($quiz, $when);
return quiz_has_grades($quiz) &&
($reviewoptions->marks >= question_display_options::MARK_AND_MAX ||
has_capability('moodle/grade:viewhidden', $this->context));
}

View File

@ -26,7 +26,8 @@
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/mod/quiz/report/attemptsreport.php');
require_once($CFG->dirroot . '/mod/quiz/report/responses/responsessettings_form.php');
require_once($CFG->dirroot . '/mod/quiz/report/responses/responses_options.php');
require_once($CFG->dirroot . '/mod/quiz/report/responses/responses_form.php');
require_once($CFG->dirroot . '/mod/quiz/report/responses/responses_table.php');
@ -51,58 +52,30 @@ class quiz_responses_report extends quiz_attempt_report {
list($currentgroup, $students, $groupstudents, $allowed) =
$this->init('responses', 'quiz_responses_settings_form', $quiz, $cm, $course);
$options = new quiz_responses_options($quiz, $cm, $course);
if ($fromform = $this->form->get_data()) {
$attemptsmode = $fromform->attemptsmode;
if ($this->qmsubselect) {
$qmfilter = $fromform->qmfilter;
} else {
$qmfilter = 0;
}
set_user_preference('quiz_report_responses_qtext', $fromform->qtext);
set_user_preference('quiz_report_responses_resp', $fromform->resp);
set_user_preference('quiz_report_responses_right', $fromform->right);
set_user_preference('quiz_report_pagesize', $fromform->pagesize);
$includeqtext = $fromform->qtext;
$includeresp = $fromform->resp;
$includeright = $fromform->right;
$pagesize = $fromform->pagesize;
$options->process_settings_from_form($fromform);
} else {
$attemptsmode = optional_param('attemptsmode', null, PARAM_INT);
if ($this->qmsubselect) {
$qmfilter = optional_param('qmfilter', 0, PARAM_INT);
} else {
$qmfilter = 0;
}
$includeqtext = get_user_preferences('quiz_report_responses_qtext', 0);
$includeresp = get_user_preferences('quiz_report_responses_resp', 1);
$includeright = get_user_preferences('quiz_report_responses_right', 0);
$pagesize = get_user_preferences('quiz_report_pagesize', 0);
$options->process_settings_from_params();
}
$this->validate_common_options($attemptsmode, $pagesize, $course, $currentgroup);
$displayoptions = array();
$displayoptions['attemptsmode'] = $attemptsmode;
$displayoptions['qmfilter'] = $qmfilter;
$displayoptions['qtext'] = $includeqtext;
$displayoptions['resp'] = $includeresp;
$displayoptions['right'] = $includeright;
$displayoptions['attemptsmode'] = $options->attempts;
$displayoptions['qmfilter'] = $options->onlygraded;
$displayoptions['qtext'] = $options->showqtext;
$displayoptions['resp'] = $options->showresponses;
$displayoptions['right'] = $options->showright;
$this->form->set_data($displayoptions +
array('pagesize' => $pagesize));
if (!$includeqtext && !$includeresp && !$includeright) {
$includeresp = 1;
set_user_preference('quiz_report_responses_resp', 1);
}
$this->form->set_data($options->get_initial_form_data());
// We only want to show the checkbox to delete attempts
// if the user has permissions and if the report mode is showing attempts.
$includecheckboxes = has_capability('mod/quiz:deleteattempts', $this->context)
&& ($attemptsmode != self::STUDENTS_WITH_NO);
&& ($options->attempts != self::STUDENTS_WITH_NO);
if ($attemptsmode == self::ALL_ATTEMPTS) {
if ($options->attempts == self::ALL_ATTEMPTS) {
// This option is only available to users who can access all groups in
// groups mode, so setting allowed to empty (which means all quiz attempts
// are accessible, is not a security porblem.
@ -116,7 +89,7 @@ class quiz_responses_report extends quiz_attempt_report {
$courseshortname = format_string($course->shortname, true,
array('context' => context_course::instance($course->id)));
$table = new quiz_responses_table($quiz, $this->context, $this->qmsubselect,
$qmfilter, $attemptsmode, $groupstudents, $students,
$options->onlygraded, $options->attempts, $groupstudents, $students,
$questions, $includecheckboxes, $this->get_base_url(), $displayoptions);
$filename = quiz_report_download_filename(get_string('responsesfilename', 'quiz_responses'),
$courseshortname, $quiz->name);
@ -178,7 +151,7 @@ class quiz_responses_report extends quiz_attempt_report {
if (!$table->is_downloading()) {
// Do not print notices when downloading.
if ($strattempthighlight = quiz_report_highlighting_grading_method(
$quiz, $this->qmsubselect, $qmfilter)) {
$quiz, $this->qmsubselect, $options->onlygraded)) {
echo '<div class="quizattemptcounts">' . $strattempthighlight . '</div>';
}
}
@ -207,15 +180,15 @@ class quiz_responses_report extends quiz_attempt_report {
$this->add_grade_columns($quiz, $columns, $headers);
foreach ($questions as $id => $question) {
if ($displayoptions['qtext']) {
if ($options->showqtext) {
$columns[] = 'question' . $id;
$headers[] = get_string('questionx', 'question', $question->number);
}
if ($displayoptions['resp']) {
if ($options->showresponses) {
$columns[] = 'response' . $id;
$headers[] = get_string('responsex', 'quiz_responses', $question->number);
}
if ($displayoptions['right']) {
if ($options->showright) {
$columns[] = 'right' . $id;
$headers[] = get_string('rightanswerx', 'quiz_responses', $question->number);
}
@ -237,7 +210,7 @@ class quiz_responses_report extends quiz_attempt_report {
$table->collapsible(true);
$table->out($pagesize, true);
$table->out($options->pagesize, true);
}
return true;
}

View File

@ -0,0 +1,97 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Class to store the options for a {@link quiz_responses_report}.
*
* @package quiz_responses
* @copyright 2012 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/mod/quiz/report/attemptsreport_options.php');
/**
* Class to store the options for a {@link quiz_responses_report}.
*
* @copyright 2012 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class quiz_responses_options extends mod_quiz_attempt_report_options {
/** @var bool whether to show the question text columns. */
public $showqtext = false;
/** @var bool whether to show the students' reponse columns. */
public $showresponses = true;
/** @var bool whether to show the correct response columns. */
public $showright = false;
public function get_initial_form_data() {
$toform = parent::get_initial_form_data();
$toform->qtext = $this->showqtext;
$toform->resp = $this->showresponses;
$toform->right = $this->showright;
return $toform;
}
public function setup_from_form_data($fromform) {
parent::setup_from_form_data($fromform);
$this->showqtext = $fromform->qtext;
$this->showresponses = $fromform->resp;
$this->showright = $fromform->right;
}
public function setup_from_params() {
parent::setup_from_params();
$this->showqtext = optional_param('qtext', $this->showqtext, PARAM_BOOL);
$this->showresponses = optional_param('resp', $this->showresponses, PARAM_BOOL);
$this->showright = optional_param('right', $this->showright, PARAM_BOOL);
}
public function setup_from_user_preferences() {
parent::setup_from_user_preferences();
$this->showqtext = get_user_preferences('quiz_report_responses_qtext', $this->showqtext);
$this->showresponses = get_user_preferences('quiz_report_responses_resp', $this->showresponses);
$this->showright = get_user_preferences('quiz_report_responses_right', $this->showright);
}
public function update_user_preferences() {
parent::update_user_preferences();
set_user_preference('quiz_report_responses_qtext', $this->showqtext);
set_user_preference('quiz_report_responses_resp', $this->showresponses);
set_user_preference('quiz_report_responses_right', $this->showright);
}
public function resolve_dependencies() {
parent::resolve_dependencies();
if (!$this->showqtext && !$this->showresponses && !$this->showright) {
// We have to show at least something.
$this->showresponses = true;
}
}
}