Commit 8127b5b0 authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review

Merge "Bug 1531610: Sorting out where viewsperpage should be used" into 16.04_STABLE

parents c272a9e1 3f24446a
...@@ -23,13 +23,7 @@ require_once('searchlib.php'); ...@@ -23,13 +23,7 @@ require_once('searchlib.php');
$query = param_variable('query', ''); $query = param_variable('query', '');
$offset = param_integer('offset', 0); $offset = param_integer('offset', 0);
$limit = param_integer('limit', 0); $limit = param_integer('limit', 0);
$userlimit = get_account_preference($USER->get('id'), 'viewsperpage'); $limit = user_preferred_limit($limit, 'itemsperpage');
if ($limit > 0 && $limit != $userlimit) {
$USER->set_account_preference('viewsperpage', $limit);
}
else {
$limit = $userlimit;
}
$data = build_grouplist_html($query, $limit, $offset); $data = build_grouplist_html($query, $limit, $offset);
......
...@@ -27,13 +27,7 @@ define('SUBSECTIONHEADING', get_field('institution', 'displayname', 'name', $ins ...@@ -27,13 +27,7 @@ define('SUBSECTIONHEADING', get_field('institution', 'displayname', 'name', $ins
$query = param_variable('query', ''); $query = param_variable('query', '');
$offset = param_integer('offset', 0); $offset = param_integer('offset', 0);
$limit = param_integer('limit', 0); $limit = param_integer('limit', 0);
$userlimit = get_account_preference($USER->get('id'), 'viewsperpage'); $limit = user_preferred_limit($limit, 'itemsperpage');
if ($limit > 0 && $limit != $userlimit) {
$USER->set_account_preference('viewsperpage', $limit);
}
else {
$limit = $userlimit;
}
$customthemedefaults = array( $customthemedefaults = array(
'background' => array('type' => 'color', 'value' => '#530E53'), 'background' => array('type' => 'color', 'value' => '#530E53'),
......
...@@ -17,7 +17,8 @@ require_once('collection.php'); ...@@ -17,7 +17,8 @@ require_once('collection.php');
// offset and limit for pagination // offset and limit for pagination
$offset = param_integer('offset', 0); $offset = param_integer('offset', 0);
$limit = param_integer('limit', 10); $limit = param_integer('limit', 0);
$limit = user_preferred_limit($limit);
$setlimit = param_boolean('setlimit', false); $setlimit = param_boolean('setlimit', false);
$owner = null; $owner = null;
$groupid = param_integer('group', 0); $groupid = param_integer('group', 0);
......
...@@ -19,8 +19,8 @@ require_once('collection.php'); ...@@ -19,8 +19,8 @@ require_once('collection.php');
// offset and limit for pagination // offset and limit for pagination
$offset = param_integer('offset', 0); $offset = param_integer('offset', 0);
$limit = param_integer('limit', 10); $limit = param_integer('limit', 0);
$limit = user_preferred_limit($limit);
$owner = null; $owner = null;
$groupid = param_integer('group', 0); $groupid = param_integer('group', 0);
$institutionname = param_alphanum('institution', false); $institutionname = param_alphanum('institution', false);
......
...@@ -20,13 +20,7 @@ define('GROUP', param_integer('group')); ...@@ -20,13 +20,7 @@ define('GROUP', param_integer('group'));
$wwwroot = get_config('wwwroot'); $wwwroot = get_config('wwwroot');
$limit = param_integer('limit', 0); $limit = param_integer('limit', 0);
$userlimit = get_account_preference($USER->get('id'), 'viewsperpage'); $limit = user_preferred_limit($limit, 'itemsperpage');
if ($limit > 0 && $limit != $userlimit) {
$USER->set_account_preference('viewsperpage', $limit);
}
else {
$limit = $userlimit;
}
$offset = param_integer('offset', 0); $offset = param_integer('offset', 0);
$sort = param_variable('sort', 'title'); $sort = param_variable('sort', 'title');
$direction = param_variable('direction', 'asc'); $direction = param_variable('direction', 'asc');
......
...@@ -20,13 +20,7 @@ define('GROUP', param_integer('group')); ...@@ -20,13 +20,7 @@ define('GROUP', param_integer('group'));
$wwwroot = get_config('wwwroot'); $wwwroot = get_config('wwwroot');
$limit = param_integer('limit', 0); $limit = param_integer('limit', 0);
$userlimit = get_account_preference($USER->get('id'), 'viewsperpage'); $limit = user_preferred_limit($limit, 'itemsperpage');
if ($limit > 0 && $limit != $userlimit) {
$USER->set_account_preference('viewsperpage', $limit);
}
else {
$limit = $userlimit;
}
$offset = param_integer('offset', 0); $offset = param_integer('offset', 0);
$sort = param_variable('sort', 'title'); $sort = param_variable('sort', 'title');
$direction = param_variable('direction', 'asc'); $direction = param_variable('direction', 'asc');
......
...@@ -22,13 +22,7 @@ $wwwroot = get_config('wwwroot'); ...@@ -22,13 +22,7 @@ $wwwroot = get_config('wwwroot');
$needsubdomain = get_config('cleanurlusersubdomains'); $needsubdomain = get_config('cleanurlusersubdomains');
$limit = param_integer('limit', 0); $limit = param_integer('limit', 0);
$userlimit = get_account_preference($USER->get('id'), 'viewsperpage'); $limit = user_preferred_limit($limit, 'itemsperpage');
if ($limit > 0 && $limit != $userlimit) {
$USER->set_account_preference('viewsperpage', $limit);
}
else {
$limit = $userlimit;
}
$offset = param_integer('offset', 0); $offset = param_integer('offset', 0);
$sort = param_variable('sort', 'title'); $sort = param_variable('sort', 'title');
$direction = param_variable('direction', 'asc'); $direction = param_variable('direction', 'asc');
......
...@@ -42,13 +42,7 @@ if (!empty($groupid)) { ...@@ -42,13 +42,7 @@ if (!empty($groupid)) {
$setlimit = true; $setlimit = true;
$limit = param_integer('limit', 0); $limit = param_integer('limit', 0);
$userlimit = get_account_preference($USER->get('id'), 'viewsperpage'); $limit = user_preferred_limit($limit);
if ($limit > 0 && $limit != $userlimit) {
$USER->set_account_preference('viewsperpage', $limit);
}
else {
$limit = $userlimit;
}
$offset = param_integer('offset', 0); $offset = param_integer('offset', 0);
$data = View::view_search(null, null, (object) array('group' => $group->id), null, $limit, $offset); $data = View::view_search(null, null, (object) array('group' => $group->id), null, $limit, $offset);
......
...@@ -169,6 +169,35 @@ function get_account_preference($userid, $field) { ...@@ -169,6 +169,35 @@ function get_account_preference($userid, $field) {
return $expected[$field]; return $expected[$field];
} }
/**
* Returns the user preferred limit if there is one
*
* @param int $limit
* @param string $field The account preference to check. To allow for having more than one limit
* for different parts of the system.
* @param mixed $userid Can be user object or id. If left blank then current $USER id will be used
*
* @return int $limit
*/
function user_preferred_limit($limit, $field = 'viewsperpage', $userid = null) {
global $USER;
if ($userid instanceof User) {
$userid = $userid->id;
}
else if ($userid === null) {
$userid = $USER->get('id');
}
$userlimit = get_account_preference($userid, $field);
if ($limit > 0 && $limit != $userlimit) {
set_account_preference($userid, $field, $limit);
}
else {
$limit = $userlimit;
}
return $limit;
}
function get_user_language($userid) { function get_user_language($userid) {
$langpref = get_account_preference($userid, 'lang'); $langpref = get_account_preference($userid, 'lang');
...@@ -213,6 +242,7 @@ function expected_account_preferences() { ...@@ -213,6 +242,7 @@ function expected_account_preferences() {
'devicedetection' => 1, 'devicedetection' => 1,
'licensedefault' => '', 'licensedefault' => '',
'viewsperpage' => 20, 'viewsperpage' => 20,
'itemsperpage' => 10,
'orderpagesby' => 'atoz', 'orderpagesby' => 'atoz',
); );
} }
......
...@@ -3713,13 +3713,7 @@ class View { ...@@ -3713,13 +3713,7 @@ class View {
// Pagination configuration // Pagination configuration
$setlimit = true; $setlimit = true;
$limit = param_integer('limit', 0); $limit = param_integer('limit', 0);
$userlimit = get_account_preference($USER->get('id'), 'viewsperpage'); $limit = user_preferred_limit($limit);
if ($limit > 0 && $limit != $userlimit) {
$USER->set_account_preference('viewsperpage', $limit);
}
else {
$limit = $userlimit;
}
$offset = param_integer('offset', 0); $offset = param_integer('offset', 0);
// load default page order from user settings as default and overwrite, if changed // load default page order from user settings as default and overwrite, if changed
$usersettingorderby = get_account_preference($USER->get('id'), 'orderpagesby'); $usersettingorderby = get_account_preference($USER->get('id'), 'orderpagesby');
......
...@@ -18,13 +18,6 @@ define('SECTION_PAGE', 'onlineusers'); ...@@ -18,13 +18,6 @@ define('SECTION_PAGE', 'onlineusers');
$offset = param_integer('offset', 0); $offset = param_integer('offset', 0);
$limit = param_integer('limit', 10); $limit = param_integer('limit', 10);
$userlimit = get_account_preference($USER->get('id'), 'viewsperpage');
if ($limit > 0 && $limit != $userlimit) {
$USER->set_account_preference('viewsperpage', $limit);
}
else {
$limit = $userlimit;
}
$data = get_onlineusers($limit, $offset); $data = get_onlineusers($limit, $offset);
build_onlinelist_html($data, 'online'); build_onlinelist_html($data, 'online');
......
...@@ -43,13 +43,7 @@ if (!$can_edit) { ...@@ -43,13 +43,7 @@ if (!$can_edit) {
$setlimit = true; $setlimit = true;
$limit = param_integer('limit', 0); $limit = param_integer('limit', 0);
$userlimit = get_account_preference($USER->get('id'), 'viewsperpage'); $limit = user_preferred_limit($limit);
if ($limit > 0 && $limit != $userlimit) {
$USER->set_account_preference('viewsperpage', $limit);
}
else {
$limit = $userlimit;
}
$offset = param_integer('offset', 0); $offset = param_integer('offset', 0);
$data = View::view_search(null, null, (object) array('group' => $group->id), null, $limit, $offset); $data = View::view_search(null, null, (object) array('group' => $group->id), null, $limit, $offset);
......
Markdown is supported
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