Commit 4bd0a8a6 authored by Dan Poltawski's avatar Dan Poltawski
Browse files

Merge branch 'wip-MDL-57511-master' of git://

parents e3ee9d48 8b0d254f
......@@ -1179,6 +1179,10 @@ function is_enrolled(context $context, $user = null, $withcapability = '', $only
* Returns an array of joins, wheres and params that will limit the group of
* users to only those enrolled and with given capability (if specified).
* Note this join will return duplicate rows for users who have been enrolled
* several times (e.g. as manual enrolment, and as self enrolment). You may
* need to use a SELECT DISTINCT in your query (see get_enrolled_sql for example).
* @param context $context
* @param string $prefix optional, a prefix to the user id column
* @param string|array $capability optional, may include a capability name, or array of names.
......@@ -389,7 +389,8 @@ abstract class quiz_attempts_report_table extends table_sql {
public function base_sql(\core\dml\sql_join $allowedstudentsjoins) {
global $DB;
$fields = $DB->sql_concat('', "'#'", 'COALESCE(quiza.attempt, 0)') . ' AS uniqueid,';
// Please note this uniqueid column is not the same as quiza.uniqueid.
$fields = 'DISTINCT ' . $DB->sql_concat('', "'#'", 'COALESCE(quiza.attempt, 0)') . ' AS uniqueid,';
if ($this->qmsubselect) {
$fields .= "\n(CASE WHEN $this->qmsubselect THEN 1 ELSE 0 END) AS gradedattempt,";
......@@ -90,6 +90,14 @@ class quiz_overview_report_testcase extends advanced_testcase {
$DB->insert_record('quiz_attempts', $data);
// This line is not really necessary for the test asserts below,
// but what it does is add an extra user row returned by
// get_enrolled_with_capabilities_join because of a second enrolment.
// The extra row returned used to make $table->query_db complain
// about duplicate records. So this is really a test that an extra
// student enrolment does not cause duplicate records in this query.
$generator->enrol_user($student2->id, $course->id, null, 'self');
// Actually getting the SQL to run is quite hard. Do a minimal set up of
// some objects.
$context = context_module::instance($quiz->cmid);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment