Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'MDL-26371_distinct_text' of git://github.com/stronk7/mo…

…odle
  • Loading branch information...
commit cbbc272542ce9ea185c6e0a7cee84c4f740f6ba1 2 parents 251e5a8 + e07c51c
@skodak skodak authored
View
24 enrol/category/locallib.php
@@ -263,16 +263,22 @@ function enrol_category_sync_full() {
// first of all add necessary enrol instances to all courses
$parentcat = $DB->sql_concat("cat.path", "'/%'");
- $sql = "SELECT DISTINCT c.*
+ // need whole course records to be used by add_instance(), use inner view (ci) to
+ // get distinct records only.
+ // TODO: Moodle 2.1. Improve enrol API to accept courseid / courserec
+ $sql = "SELECT c.*
FROM {course} c
- JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :courselevel)
- JOIN (SELECT DISTINCT cctx.path
- FROM {course_categories} cc
- JOIN {context} cctx ON (cctx.instanceid = cc.id AND cctx.contextlevel = :catlevel)
- JOIN {role_assignments} ra ON (ra.contextid = cctx.id AND ra.roleid $roleids)
- ) cat ON (ctx.path LIKE $parentcat)
- LEFT JOIN {enrol} e ON (e.courseid = c.id AND e.enrol = 'category')
- WHERE e.id IS NULL";
+ JOIN (
+ SELECT DISTINCT c.id
+ FROM {course} c
+ JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :courselevel)
+ JOIN (SELECT DISTINCT cctx.path
+ FROM {course_categories} cc
+ JOIN {context} cctx ON (cctx.instanceid = cc.id AND cctx.contextlevel = :catlevel)
+ JOIN {role_assignments} ra ON (ra.contextid = cctx.id AND ra.roleid $roleids)
+ ) cat ON (ctx.path LIKE $parentcat)
+ LEFT JOIN {enrol} e ON (e.courseid = c.id AND e.enrol = 'category')
+ WHERE e.id IS NULL) ci ON (c.id = ci.id)";
$rs = $DB->get_recordset_sql($sql, $params);
foreach($rs as $course) {
View
14 mod/glossary/sql.php
@@ -134,6 +134,9 @@
default:
$sqlselect = "SELECT ge.*, ge.concept AS glossarypivot";
$sqlfrom = "FROM {glossary_entries} ge";
+ // For cases needing inner view
+ $sqlwrapheader = '';
+ $sqlwrapfooter = '';
$where = '';
$fullpivot = 0;
@@ -203,7 +206,13 @@
} else {
$searchcond = implode(" AND ", $searchcond);
- $sqlselect = "SELECT DISTINCT ge.*, ge.concept AS glossarypivot";
+ // Need one inner view here to avoid distinct + text
+ $sqlwrapheader = 'SELECT ge.*, ge.concept AS glossarypivot
+ FROM {glossary_entries} ge
+ JOIN ( ';
+ $sqlwrapfooter = ' ) gei ON (ge.id = gei.id)';
+
+ $sqlselect = "SELECT DISTINCT ge.id";
$sqlfrom = "FROM {glossary_entries} ge
LEFT JOIN {glossary_alias} al ON al.entryid = ge.id";
$where = "AND ($searchcond)";
@@ -262,5 +271,6 @@
$limitnum = $entriesbypage;
}
- $allentries = $DB->get_records_sql("$sqlselect $sqlfrom $sqlwhere $sqlorderby", $params, $limitfrom, $limitnum);
+ $query = "$sqlwrapheader $sqlselect $sqlfrom $sqlwhere $sqlwrapfooter $sqlorderby";
+ $allentries = $DB->get_records_sql($query, $params, $limitfrom, $limitnum);
View
17 mod/lesson/essay.php
@@ -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
6 mod/lesson/report.php
@@ -41,10 +41,12 @@
$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
@@ -52,7 +54,7 @@
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
Please sign in to comment.
Something went wrong with that request. Please try again.