Permalink
Browse files

MDL-26371 sql - avoid distinct + text in lesson essay & report

  • Loading branch information...
1 parent b37d06c commit e07c51c4811e39d8efddf4f2cbd4fa153253fa16 @stronk7 stronk7 committed Feb 12, 2011
Showing with 15 additions and 8 deletions.
  1. +11 −6 mod/lesson/essay.php
  2. +4 −2 mod/lesson/report.php
View
@@ -135,12 +135,17 @@
} else {
$queryadd = '';
$params = array ("lessonid" => $lesson->id);
- if (!$users = $DB->get_records_sql("SELECT DISTINCT u.id, u.*
- FROM {user} u,
- {lesson_attempts} a
- WHERE a.lessonid = :lessonid and
- u.id = a.userid
- ORDER BY u.lastname", $params)) {
+ // Need to use inner view to avoid distinct + text
+ if (!$users = $DB->get_records_sql("
+ SELECT u.*
+ FROM {user} u
+ JOIN (
+ SELECT DISTINCT u.id
+ FROM {user} u,
+ {lesson_attempts} a
+ WHERE a.lessonid = :lessonid and
+ u.id = a.userid) ui ON (u.id = ui.id)
+ ORDER BY u.lastname", $params)) {
print_error('cannotfinduser', 'lesson');
}
}
View
@@ -41,18 +41,20 @@
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_capability('mod/lesson:manage', $context);
+$ufields = user_picture::fields('u'); // These fields are enough
$params = array("lessonid" => $lesson->id);
+// TODO: Improve this. Fetching all students always is crazy!
if (!empty($cm->groupingid)) {
$params["groupid"] = $cm->groupingid;
- $sql = "SELECT DISTINCT u.id, u.*
+ $sql = "SELECT DISTINCT $ufields
FROM {lesson_attempts} a
INNER JOIN {user} u ON u.id = a.userid
INNER JOIN {groups_members} gm ON gm.userid = u.id
INNER JOIN {groupings_groups} gg ON gm.groupid = :groupid
WHERE a.lessonid = :lessonid
ORDER BY u.lastname";
} else {
- $sql = "SELECT DISTINCT u.id, u.*
+ $sql = "SELECT DISTINCT $ufields
FROM {user} u,
{lesson_attempts} a
WHERE a.lessonid = :lessonid and

0 comments on commit e07c51c

Please sign in to comment.