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
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
abstract class quiz_attempt_report extends quiz_default_report {
|
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. */
|
/** @var object the quiz context. */
|
||||||
protected $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) {
|
protected function validate_common_options(&$attemptsmode, &$pagesize, $course, $currentgroup) {
|
||||||
if ($currentgroup) {
|
if ($currentgroup) {
|
||||||
// Default for when a group is selected.
|
// Default for when a group is selected.
|
||||||
if ($attemptsmode === null || $attemptsmode == QUIZ_REPORT_ATTEMPTS_ALL) {
|
if ($attemptsmode === null || $attemptsmode == self::ALL_ATTEMPTS) {
|
||||||
$attemptsmode = QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH;
|
$attemptsmode = self::STUDENTS_WITH;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (!$currentgroup && $course->id == SITEID) {
|
} else if (!$currentgroup && $course->id == SITEID) {
|
||||||
// Force report on front page to show all, unless a group is selected.
|
// 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) {
|
} else if ($attemptsmode === null) {
|
||||||
$attemptsmode = QUIZ_REPORT_ATTEMPTS_ALL;
|
$attemptsmode = self::ALL_ATTEMPTS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($pagesize < 1) {
|
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();
|
$options = array();
|
||||||
if (!$this->_customdata['currentgroup']) {
|
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'] ||
|
if ($this->_customdata['currentgroup'] ||
|
||||||
!is_inside_frontpage($this->_customdata['context'])) {
|
!is_inside_frontpage($this->_customdata['context'])) {
|
||||||
$options[QUIZ_REPORT_ATTEMPTS_ALL_STUDENTS] =
|
$options[quiz_attempt_report::ALL_STUDENTS] =
|
||||||
get_string('optallstudents', 'quiz_overview', $studentsstring);
|
get_string('optallstudents', 'quiz_overview', $studentsstring);
|
||||||
$options[QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH] =
|
$options[quiz_attempt_report::STUDENTS_WITH] =
|
||||||
get_string('optattemptsonly', 'quiz_overview', $studentsstring);
|
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);
|
get_string('optnoattemptsonly', 'quiz_overview', $studentsstring);
|
||||||
}
|
}
|
||||||
$mform->addElement('select', 'attemptsmode',
|
$mform->addElement('select', 'attemptsmode',
|
||||||
|
@ -318,25 +318,25 @@ abstract class quiz_attempt_report_table extends table_sql {
|
|||||||
$from .= " AND $this->qmsubselect";
|
$from .= " AND $this->qmsubselect";
|
||||||
}
|
}
|
||||||
switch ($this->attemptsmode) {
|
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.
|
// Show all attempts, including students who are no longer in the course.
|
||||||
$where = 'quiza.id IS NOT NULL AND quiza.preview = 0';
|
$where = 'quiza.id IS NOT NULL AND quiza.preview = 0';
|
||||||
break;
|
break;
|
||||||
case QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH:
|
case quiz_attempt_report::STUDENTS_WITH:
|
||||||
// Show only students with attempts.
|
// Show only students with attempts.
|
||||||
list($usql, $uparams) = $DB->get_in_or_equal(
|
list($usql, $uparams) = $DB->get_in_or_equal(
|
||||||
$reportstudents, SQL_PARAMS_NAMED, 'u');
|
$reportstudents, SQL_PARAMS_NAMED, 'u');
|
||||||
$params += $uparams;
|
$params += $uparams;
|
||||||
$where = "u.id $usql AND quiza.preview = 0 AND quiza.id IS NOT NULL";
|
$where = "u.id $usql AND quiza.preview = 0 AND quiza.id IS NOT NULL";
|
||||||
break;
|
break;
|
||||||
case QUIZ_REPORT_ATTEMPTS_STUDENTS_WITH_NO:
|
case quiz_attempt_report::STUDENTS_WITH_NO:
|
||||||
// Show only students without attempts.
|
// Show only students without attempts.
|
||||||
list($usql, $uparams) = $DB->get_in_or_equal(
|
list($usql, $uparams) = $DB->get_in_or_equal(
|
||||||
$reportstudents, SQL_PARAMS_NAMED, 'u');
|
$reportstudents, SQL_PARAMS_NAMED, 'u');
|
||||||
$params += $uparams;
|
$params += $uparams;
|
||||||
$where = "u.id $usql AND quiza.id IS NULL";
|
$where = "u.id $usql AND quiza.id IS NULL";
|
||||||
break;
|
break;
|
||||||
case QUIZ_REPORT_ATTEMPTS_ALL_STUDENTS:
|
case quiz_attempt_report::ALL_STUDENTS:
|
||||||
// Show all students with or without attempts.
|
// Show all students with or without attempts.
|
||||||
list($usql, $uparams) = $DB->get_in_or_equal(
|
list($usql, $uparams) = $DB->get_in_or_equal(
|
||||||
$reportstudents, SQL_PARAMS_NAMED, 'u');
|
$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.
|
// if the user has permissions and if the report mode is showing attempts.
|
||||||
$includecheckboxes = has_any_capability(
|
$includecheckboxes = has_any_capability(
|
||||||
array('mod/quiz:regrade', 'mod/quiz:deleteattempts'), $this->context)
|
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
|
// 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
|
// groups mode, so setting allowed to empty (which means all quiz attempts
|
||||||
// are accessible, is not a security porblem.
|
// are accessible, is not a security porblem.
|
||||||
@ -203,7 +203,7 @@ class quiz_overview_report extends quiz_attempt_report {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$hasstudents = $students && (!$currentgroup || $groupstudents);
|
$hasstudents = $students && (!$currentgroup || $groupstudents);
|
||||||
if ($hasquestions && ($hasstudents || $attemptsmode == QUIZ_REPORT_ATTEMPTS_ALL)) {
|
if ($hasquestions && ($hasstudents || $attemptsmode == self::ALL_ATTEMPTS)) {
|
||||||
// Construct the SQL.
|
// Construct the SQL.
|
||||||
$fields = $DB->sql_concat('u.id', "'#'", 'COALESCE(quiza.attempt, 0)') .
|
$fields = $DB->sql_concat('u.id', "'#'", 'COALESCE(quiza.attempt, 0)') .
|
||||||
' AS uniqueid, ';
|
' AS uniqueid, ';
|
||||||
|
@ -28,14 +28,6 @@ defined('MOODLE_INTERNAL') || die();
|
|||||||
require_once($CFG->dirroot . '/mod/quiz/lib.php');
|
require_once($CFG->dirroot . '/mod/quiz/lib.php');
|
||||||
require_once($CFG->libdir . '/filelib.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
|
* Takes an array of objects and constructs a multidimensional array keyed by
|
||||||
* the keys it finds on the object.
|
* 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
|
// We only want to show the checkbox to delete attempts
|
||||||
// if the user has permissions and if the report mode is showing attempts.
|
// if the user has permissions and if the report mode is showing attempts.
|
||||||
$includecheckboxes = has_capability('mod/quiz:deleteattempts', $this->context)
|
$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
|
// 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
|
// groups mode, so setting allowed to empty (which means all quiz attempts
|
||||||
// are accessible, is not a security porblem.
|
// are accessible, is not a security porblem.
|
||||||
@ -188,7 +188,7 @@ class quiz_responses_report extends quiz_attempt_report {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$hasstudents = $students && (!$currentgroup || $groupstudents);
|
$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.
|
// Print information on the grading method and whether we are displaying.
|
||||||
if (!$table->is_downloading()) {
|
if (!$table->is_downloading()) {
|
||||||
// Do not print notices when downloading.
|
// Do not print notices when downloading.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user