From: moodler Date: Sun, 1 Oct 2006 08:08:26 +0000 (+0000) Subject: FIxes for the assign screen, to make it a lot faster and able to cope X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=a971a5985aa017ddbf5159d0aaf893f8007d1900;p=moodle.git FIxes for the assign screen, to make it a lot faster and able to cope better with very large numbers of users MDL-6766 --- diff --git a/admin/roles/assign.html b/admin/roles/assign.html index 8d63225313..8ee63e9a47 100755 --- a/admin/roles/assign.html +++ b/admin/roles/assign.html @@ -19,9 +19,9 @@ + onFocus="document.assignform.add.disabled=false; + document.assignform.remove.disabled=true; + document.assignform.removeselect.selectedIndex=-1;"> \n"; - foreach ($searchusers as $user) { - $fullname = fullname($user, true); - echo "\n"; + if (!empty($searchtext)) { + echo "_numOfRows . ")\">\n"; + while (! $availableusers->EOF) { + $user = $availableusers->FetchObj(); + if (!isset($contextusers[$user->id])) { + $fullname = fullname($user, true); + echo "\n"; + } + $availableusers->MoveNext(); } echo "\n"; - } - else { + + } else { if ($usercount > MAX_USERS_PER_PAGE) { echo ''."\n" .''."\n"; - } - else { - if ($usercount > 0) { //fix for bug#4455 - foreach ($users as $user) { + } else { + while (! $availableusers->EOF) { + $user = $availableusers->FetchObj(); + if (!isset($contextusers[$user->id])) { $fullname = fullname($user, true); echo "\n"; } + $availableusers->MoveNext(); } } } @@ -70,14 +75,14 @@
addselect as $adduser) { - $adduser = clean_param($adduser, PARAM_INT); + if (!$adduser = clean_param($adduser, PARAM_INT)) { + continue; + } $allow = true; if ($inmeta) { if (has_capability('moodle/course:managemetacourse', $context, $adduser)) { @@ -175,44 +179,34 @@ } } + if ($roleid) { /// prints a form to swap roles -/// Get all existing participants in this course. - - $existinguserarray = array(); - - if (!$contextusers = get_role_users($roleid, $context)) { - $contextusers = array(); - } + /// Get all existing participants in this context. - foreach ($contextusers as $contextuser) { - $existinguserarray[] = $contextuser->id; - } + if (!$contextusers = get_role_users($roleid, $context, false, 'u.id, u.firstname, u.lastname, u.email')) { + $contextusers = array(); + } - $existinguserlist = implode(',', $existinguserarray); - unset($existinguserarray); + $select = "username <> 'guest' AND deleted = 0 AND confirmed = 1"; + + $usercount = count_records_select('user', $select) - count($contextusers); - $usercount = get_users(false, '', true, $existinguserlist); + $searchtext = trim($searchtext); -/// Get search results excluding any users already in this course - if (($searchtext != '') and $previoussearch) { - $searchusers = get_users(true, $searchtext, true, $existinguserlist, 'firstname ASC, lastname ASC', - '', '', 0, MAX_USERS_PER_PAGE, 'id, firstname, lastname, email'); - } + if ($searchtext !== '') { // Search for a subset of remaining users + $LIKE = sql_ilike(); + $FULLNAME = sql_fullname(); -/// If no search results then get potential students for this course excluding users already in course - if (empty($searchusers)) { - $users = array(); - if ($usercount <= MAX_USERS_PER_PAGE) { - if (!$users = get_users(true, '', true, $existinguserlist, 'firstname ASC, lastname ASC', '', '', - 0, MAX_USERS_PER_PAGE, 'id, firstname, lastname, email')) { - $users = array(); - } + $select .= " AND ($FULLNAME $LIKE '%$searchtext%' OR email $LIKE '%$searchtext%') "; } - } + $availableusers = get_recordset_sql('SELECT id, firstname, lastname, email + FROM '.$CFG->prefix.'user + WHERE '.$select.' + ORDER BY lastname ASC, firstname ASC'); - if ($roleid) { - /// prints a form to swap roles + /// In the .html file below we loop through these results and exclude any in $contextusers + echo '
'; echo '
'.$strcurrentcontext.': '.print_context_name($context).'
'; if ($userid) { @@ -254,10 +248,7 @@ $table->align = array('right', 'center'); foreach ($assignableroles as $roleid => $rolename) { - $countusers = 0; - if ($contextusers = get_role_users($roleid, $context)) { - $countusers = count($contextusers); - } + $countusers = count_role_users($roleid, $context); $table->data[] = array(''.$rolename.'', $countusers); }