Commit cbbc2725 authored by Petr Skoda's avatar Petr Skoda
Browse files

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

parents 251e5a8b e07c51c4
......@@ -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) {
......
......@@ -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);
......@@ -135,12 +135,17 @@ switch ($mode) {
} 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');
}
}
......
......@@ -41,10 +41,12 @@ require_login($course, false, $cm);
$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 @@ if (!empty($cm->groupingid)) {
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
......
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