MDL-47227 admin: Fix user bulk selection over 1000
[moodle.git] / admin / user / lib.php
CommitLineData
244bb396 1<?php
cd1edf9e 2
3require_once($CFG->dirroot.'/user/filters/lib.php');
4
5if (!defined('MAX_BULK_USERS')) {
6 define('MAX_BULK_USERS', 2000);
7}
8
9function add_selection_all($ufiltering) {
c30bcaae 10 global $SESSION, $DB, $CFG;
cd1edf9e 11
04aec3da 12 list($sqlwhere, $params) = $ufiltering->get_sql_filter("id<>:exguest AND deleted <> 1", array('exguest'=>$CFG->siteguest));
cd1edf9e 13
755d2c74
EL
14 $rs = $DB->get_recordset_select('user', $sqlwhere, $params, 'fullname', 'id,'.$DB->sql_fullname().' AS fullname');
15 foreach ($rs as $user) {
16 if (!isset($SESSION->bulk_users[$user->id])) {
17 $SESSION->bulk_users[$user->id] = $user->id;
cd1edf9e 18 }
cd1edf9e 19 }
755d2c74 20 $rs->close();
cd1edf9e 21}
22
23function get_selection_data($ufiltering) {
39bc8cd0 24 global $SESSION, $DB, $CFG;
cd1edf9e 25
26 // get the SQL filter
04aec3da 27 list($sqlwhere, $params) = $ufiltering->get_sql_filter("id<>:exguest AND deleted <> 1", array('exguest'=>$CFG->siteguest));
cd1edf9e 28
04aec3da 29 $total = $DB->count_records_select('user', "id<>:exguest AND deleted <> 1", array('exguest'=>$CFG->siteguest));
624a690b 30 $acount = $DB->count_records_select('user', $sqlwhere, $params);
cd1edf9e 31 $scount = count($SESSION->bulk_users);
32
33 $userlist = array('acount'=>$acount, 'scount'=>$scount, 'ausers'=>false, 'susers'=>false, 'total'=>$total);
ca8d6e37 34 $userlist['ausers'] = $DB->get_records_select_menu('user', $sqlwhere, $params, 'fullname', 'id,'.$DB->sql_fullname().' AS fullname', 0, MAX_BULK_USERS);
cd1edf9e 35
36 if ($scount) {
37 if ($scount < MAX_BULK_USERS) {
912296ad 38 $bulkusers = $SESSION->bulk_users;
cd1edf9e 39 } else {
a5137c50 40 $bulkusers = array_slice($SESSION->bulk_users, 0, MAX_BULK_USERS, true);
cd1edf9e 41 }
912296ad
PFO
42 list($in, $inparams) = $DB->get_in_or_equal($bulkusers);
43 $userlist['susers'] = $DB->get_records_select_menu('user', "id $in", $inparams, 'fullname', 'id,'.$DB->sql_fullname().' AS fullname');
cd1edf9e 44 }
45
46 return $userlist;
47}