mirror of
https://github.com/moodle/moodle.git
synced 2025-02-01 05:18:06 +01:00
MDL-32322 quiz reports: defines -> class constants.
This commit is contained in:
parent
2639a68ad5
commit
5bf8a1695d
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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',
|
||||
|
@ -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');
|
||||
|
@ -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, ';
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user