Permalink
Browse files

Merge branch 'w34_MDL-34776_m23_notinsql' of git://github.com/skodak/…

…moodle into MOODLE_23_STABLE
  • Loading branch information...
2 parents bae745a + e3a5ed9 commit ea438c8d7bd66e3b00af27665c38969d35d4c054 @stronk7 stronk7 committed Aug 21, 2012
Showing with 14 additions and 23 deletions.
  1. +4 −6 admin/roles/lib.php
  2. +5 −9 enrol/locallib.php
  3. +3 −5 enrol/manual/locallib.php
  4. +2 −3 user/selector/lib.php
View
10 admin/roles/lib.php
@@ -1042,12 +1042,10 @@ public function find_users($search) {
$countfields = 'SELECT COUNT(u.id)';
$sql = " FROM {user} u
- WHERE u.id IN ($enrolsql) $wherecondition
- AND u.id NOT IN (
- SELECT r.userid
- FROM {role_assignments} r
- WHERE r.contextid = :contextid
- AND r.roleid = :roleid)";
+ LEFT JOIN {role_assignments} ra ON (ra.userid = u.id AND ra.roleid = :roleid AND ra.contextid = :contextid)
+ WHERE u.id IN ($enrolsql)
+ $wherecondition
+ AND ra.id IS NULL";
$order = ' ORDER BY lastname ASC, firstname ASC';
$params['contextid'] = $this->context->id;
View
14 enrol/locallib.php
@@ -278,7 +278,7 @@ public function get_potential_users($enrolid, $search='', $searchanywhere=false,
global $DB, $CFG;
// Add some additional sensible conditions
- $tests = array("id <> :guestid", 'u.deleted = 0', 'u.confirmed = 1');
+ $tests = array("u.id <> :guestid", 'u.deleted = 0', 'u.confirmed = 1');
$params = array('guestid' => $CFG->siteguest);
if (!empty($search)) {
$conditions = get_extra_user_fields($this->get_context());
@@ -306,10 +306,9 @@ public function get_potential_users($enrolid, $search='', $searchanywhere=false,
$fields = 'SELECT '.$ufields;
$countfields = 'SELECT COUNT(1)';
$sql = " FROM {user} u
+ LEFT JOIN {user_enrolments} ue ON (ue.userid = u.id AND ue.enrolid = :enrolid)
WHERE $wherecondition
- AND u.id NOT IN (SELECT ue.userid
- FROM {user_enrolments} ue
- JOIN {enrol} e ON (e.id = ue.enrolid AND e.id = :enrolid))";
+ AND ue.id IS NULL";
$order = ' ORDER BY u.lastname ASC, u.firstname ASC';
$params['enrolid'] = $enrolid;
$totalusers = $DB->count_records_sql($countfields . $sql, $params);
@@ -353,12 +352,9 @@ public function search_other_users($search='', $searchanywhere=false, $page=0, $
$fields = 'SELECT '.user_picture::fields('u', array('username','lastaccess'));
$countfields = 'SELECT COUNT(u.id)';
$sql = " FROM {user} u
+ LEFT JOIN {role_assignments} ra ON (ra.userid = u.id AND ra.contextid = :contextid)
WHERE $wherecondition
- AND u.id NOT IN (
- SELECT u.id
- FROM {role_assignments} r, {user} u
- WHERE r.contextid = :contextid AND
- u.id = r.userid)";
+ AND ra.id IS NULL";
$order = ' ORDER BY lastname ASC, firstname ASC';
$params['contextid'] = $this->context->id;
View
8 enrol/manual/locallib.php
@@ -55,11 +55,9 @@ public function find_users($search) {
$countfields = 'SELECT COUNT(1)';
$sql = " FROM {user} u
- WHERE $wherecondition AND
- u.id NOT IN (
- SELECT ue.userid
- FROM {user_enrolments} ue
- JOIN {enrol} e ON (e.id = ue.enrolid AND e.id = :enrolid))";
+ LEFT JOIN {user_enrolments} ue ON (ue.userid = u.id AND ue.enrolid = :enrolid)
+ WHERE $wherecondition
+ AND ue.id IS NULL";
$order = ' ORDER BY u.lastname ASC, u.firstname ASC';
if (!$this->is_validating()) {
View
5 user/selector/lib.php
@@ -832,10 +832,9 @@ public function find_users($search) {
JOIN ($enrolsql) e ON e.id = u.id
LEFT JOIN {role_assignments} ra ON (ra.userid = u.id AND ra.contextid " . get_related_contexts_string($context) . " AND ra.roleid $roleids)
LEFT JOIN {role} r ON r.id = ra.roleid
+ LEFT JOIN {groups_members} gm ON (gm.userid = u.id AND gm.groupid = :groupid)
WHERE u.deleted = 0
- AND u.id NOT IN (SELECT userid
- FROM {groups_members}
- WHERE groupid = :groupid)
+ AND gm.id IS NULL
AND $searchcondition";
$orderby = "ORDER BY u.lastname, u.firstname";

0 comments on commit ea438c8

Please sign in to comment.