From 5bf8a1695dcff5497a8c0caaab247ab120ec77d4 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Wed, 4 Apr 2012 18:38:40 +0100 Subject: [PATCH] MDL-32322 quiz reports: defines -> class constants. --- mod/quiz/report/attemptsreport.php | 22 +++++++++++++++++----- mod/quiz/report/attemptsreport_form.php | 8 ++++---- mod/quiz/report/attemptsreport_table.php | 8 ++++---- mod/quiz/report/overview/report.php | 6 +++--- mod/quiz/report/reportlib.php | 8 -------- mod/quiz/report/responses/report.php | 6 +++--- 6 files changed, 31 insertions(+), 27 deletions(-) diff --git a/mod/quiz/report/attemptsreport.php b/mod/quiz/report/attemptsreport.php index eeaf1a05538..c0012d1862a 100644 --- a/mod/quiz/report/attemptsreport.php +++ b/mod/quiz/report/attemptsreport.php @@ -36,6 +36,18 @@ require_once($CFG->libdir.'/tablelib.php'); * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ abstract class quiz_attempt_report extends quiz_default_report { + /** @var int default page size for reports. */ + const DEFAULT_PAGE_SIZE = 30; + + /** @var int include all attempts. */ + const ALL_ATTEMPTS = 0; + /** @var int include just enroled users who have not attempted the quiz. */ + const STUDENTS_WITH_NO = 1; + /** @var int include just enroled users who have attempted the quiz. */ + const STUDENTS_WITH = 2; + /** @var int include all enroled users. */ + const ALL_STUDENTS = 3; + /** @var object the quiz context. */ protected $context; @@ -119,20 +131,20 @@ abstract class quiz_attempt_report extends quiz_default_report { protected function validate_common_options(&$attemptsmode, &$pagesize, $course, $currentgroup) { if ($currentgroup) { // Default for when a group is selected. - if ($attemptsmode === null || $attemptsmode == QUIZ_REPORT_ATTEMPTS_ALL) { - $attemptsmode = QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH; + 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 = QUIZ_REPORT_ATTEMPTS_ALL; + $attemptsmode = self::ALL_ATTEMPTS; } else if ($attemptsmode === null) { - $attemptsmode = QUIZ_REPORT_ATTEMPTS_ALL; + $attemptsmode = self::ALL_ATTEMPTS; } if ($pagesize < 1) { - $pagesize = QUIZ_REPORT_DEFAULT_PAGE_SIZE; + $pagesize = self::DEFAULT_PAGE_SIZE; } } diff --git a/mod/quiz/report/attemptsreport_form.php b/mod/quiz/report/attemptsreport_form.php index 8814e20af0e..11a6c8f369c 100644 --- a/mod/quiz/report/attemptsreport_form.php +++ b/mod/quiz/report/attemptsreport_form.php @@ -56,15 +56,15 @@ abstract class mod_quiz_attempt_report_form extends moodleform { } $options = array(); if (!$this->_customdata['currentgroup']) { - $options[QUIZ_REPORT_ATTEMPTS_ALL] = get_string('optallattempts', 'quiz_overview'); + $options[quiz_attempt_report::ALL_ATTEMPTS] = get_string('optallattempts', 'quiz_overview'); } if ($this->_customdata['currentgroup'] || !is_inside_frontpage($this->_customdata['context'])) { - $options[QUIZ_REPORT_ATTEMPTS_ALL_STUDENTS] = + $options[quiz_attempt_report::ALL_STUDENTS] = get_string('optallstudents', 'quiz_overview', $studentsstring); - $options[QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH] = + $options[quiz_attempt_report::STUDENTS_WITH] = get_string('optattemptsonly', 'quiz_overview', $studentsstring); - $options[QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH_NO] = + $options[quiz_attempt_report::STUDENTS_WITH_NO] = get_string('optnoattemptsonly', 'quiz_overview', $studentsstring); } $mform->addElement('select', 'attemptsmode', diff --git a/mod/quiz/report/attemptsreport_table.php b/mod/quiz/report/attemptsreport_table.php index 485c60c17e6..86fd8a887ad 100755 --- a/mod/quiz/report/attemptsreport_table.php +++ b/mod/quiz/report/attemptsreport_table.php @@ -318,25 +318,25 @@ abstract class quiz_attempt_report_table extends table_sql { $from .= " AND $this->qmsubselect"; } switch ($this->attemptsmode) { - case QUIZ_REPORT_ATTEMPTS_ALL: + case quiz_attempt_report::ALL_ATTEMPTS: // Show all attempts, including students who are no longer in the course. $where = 'quiza.id IS NOT NULL AND quiza.preview = 0'; break; - case QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH: + case quiz_attempt_report::STUDENTS_WITH: // Show only students with attempts. list($usql, $uparams) = $DB->get_in_or_equal( $reportstudents, SQL_PARAMS_NAMED, 'u'); $params += $uparams; $where = "u.id $usql AND quiza.preview = 0 AND quiza.id IS NOT NULL"; break; - case QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH_NO: + case quiz_attempt_report::STUDENTS_WITH_NO: // Show only students without attempts. list($usql, $uparams) = $DB->get_in_or_equal( $reportstudents, SQL_PARAMS_NAMED, 'u'); $params += $uparams; $where = "u.id $usql AND quiza.id IS NULL"; break; - case QUIZ_REPORT_ATTEMPTS_ALL_STUDENTS: + case quiz_attempt_report::ALL_STUDENTS: // Show all students with or without attempts. list($usql, $uparams) = $DB->get_in_or_equal( $reportstudents, SQL_PARAMS_NAMED, 'u'); diff --git a/mod/quiz/report/overview/report.php b/mod/quiz/report/overview/report.php index bdb49ed2ec1..0565aa8ca08 100644 --- a/mod/quiz/report/overview/report.php +++ b/mod/quiz/report/overview/report.php @@ -107,9 +107,9 @@ class quiz_overview_report extends quiz_attempt_report { // 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 != QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH_NO); + && ($attemptsmode != self::STUDENTS_WITH_NO); - if ($attemptsmode == QUIZ_REPORT_ATTEMPTS_ALL) { + if ($attemptsmode == 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. @@ -203,7 +203,7 @@ class quiz_overview_report extends quiz_attempt_report { } $hasstudents = $students && (!$currentgroup || $groupstudents); - if ($hasquestions && ($hasstudents || $attemptsmode == QUIZ_REPORT_ATTEMPTS_ALL)) { + if ($hasquestions && ($hasstudents || $attemptsmode == self::ALL_ATTEMPTS)) { // Construct the SQL. $fields = $DB->sql_concat('u.id', "'#'", 'COALESCE(quiza.attempt, 0)') . ' AS uniqueid, '; diff --git a/mod/quiz/report/reportlib.php b/mod/quiz/report/reportlib.php index 5f2832f3d0f..164cbb29ac3 100644 --- a/mod/quiz/report/reportlib.php +++ b/mod/quiz/report/reportlib.php @@ -28,14 +28,6 @@ defined('MOODLE_INTERNAL') || die(); require_once($CFG->dirroot . '/mod/quiz/lib.php'); require_once($CFG->libdir . '/filelib.php'); -define('QUIZ_REPORT_DEFAULT_PAGE_SIZE', 30); -define('QUIZ_REPORT_DEFAULT_GRADING_PAGE_SIZE', 10); - -define('QUIZ_REPORT_ATTEMPTS_ALL', 0); -define('QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH_NO', 1); -define('QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH', 2); -define('QUIZ_REPORT_ATTEMPTS_ALL_STUDENTS', 3); - /** * Takes an array of objects and constructs a multidimensional array keyed by * the keys it finds on the object. diff --git a/mod/quiz/report/responses/report.php b/mod/quiz/report/responses/report.php index 09fa0dc0124..c3931eb035f 100644 --- a/mod/quiz/report/responses/report.php +++ b/mod/quiz/report/responses/report.php @@ -115,9 +115,9 @@ class quiz_responses_report extends quiz_attempt_report { // 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 != QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH_NO); + && ($attemptsmode != self::STUDENTS_WITH_NO); - if ($attemptsmode == QUIZ_REPORT_ATTEMPTS_ALL) { + if ($attemptsmode == 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. @@ -188,7 +188,7 @@ class quiz_responses_report extends quiz_attempt_report { } $hasstudents = $students && (!$currentgroup || $groupstudents); - if ($hasquestions && ($hasstudents || $attemptsmode == QUIZ_REPORT_ATTEMPTS_ALL)) { + if ($hasquestions && ($hasstudents || $attemptsmode == self::ALL_ATTEMPTS)) { // Print information on the grading method and whether we are displaying. if (!$table->is_downloading()) { // Do not print notices when downloading.