Skip to content

Commit

Permalink
MDL-36395: Converted hard-coded MAX_USER_PER_PAGE to config setting
Browse files Browse the repository at this point in the history
course, cohort, enrol, role, groups and forum used to use hard-coded
MAX_USERS_PER_PAGE=100 for rendering user list. This has been converted
to $CFG->maxusersperpage.
  • Loading branch information
Rajesh Taneja committed Mar 12, 2013
1 parent 8673a98 commit 9a51c3d
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 23 deletions.
15 changes: 5 additions & 10 deletions admin/roles/lib.php
Expand Up @@ -1089,8 +1089,6 @@ protected function add_permission_cells($capability) {
* Base class to avoid duplicating code.
*/
abstract class role_assign_user_selector_base extends user_selector_base {
const MAX_USERS_PER_PAGE = 100;

protected $roleid;
protected $context;

Expand Down Expand Up @@ -1159,7 +1157,7 @@ public function find_users($search) {
// Check to see if there are too many to show sensibly.
if (!$this->is_validating()) {
$potentialmemberscount = $DB->count_records_sql($countfields . $sql, $params);
if ($potentialmemberscount > role_assign_user_selector_base::MAX_USERS_PER_PAGE) {
if ($potentialmemberscount > $this->maxusersperpage) {
return $this->too_many_results($search, $potentialmemberscount);
}
}
Expand Down Expand Up @@ -1187,9 +1185,6 @@ public function find_users($search) {
* @copyright 2012 Petr Skoda {@link http://skodak.org}
*/
class role_check_users_selector extends user_selector_base {
const MAX_ENROLLED_PER_PAGE = 100;
const MAX_POTENTIAL_PER_PAGE = 100;

/** @var bool limit listing of users to enrolled only */
var $onlyenrolled;

Expand Down Expand Up @@ -1270,7 +1265,7 @@ public function find_users($search) {

if ($sql1) {
$enrolleduserscount = $DB->count_records_sql($countfields . $sql1, $params);
if (!$this->is_validating() and $enrolleduserscount > $this::MAX_ENROLLED_PER_PAGE) {
if (!$this->is_validating() and $enrolleduserscount > $this->maxusersperpage) {
$result[$groupname1] = array();
$toomany = $this->too_many_results($search, $enrolleduserscount);
$result[implode(' - ', array_keys($toomany))] = array();
Expand All @@ -1287,7 +1282,7 @@ public function find_users($search) {
}
if ($sql2) {
$otheruserscount = $DB->count_records_sql($countfields . $sql2, $params);
if (!$this->is_validating() and $otheruserscount > $this::MAX_POTENTIAL_PER_PAGE) {
if (!$this->is_validating() and $otheruserscount > $this->maxusersperpage) {
$result[$groupname2] = array();
$toomany = $this->too_many_results($search, $otheruserscount);
$result[implode(' - ', array_keys($toomany))] = array();
Expand Down Expand Up @@ -1340,7 +1335,7 @@ public function find_users($search) {

if (!$this->is_validating()) {
$potentialmemberscount = $DB->count_records_sql($countfields . $sql, $params);
if ($potentialmemberscount > role_assign_user_selector_base::MAX_USERS_PER_PAGE) {
if ($potentialmemberscount > $this->maxusersperpage) {
return $this->too_many_results($search, $potentialmemberscount);
}
}
Expand Down Expand Up @@ -1765,7 +1760,7 @@ public function find_users($search) {
// Check to see if there are too many to show sensibly.
if (!$this->is_validating()) {
$potentialcount = $DB->count_records_sql($countfields . $sql, $params);
if ($potentialcount > 100) {
if ($potentialcount > $this->maxusersperpage) {
return $this->too_many_results($search, $potentialcount);
}
}
Expand Down
1 change: 1 addition & 0 deletions admin/settings/users.php
Expand Up @@ -150,6 +150,7 @@
'department' => new lang_string('department'),
'institution' => new lang_string('institution'),
)));
$temp->add(new admin_setting_configtext('maxusersperpage', new lang_string('maxusersperpage','admin'), new lang_string('configmaxusersperpage','admin'), 100, PARAM_INT));
$temp->add(new admin_setting_configcheckbox('enablegravatar', new lang_string('enablegravatar', 'admin'), new lang_string('enablegravatar_help', 'admin'), 0));
$temp->add(new admin_setting_configtext('gravatardefaulturl', new lang_string('gravatardefaulturl', 'admin'), new lang_string('gravatardefaulturl_help', 'admin'), 'mm'));
}
Expand Down
4 changes: 1 addition & 3 deletions admin/webservice/lib.php
Expand Up @@ -29,8 +29,6 @@
* either all the other Moodle users.
*/
class service_user_selector extends user_selector_base {
const MAX_USERS_PER_PAGE = 100;

protected $serviceid;
protected $displayallowedusers; //set to true if the selector displays the
//allowed users on this service
Expand Down Expand Up @@ -85,7 +83,7 @@ public function find_users($search) {

if (!$this->is_validating()) {
$potentialmemberscount = $DB->count_records_sql($countfields . $sql, $params);
if ($potentialmemberscount > service_user_selector::MAX_USERS_PER_PAGE) {
if ($potentialmemberscount > $this->maxusersperpage) {
return $this->too_many_results($search, $potentialmemberscount);
}
}
Expand Down
2 changes: 1 addition & 1 deletion cohort/locallib.php
Expand Up @@ -62,7 +62,7 @@ public function find_users($search) {

if (!$this->is_validating()) {
$potentialmemberscount = $DB->count_records_sql($countfields . $sql, $params);
if ($potentialmemberscount > 100) {
if ($potentialmemberscount > $this->maxusersperpage) {
return $this->too_many_results($search, $potentialmemberscount);
}
}
Expand Down
4 changes: 2 additions & 2 deletions enrol/manual/locallib.php
Expand Up @@ -63,7 +63,7 @@ public function find_users($search) {

if (!$this->is_validating()) {
$potentialmemberscount = $DB->count_records_sql($countfields . $sql, $params);
if ($potentialmemberscount > 100) {
if ($potentialmemberscount > $this->maxusersperpage) {
return $this->too_many_results($search, $potentialmemberscount);
}
}
Expand Down Expand Up @@ -127,7 +127,7 @@ public function find_users($search) {

if (!$this->is_validating()) {
$potentialmemberscount = $DB->count_records_sql($countfields . $sql, $params);
if ($potentialmemberscount > 100) {
if ($potentialmemberscount > $this->maxusersperpage) {
return $this->too_many_results($search, $potentialmemberscount);
}
}
Expand Down
2 changes: 2 additions & 0 deletions lang/en/admin.php
Expand Up @@ -687,6 +687,8 @@
$string['maxbytes'] = 'Maximum uploaded file size';
$string['maxconsecutiveidentchars'] = 'Consecutive identical characters';
$string['maxeditingtime'] = 'Maximum time to edit posts';
$string['maxusersperpage'] = ' Maximum users per page';
$string['configmaxusersperpage'] = 'Maximum number of users displayed within user selector in course, group, cohort, webservice etc.';
$string['mbstringrecommended'] = 'Installing the optional MBSTRING library is highly recommended in order to improve site performance, particularly if your site is supporting non-Latin languages.';
$string['mediapluginavi'] = 'Enable .avi filter';
$string['mediapluginflv'] = 'Enable .flv filter';
Expand Down
4 changes: 1 addition & 3 deletions mod/forum/lib.php
Expand Up @@ -7894,8 +7894,6 @@ protected function get_options() {
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class forum_potential_subscriber_selector extends forum_subscriber_selector_base {
const MAX_USERS_PER_PAGE = 100;

/**
* If set to true EVERYONE in this course is force subscribed to this forum
* @var bool
Expand Down Expand Up @@ -7983,7 +7981,7 @@ public function find_users($search) {
// Check to see if there are too many to show sensibly.
if (!$this->is_validating()) {
$potentialmemberscount = $DB->count_records_sql($countfields . $sql, $params);
if ($potentialmemberscount > self::MAX_USERS_PER_PAGE) {
if ($potentialmemberscount > $this->maxusersperpage) {
return $this->too_many_results($search, $potentialmemberscount);
}
}
Expand Down
10 changes: 7 additions & 3 deletions user/selector/lib.php
Expand Up @@ -77,6 +77,8 @@ abstract class user_selector_base {
array('none', 'moodle')
));

/** @var int this is used to define maximum number of users visible in list */
public $maxusersperpage = 100;

// Public API ==============================================================

Expand Down Expand Up @@ -120,6 +122,10 @@ public function __construct($name, $options = array()) {
$this->preserveselected = $this->initialise_option('userselector_preserveselected', $this->preserveselected);
$this->autoselectunique = $this->initialise_option('userselector_autoselectunique', $this->autoselectunique);
$this->searchanywhere = $this->initialise_option('userselector_searchanywhere', $this->searchanywhere);

if (!empty($CFG->maxusersperpage)) {
$this->maxusersperpage = $CFG->maxusersperpage;
}
}

/**
Expand Down Expand Up @@ -751,8 +757,6 @@ public function find_users($search) {
* Used on the add group members page.
*/
class group_non_members_selector extends groups_user_selector_base {
const MAX_USERS_PER_PAGE = 100;

/**
* An array of user ids populated by find_users() used in print_user_summaries()
*/
Expand Down Expand Up @@ -860,7 +864,7 @@ public function find_users($search) {

if (!$this->is_validating()) {
$potentialmemberscount = $DB->count_records_sql("SELECT COUNT(DISTINCT u.id) $sql", $params);
if ($potentialmemberscount > group_non_members_selector::MAX_USERS_PER_PAGE) {
if ($potentialmemberscount > $this->maxusersperpage) {
return $this->too_many_results($search, $potentialmemberscount);
}
}
Expand Down
2 changes: 1 addition & 1 deletion version.php
Expand Up @@ -29,7 +29,7 @@

defined('MOODLE_INTERNAL') || die();

$version = 2013030800.00; // YYYYMMDD = weekly release date of this DEV branch
$version = 2013031200.00; // YYYYMMDD = weekly release date of this DEV branch
// RR = release increments - 00 in DEV branches
// .XX = incremental changes

Expand Down

0 comments on commit 9a51c3d

Please sign in to comment.