Commit 10c4fce5 authored by John Beedell's avatar John Beedell
Browse files

MDL-27072 Quiz: Remove get_users_by_capability from quiz reports

parent d9520bc0
......@@ -7279,10 +7279,12 @@ function get_suspended_userids(context $context, $usecache = false) {
}
/**
* Gets sql for finding users with a capability in the given context
* Gets sql for finding users with capability in the given context
*
* @param context $context
* @param string $capability
* @param string|array $capability Capability name or array of names.
* If an array is provided then this is the equivalent of a logical 'OR',
* i.e. the user needs to have one of these capabilities.
* @return array($sql, $params)
*/
function get_with_capability_sql(context $context, $capability) {
......@@ -7301,11 +7303,13 @@ function get_with_capability_sql(context $context, $capability) {
}
/**
* Gets sql joins for finding users with a capability in the given context
* Gets sql joins for finding users with capability in the given context
*
* @param context $context
* @param string $capability
* @param string $useridcolumn e.g. u.id
* @param context $context Context for the join
* @param string|array $capability Capability name or array of names.
* If an array is provided then this is the equivalent of a logical 'OR',
* i.e. the user needs to have one of these capabilities.
* @param string $useridcolumn e.g. 'u.id'
* @return \core\dml\sql_join Contains joins, wheres, params
*/
function get_with_capability_join(context $context, $capability, $useridcolumn) {
......@@ -7328,14 +7332,15 @@ function get_with_capability_join(context $context, $capability, $useridcolumn)
list($contextids, $contextpaths) = get_context_info_list($context);
list($incontexts, $cparams) = $DB->get_in_or_equal($contextids, SQL_PARAMS_NAMED, 'ctx');
$cparams['cap'] = $capability;
list($incaps, $capsparams) = $DB->get_in_or_equal($capability, SQL_PARAMS_NAMED, 'cap');
$defs = array();
$sql = "SELECT rc.id, rc.roleid, rc.permission, ctx.path
FROM {role_capabilities} rc
JOIN {context} ctx on rc.contextid = ctx.id
WHERE rc.contextid $incontexts AND rc.capability = :cap";
$rcs = $DB->get_records_sql($sql, $cparams);
WHERE rc.contextid $incontexts AND rc.capability $incaps";
$rcs = $DB->get_records_sql($sql, array_merge($cparams, $capsparams));
foreach ($rcs as $rc) {
$defs[$rc->path][$rc->roleid] = $rc->permission;
}
......
......@@ -1159,7 +1159,9 @@ function is_enrolled(context $context, $user = null, $withcapability = '', $only
*
* @param context $context
* @param string $prefix optional, a prefix to the user id column
* @param string $capability optional, may include a capability name
* @param string|array $capability optional, may include a capability name, or array of names.
* If an array is provided then this is the equivalent of a logical 'OR',
* i.e. the user needs to have one of these capabilities.
* @param int $group optional, 0 indicates no current group, otherwise the group id
* @param bool $onlyactive consider only active enrolments in enabled plugins and time restrictions
* @param bool $onlysuspended inverse of onlyactive, consider only suspended enrolments
......
......@@ -72,21 +72,27 @@ abstract class quiz_attempts_report extends quiz_default_report {
* @param object $quiz
* @param object $cm
* @param object $course
* @return array with four elements:
* 0 => integer the current group id (0 for none).
* 1 => \core\dml\sql_join Contains joins, wheres, params for all the students in this course.
* 2 => \core\dml\sql_join Contains joins, wheres, params for all the students in the current group.
* 3 => \core\dml\sql_join Contains joins, wheres, params for all the students to show in the report.
* Will be the same as either element 1 or 2.
*/
protected function init($mode, $formclass, $quiz, $cm, $course) {
$this->mode = $mode;
$this->context = context_module::instance($cm->id);
list($currentgroup, $students, $groupstudents, $allowed) =
$this->load_relevant_students($cm, $course);
list($currentgroup, $studentsjoins, $groupstudentsjoins, $allowedjoins) = $this->get_students_joins(
$cm, $course);
$this->qmsubselect = quiz_report_qm_filter_select($quiz);
$this->form = new $formclass($this->get_base_url(),
array('quiz' => $quiz, 'currentgroup' => $currentgroup, 'context' => $this->context));
return array($currentgroup, $students, $groupstudents, $allowed);
return array($currentgroup, $studentsjoins, $groupstudentsjoins, $allowedjoins);
}
/**
......@@ -99,45 +105,37 @@ abstract class quiz_attempts_report extends quiz_default_report {
}
/**
* Get information about which students to show in the report.
* @param object $cm the coures module.
* Get sql fragments (joins) which can be used to build queries that
* will select an appropriate set of students to show in the reports.
*
* @param object $cm the course module.
* @param object $course the course settings.
* @return array with four elements:
* 0 => integer the current group id (0 for none).
* 1 => array ids of all the students in this course.
* 2 => array ids of all the students in the current group.
* 3 => array ids of all the students to show in the report. Will be the
* same as either element 1 or 2.
* 1 => \core\dml\sql_join Contains joins, wheres, params for all the students in this course.
* 2 => \core\dml\sql_join Contains joins, wheres, params for all the students in the current group.
* 3 => \core\dml\sql_join Contains joins, wheres, params for all the students to show in the report.
* Will be the same as either element 1 or 2.
*/
protected function load_relevant_students($cm, $course = null) {
protected function get_students_joins($cm, $course = null) {
$currentgroup = $this->get_current_group($cm, $course, $this->context);
$empty = new \core\dml\sql_join();
if ($currentgroup == self::NO_GROUPS_ALLOWED) {
return array($currentgroup, array(), array(), array());
return array($currentgroup, $empty, $empty, $empty);
}
if (!$students = get_users_by_capability($this->context,
array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'),
'u.id, 1', '', '', '', '', '', false)) {
$students = array();
} else {
$students = array_keys($students);
}
$studentsjoins = get_enrolled_with_capabilities_join($this->context);
if (empty($currentgroup)) {
return array($currentgroup, $students, array(), $students);
return array($currentgroup, $studentsjoins, $empty, $studentsjoins);
}
// We have a currently selected group.
if (!$groupstudents = get_users_by_capability($this->context,
array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'),
'u.id, 1', '', '', '', $currentgroup, '', false)) {
$groupstudents = array();
} else {
$groupstudents = array_keys($groupstudents);
}
$groupstudentsjoins = get_enrolled_with_capabilities_join($this->context, '',
array('mod/quiz:attempt', 'mod/quiz:reviewmyattempts'), $currentgroup);
return array($currentgroup, $students, $groupstudents, $groupstudents);
return array($currentgroup, $studentsjoins, $groupstudentsjoins, $groupstudentsjoins);
}
/**
......@@ -281,16 +279,17 @@ abstract class quiz_attempts_report extends quiz_default_report {
* @param object $quiz the quiz settings.
* @param object $cm the cm object for the quiz.
* @param int $currentgroup the currently selected group.
* @param array $groupstudents the students in the current group.
* @param array $allowed the users whose attempt this user is allowed to modify.
* @param \core\dml\sql_join $groupstudentsjoins (joins, wheres, params) the students in the current group.
* @param \core\dml\sql_join $allowedjoins (joins, wheres, params) the users whose attempt this user is allowed to modify.
* @param moodle_url $redirecturl where to redircet to after a successful action.
*/
protected function process_actions($quiz, $cm, $currentgroup, $groupstudents, $allowed, $redirecturl) {
if (empty($currentgroup) || $groupstudents) {
protected function process_actions($quiz, $cm, $currentgroup, \core\dml\sql_join $groupstudentsjoins,
\core\dml\sql_join $allowedjoins, $redirecturl) {
if (empty($currentgroup) || $this->hasgroupstudents) {
if (optional_param('delete', 0, PARAM_BOOL) && confirm_sesskey()) {
if ($attemptids = optional_param_array('attemptid', array(), PARAM_INT)) {
require_capability('mod/quiz:deleteattempts', $this->context);
$this->delete_selected_attempts($quiz, $cm, $attemptids, $allowed);
$this->delete_selected_attempts($quiz, $cm, $attemptids, $allowedjoins);
redirect($redirecturl);
}
}
......@@ -303,21 +302,31 @@ abstract class quiz_attempts_report extends quiz_default_report {
* this quiz are not deleted.
* @param object $cm the course_module object.
* @param array $attemptids the list of attempt ids to delete.
* @param array $allowed This list of userids that are visible in the report.
* @param \core\dml\sql_join $allowedjoins (joins, wheres, params) This list of userids that are visible in the report.
* Users can only delete attempts that they are allowed to see in the report.
* Empty means all users.
*/
protected function delete_selected_attempts($quiz, $cm, $attemptids, $allowed) {
protected function delete_selected_attempts($quiz, $cm, $attemptids, \core\dml\sql_join $allowedjoins) {
global $DB;
foreach ($attemptids as $attemptid) {
$attempt = $DB->get_record('quiz_attempts', array('id' => $attemptid));
if (!$attempt || $attempt->quiz != $quiz->id || $attempt->preview != 0) {
// Ensure the attempt exists, and belongs to this quiz. If not skip.
continue;
if (empty($allowedjoins->joins)) {
$sql = "SELECT quiza.*
FROM {quiz_attempts} quiza
JOIN {user} u ON u.id = quiza.userid
WHERE quiza.id = :attemptid";
} else {
$sql = "SELECT quiza.*
FROM {quiz_attempts} quiza
JOIN {user} u ON u.id = quiza.userid
{$allowedjoins->joins}
WHERE {$allowedjoins->wheres} AND quiza.id = :attemptid";
}
if ($allowed && !in_array($attempt->userid, $allowed)) {
// Ensure the attempt belongs to a student included in the report. If not skip.
$params = $allowedjoins->params + array('attemptid' => $attemptid);
$attempt = $DB->get_record_sql($sql, $params);
if (!$attempt || $attempt->quiz != $quiz->id || $attempt->preview != 0) {
// Ensure the attempt exists, belongs to this quiz and belongs to
// a student included in the report. If not skip.
continue;
}
......@@ -326,4 +335,21 @@ abstract class quiz_attempts_report extends quiz_default_report {
quiz_delete_attempt($attempt, $quiz);
}
}
/**
* Get information about which students to show in the report.
* @param object $cm the coures module.
* @param object $course the course settings.
* @return array with four elements:
* 0 => integer the current group id (0 for none).
* 1 => array ids of all the students in this course.
* 2 => array ids of all the students in the current group.
* 3 => array ids of all the students to show in the report. Will be the
* same as either element 1 or 2.
* @deprecated since Moodle 3.2 Please use get_students_joins() instead.
*/
protected function load_relevant_students($cm, $course = null) {
$msg = 'The function load_relevant_students() is deprecated. Please use get_students_joins() instead.';
throw new coding_exception($msg);
}
}
......@@ -61,11 +61,13 @@ abstract class quiz_attempts_report_table extends table_sql {
/** @var object mod_quiz_attempts_report_options the options affecting this report. */
protected $options;
/** @var object the ids of the students in the currently selected group, if applicable. */
protected $groupstudents;
/** @var \core\dml\sql_join Contains joins, wheres, params to find students
* in the currently selected group, if applicable.
*/
protected $groupstudentsjoins;
/** @var object the ids of the students in the course. */
protected $students;
/** @var \core\dml\sql_join Contains joins, wheres, params to find the students in the course. */
protected $studentsjoins;
/** @var object the questions that comprise this quiz.. */
protected $questions;
......@@ -80,20 +82,20 @@ abstract class quiz_attempts_report_table extends table_sql {
* @param context $context
* @param string $qmsubselect
* @param mod_quiz_attempts_report_options $options
* @param array $groupstudents
* @param array $students
* @param \core\dml\sql_join $groupstudentsjoins Contains joins, wheres, params
* @param \core\dml\sql_join $studentsjoins Contains joins, wheres, params
* @param array $questions
* @param moodle_url $reporturl
*/
public function __construct($uniqueid, $quiz, $context, $qmsubselect,
mod_quiz_attempts_report_options $options, $groupstudents, $students,
mod_quiz_attempts_report_options $options, \core\dml\sql_join $groupstudentsjoins, \core\dml\sql_join $studentsjoins,
$questions, $reporturl) {
parent::__construct($uniqueid);
$this->quiz = $quiz;
$this->context = $context;
$this->qmsubselect = $qmsubselect;
$this->groupstudents = $groupstudents;
$this->students = $students;
$this->groupstudentsjoins = $groupstudentsjoins;
$this->studentsjoins = $studentsjoins;
$this->questions = $questions;
$this->includecheckboxes = $options->checkboxcolumn;
$this->reporturl = $reporturl;
......@@ -380,11 +382,11 @@ abstract class quiz_attempts_report_table extends table_sql {
/**
* Contruct all the parts of the main database query.
* @param array $reportstudents list if userids of users to include in the report.
* @param \core\dml\sql_join $allowedstudentsjoins (joins, wheres, params) defines allowed users for the report.
* @return array with 4 elements ($fields, $from, $where, $params) that can be used to
* build the actual database query.
* build the actual database query.
*/
public function base_sql($reportstudents) {
public function base_sql(\core\dml\sql_join $allowedstudentsjoins) {
global $DB;
$fields = $DB->sql_concat('u.id', "'#'", 'COALESCE(quiza.attempt, 0)') . ' AS uniqueid,';
......@@ -419,7 +421,7 @@ abstract class quiz_attempts_report_table extends table_sql {
// badly synchronised clocks, and a student does a really quick attempt.
// This part is the same for all cases. Join the users and quiz_attempts tables.
$from = "\n{user} u";
$from = " {user} u";
$from .= "\nLEFT JOIN {quiz_attempts} quiza ON
quiza.userid = u.id AND quiza.quiz = :quizid";
$params = array('quizid' => $this->quiz->id);
......@@ -436,24 +438,21 @@ abstract class quiz_attempts_report_table extends table_sql {
break;
case quiz_attempts_report::ENROLLED_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";
$from .= "\n" . $allowedstudentsjoins->joins;
$where = "quiza.preview = 0 AND quiza.id IS NOT NULL AND " . $allowedstudentsjoins->wheres;
$params = array_merge($params, $allowedstudentsjoins->params);
break;
case quiz_attempts_report::ENROLLED_WITHOUT:
// 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";
$from .= "\n" . $allowedstudentsjoins->joins;
$where = "quiza.id IS NULL AND " . $allowedstudentsjoins->wheres;
$params = array_merge($params, $allowedstudentsjoins->params);
break;
case quiz_attempts_report::ENROLLED_ALL:
// Show all students with or without attempts.
list($usql, $uparams) = $DB->get_in_or_equal(
$reportstudents, SQL_PARAMS_NAMED, 'u');
$params += $uparams;
$where = "u.id $usql AND (quiza.preview = 0 OR quiza.preview IS NULL)";
$from .= "\n" . $allowedstudentsjoins->joins;
$where = "(quiza.preview = 0 OR quiza.preview IS NULL) AND " . $allowedstudentsjoins->wheres;
$params = array_merge($params, $allowedstudentsjoins->params);
break;
}
......
......@@ -49,7 +49,6 @@ class quiz_grading_report extends quiz_default_report {
protected $context;
public function display($quiz, $cm, $course) {
global $CFG, $DB, $PAGE;
$this->quiz = $quiz;
$this->cm = $cm;
......@@ -116,11 +115,10 @@ class quiz_grading_report extends quiz_default_report {
// Get the group, and the list of significant users.
$this->currentgroup = $this->get_current_group($cm, $course, $this->context);
if ($this->currentgroup == self::NO_GROUPS_ALLOWED) {
$this->users = array();
$this->userssql = array();
} else {
$this->users = get_users_by_capability($this->context,
array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'), '', '', '', '',
$this->currentgroup, '', false);
$this->userssql = get_enrolled_sql($this->context,
array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'), $this->currentgroup);
}
$hasquestions = quiz_has_questions($quiz->id);
......@@ -158,29 +156,28 @@ class quiz_grading_report extends quiz_default_report {
}
protected function get_qubaids_condition() {
global $DB;
$where = "quiza.quiz = :mangrquizid AND
quiza.preview = 0 AND
quiza.state = :statefinished";
$params = array('mangrquizid' => $this->cm->instance, 'statefinished' => quiz_attempt::FINISHED);
$usersjoin = '';
$currentgroup = groups_get_activity_group($this->cm, true);
$enrolleduserscount = count_enrolled_users($this->context,
array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'), $currentgroup);
if ($currentgroup) {
$users = get_users_by_capability($this->context,
array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'), 'u.id, u.id', '', '', '',
$currentgroup, '', false);
if (empty($users)) {
$userssql = get_enrolled_sql($this->context,
array('mod/quiz:reviewmyattempts', 'mod/quiz:attempt'), $currentgroup);
if ($enrolleduserscount < 1) {
$where .= ' AND quiza.userid = 0';
} else {
list($usql, $uparam) = $DB->get_in_or_equal(array_keys($users),
SQL_PARAMS_NAMED, 'mangru');
$where .= ' AND quiza.userid ' . $usql;
$params += $uparam;
$usersjoin = "JOIN ({$userssql[0]}) AS enr ON quiza.userid = enr.id";
$params += $userssql[1];
}
}
return new qubaid_join('{quiz_attempts} quiza', 'quiza.uniqueid', $where, $params);
return new qubaid_join("{quiz_attempts} quiza $usersjoin ", 'quiza.uniqueid', $where, $params);
}
protected function load_attempts_by_usage_ids($qubaids) {
......
@mod @mod_quiz @mod_quiz_grading_basic
Feature: Basic use of the Manual grading report
In order to easily find students attempts that need manual grading
As a teacher
I need to use the manual grading report
@javascript
Scenario: Use the Manual grading report
Given the following "users" exist:
| username | firstname | lastname | email | idnumber |
| teacher1 | T1 | Teacher1 | teacher1@example.com | T1000 |
| student1 | S1 | Student1 | student1@example.com | S1000 !
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
And I log in as "teacher1"
And I am on site homepage
And I follow "Course 1"
And I turn editing mode on
And I add a "Quiz" to section "1" and I fill the form with:
| Name | Quiz 1 |
| Description | Quiz 1 description |
And I add a "Short answer" question to the "Quiz 1" quiz with:
| Question name | Short answer 001 |
| Question text | Where is the capital city of France? |
| Answer 1 | Paris |
| Grade | 100% |
# Check report shows nothing when there are no attempts.
And I follow "Course 1"
And I follow "Quiz 1"
When I navigate to "Manual grading" node in "Quiz administration > Results"
Then I should see "Manual grading"
And I should see "Quiz 1"
And I should see "Nothing to display"
And I follow "Also show questions that have been graded automatically"
And I should see "Nothing to display"
And I log out
# Create an attempt.
When I log in as "student1"
And I follow "Course 1"
And I follow "Quiz 1"
And I press "Attempt quiz now"
Then I should see "Question 1"
And I should see "Not yet answered"
And I should see "Where is the capital city of France?"
When I set the field "Answer:" to "Paris"
And I press "Finish attempt ..."
Then I should see "Answer saved"
When I press "Submit all and finish"
And I click on "Submit all and finish" "button" in the "Confirmation" "dialogue"
And I log out
# Use the manual grading report.
When I log in as "teacher1"
And I follow "Course 1"
And I follow "Quiz 1"
And I navigate to "Manual grading" node in "Quiz administration > Results"
Then I should see "Manual grading"
When I follow "Also show questions that have been graded automatically"
Then I should see "Short answer 001"
And I should see "0" in the ".cell.c2" "css_element"
And I should see "0" in the ".cell.c3" "css_element"
# Adjust the mark for Student1.
When I click on "update grades" "link" in the "Short answer 001" "table_row"
And I set the field "Comment" to "I have adjusted your mark to 0.6"
And I set the field "Mark" to "0.6"
And I press "Save and go to next page"
Then I should see "All selected attempts have been graded. Returning to the list of questions."
And I should see "0" in the ".cell.c2" "css_element"
And I should see "1" in the ".cell.c3" "css_element"
......@@ -44,15 +44,16 @@ class quiz_overview_table extends quiz_attempts_report_table {
* @param context $context
* @param string $qmsubselect
* @param quiz_overview_options $options
* @param array $groupstudents
* @param array $students
* @param \core\dml\sql_join $groupstudentsjoins
* @param \core\dml\sql_join $studentsjoins
* @param array $questions
* @param moodle_url $reporturl
*/
public function __construct($quiz, $context, $qmsubselect,
quiz_overview_options $options, $groupstudents, $students, $questions, $reporturl) {
quiz_overview_options $options, \core\dml\sql_join $groupstudentsjoins,
\core\dml\sql_join $studentsjoins, $questions, $reporturl) {
parent::__construct('mod-quiz-report-overview-report', $quiz , $context,
$qmsubselect, $options, $groupstudents, $students, $questions, $reporturl);
$qmsubselect, $options, $groupstudentsjoins, $studentsjoins, $questions, $reporturl);
}
public function build_table() {
......@@ -68,24 +69,39 @@ class quiz_overview_table extends quiz_attempts_report_table {
// End of adding the data from attempts. Now add averages at bottom.
$this->add_separator();
if ($this->groupstudents) {
$this->add_average_row(get_string('groupavg', 'grades'), $this->groupstudents);
if (!empty($this->groupstudentsjoins->joins)) {
$sql = "SELECT DISTINCT u.id
FROM {user} u
{$this->groupstudentsjoins->joins}
WHERE {$this->groupstudentsjoins->wheres}";
$groupstudents = $DB->get_records_sql($sql, $this->groupstudentsjoins->params);
if ($groupstudents) {
$this->add_average_row(get_string('groupavg', 'grades'), $this->groupstudentsjoins);
}
}
if ($this->students) {
$this->add_average_row(get_string('overallaverage', 'grades'), $this->students);
if (!empty($this->studentsjoins->joins)) {
$sql = "SELECT DISTINCT u.id
FROM {user} u
{$this->studentsjoins->joins}
WHERE {$this->studentsjoins->wheres}";
$students = $DB->get_records_sql($sql, $this->studentsjoins->params);
if ($students) {
$this->add_average_row(get_string('overallaverage', 'grades'), $this->studentsjoins);
}
}
}
/**
* Add an average grade over the attempts of a set of users.
* @param string $label the title ot use for this row.
* @param array $users the users to average over.
* @param \core\dml\sql_join $usersjoins (joins, wheres, params) for the users to average over.
*/
protected function add_average_row($label, $users) {
protected function add_average_row($label, \core\dml\sql_join $usersjoins) {
global $DB;
list($fields, $from, $where, $params) = $this->base_sql($users);
list($fields, $from, $where, $params) = $this->base_sql($usersjoins);
$record = $DB->get_record_sql("
SELECT AVG(quiza.sumgrades) AS grade, COUNT(quiza.sumgrades) AS numaveraged
FROM $from
......
......@@ -40,10 +40,11 @@ require_once($CFG->dirroot . '/mod/quiz/report/overview/overview_table.php');
class quiz_overview_report extends quiz_attempts_report {
public function display($quiz, $cm, $course) {
global $CFG, $DB, $OUTPUT, $PAGE;
global $DB, $OUTPUT, $PAGE;
list($currentgroup, $studentsjoins, $groupstudentsjoins, $allowedjoins) = $this->init(
'overview', 'quiz_overview_settings_form', $quiz, $cm, $course);
list($currentgroup, $students, $groupstudents, $allowed) =
$this->init('overview', 'quiz_overview_settings_form', $quiz, $cm, $course);
$options = new quiz_overview_options('overview', $quiz, $cm, $course);
if ($fromform = $this->form->get_data()) {
......@@ -55,13 +56,6 @@ class quiz_overview_report extends quiz_attempts_report {
$this->form->set_data($options->get_initial_form_data());
if ($options->attempts == self::ALL_WITH) {
// 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.
$allowed = array();
}
// Load the required questions.
$questions = quiz_report_get_significant_questions($quiz);
......@@ -69,7 +63,7 @@ class quiz_overview_report extends quiz_attempts_report {
$courseshortname = format_string($course->shortname, true,
array('context' => context_course::instance($course->id)));
$table = new quiz_overview_table($quiz, $this->context, $this->qmsubselect,
$options, $groupstudents, $students, $questions, $options->get_url());
$options, $groupstudentsjoins, $studentsjoins, $questions, $options->get_url());
$filename = quiz_report_download_filename(get_string('overviewfilename', 'quiz_overview'),
$courseshortname, $quiz->name);
$table->is_downloading($options->download, $filename,
......@@ -78,8 +72,31 @@ class quiz_overview_report extends quiz_attempts_report {
raise_memory_limit(MEMORY_EXTRA);
}
$this->hasgroupstudents = false;
if (!empty($groupstudentsjoins->joins)) {
$sql = "SELECT DISTINCT u.id
FROM {user} u
$groupstudentsjoins->joins
WHERE $groupstudentsjoins->wheres";
$this->hasgroupstudents = $DB->record_exists_sql($sql, $groupstudentsjoins->params);
}
$hasstudents = false;
if (!empty($studentsjoins->joins)) {
$sql = "SELECT DISTINCT u.id