From f7b2d6bf39a5a8299f6b06bdfdc7a19c4b69b34a Mon Sep 17 00:00:00 2001 From: VASILEIOS SOTIRAS Date: Fri, 27 Apr 2018 10:34:58 +0100 Subject: [PATCH] Update locallib.php Avoid Moodle Query duplicate records error by adding a unique id for each tuple --- locallib.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/locallib.php b/locallib.php index 554e353..2cc0373 100644 --- a/locallib.php +++ b/locallib.php @@ -24,8 +24,9 @@ function report_componentgrades_get_students($courseid) { global $DB; - return $DB->get_records_sql('SELECT stu.id AS userid, stu.idnumber AS idnumber, stu.firstname, stu.lastname, stu.username AS student - FROM {user} AS stu + return $DB->get_records_sql('SELECT (@id := @id +1) id,stu.id AS userid, stu.idnumber AS idnumber, stu.firstname, stu.lastname, stu.username AS student + FROM (select @id :=0 id) id, + {user} AS stu JOIN {user_enrolments} ue ON ue.userid = stu.id JOIN {enrol} enr ON ue.enrolid = enr.id WHERE enr.courseid = ? @@ -113,4 +114,4 @@ function report_componentgrades_add_data($sheet, $students, $gradinginfopos, $me } } } -} \ No newline at end of file +}