Skip to content

Commit

Permalink
Merge branch 'wip-MDL-57511-master' of git://github.com/Beedell/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
danpoltawski committed Jan 23, 2017
2 parents e3ee9d4 + 8b0d254 commit 4bd0a8a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/enrollib.php
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion mod/quiz/report/attemptsreport_table.php
Expand Up @@ -389,7 +389,8 @@ protected function get_required_latest_state_fields($slot, $alias) {
public function base_sql(\core\dml\sql_join $allowedstudentsjoins) {
global $DB;

$fields = $DB->sql_concat('u.id', "'#'", 'COALESCE(quiza.attempt, 0)') . ' AS uniqueid,';
// Please note this uniqueid column is not the same as quiza.uniqueid.
$fields = 'DISTINCT ' . $DB->sql_concat('u.id', "'#'", 'COALESCE(quiza.attempt, 0)') . ' AS uniqueid,';

if ($this->qmsubselect) {
$fields .= "\n(CASE WHEN $this->qmsubselect THEN 1 ELSE 0 END) AS gradedattempt,";
Expand Down
8 changes: 8 additions & 0 deletions mod/quiz/report/overview/tests/report_test.php
Expand Up @@ -90,6 +90,14 @@ public function test_report_sql() {
$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);
Expand Down

0 comments on commit 4bd0a8a

Please sign in to comment.