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');
$query = param_variable('query', '');
$offset = param_integer('offset', 0);
$limit = param_integer('limit', 0);
$userlimit = get_account_preference($USER->get('id'), 'viewsperpage');
if ($limit > 0 && $limit != $userlimit) {
$USER->set_account_preference('viewsperpage', $limit);
}
else {
$limit = $userlimit;
}
$limit = user_preferred_limit($limit, 'itemsperpage');
$data = build_grouplist_html($query, $limit, $offset);
......
......@@ -27,13 +27,7 @@ define('SUBSECTIONHEADING', get_field('institution', 'displayname', 'name', $ins
$query = param_variable('query', '');
$offset = param_integer('offset', 0);
$limit = param_integer('limit', 0);
$userlimit = get_account_preference($USER->get('id'), 'viewsperpage');
if ($limit > 0 && $limit != $userlimit) {
$USER->set_account_preference('viewsperpage', $limit);
}
else {
$limit = $userlimit;
}
$limit = user_preferred_limit($limit, 'itemsperpage');
$customthemedefaults = array(
'background' => array('type' => 'color', 'value' => '#530E53'),
......
......@@ -17,7 +17,8 @@ require_once('collection.php');
// offset and limit for pagination
$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);
$owner = null;
$groupid = param_integer('group', 0);
......
......@@ -19,8 +19,8 @@ require_once('collection.php');
// offset and limit for pagination
$offset = param_integer('offset', 0);
$limit = param_integer('limit', 10);
$limit = param_integer('limit', 0);
$limit = user_preferred_limit($limit);
$owner = null;
$groupid = param_integer('group', 0);
$institutionname = param_alphanum('institution', false);
......
......@@ -20,13 +20,7 @@ define('GROUP', param_integer('group'));
$wwwroot = get_config('wwwroot');
$limit = param_integer('limit', 0);
$userlimit = get_account_preference($USER->get('id'), 'viewsperpage');
if ($limit > 0 && $limit != $userlimit) {
$USER->set_account_preference('viewsperpage', $limit);
}
else {
$limit = $userlimit;
}
$limit = user_preferred_limit($limit, 'itemsperpage');
$offset = param_integer('offset', 0);
$sort = param_variable('sort', 'title');
$direction = param_variable('direction', 'asc');
......
......@@ -20,13 +20,7 @@ define('GROUP', param_integer('group'));
$wwwroot = get_config('wwwroot');
$limit = param_integer('limit', 0);
$userlimit = get_account_preference($USER->get('id'), 'viewsperpage');
if ($limit > 0 && $limit != $userlimit) {
$USER->set_account_preference('viewsperpage', $limit);
}
else {
$limit = $userlimit;
}
$limit = user_preferred_limit($limit, 'itemsperpage');
$offset = param_integer('offset', 0);
$sort = param_variable('sort', 'title');
$direction = param_variable('direction', 'asc');
......
......@@ -22,13 +22,7 @@ $wwwroot = get_config('wwwroot');
$needsubdomain = get_config('cleanurlusersubdomains');
$limit = param_integer('limit', 0);
$userlimit = get_account_preference($USER->get('id'), 'viewsperpage');
if ($limit > 0 && $limit != $userlimit) {
$USER->set_account_preference('viewsperpage', $limit);
}
else {
$limit = $userlimit;
}
$limit = user_preferred_limit($limit, 'itemsperpage');
$offset = param_integer('offset', 0);
$sort = param_variable('sort', 'title');
$direction = param_variable('direction', 'asc');
......
......@@ -42,13 +42,7 @@ if (!empty($groupid)) {
$setlimit = true;
$limit = param_integer('limit', 0);
$userlimit = get_account_preference($USER->get('id'), 'viewsperpage');
if ($limit > 0 && $limit != $userlimit) {
$USER->set_account_preference('viewsperpage', $limit);
}
else {
$limit = $userlimit;
}
$limit = user_preferred_limit($limit);
$offset = param_integer('offset', 0);
$data = View::view_search(null, null, (object) array('group' => $group->id), null, $limit, $offset);
......
......@@ -169,6 +169,35 @@ function get_account_preference($userid, $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) {
$langpref = get_account_preference($userid, 'lang');
......@@ -213,6 +242,7 @@ function expected_account_preferences() {
'devicedetection' => 1,
'licensedefault' => '',
'viewsperpage' => 20,
'itemsperpage' => 10,
'orderpagesby' => 'atoz',
);
}
......
......@@ -3713,13 +3713,7 @@ class View {
// Pagination configuration
$setlimit = true;
$limit = param_integer('limit', 0);
$userlimit = get_account_preference($USER->get('id'), 'viewsperpage');
if ($limit > 0 && $limit != $userlimit) {
$USER->set_account_preference('viewsperpage', $limit);
}
else {
$limit = $userlimit;
}
$limit = user_preferred_limit($limit);
$offset = param_integer('offset', 0);
// load default page order from user settings as default and overwrite, if changed
$usersettingorderby = get_account_preference($USER->get('id'), 'orderpagesby');
......
......@@ -18,13 +18,6 @@ define('SECTION_PAGE', 'onlineusers');
$offset = param_integer('offset', 0);
$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);
build_onlinelist_html($data, 'online');
......
......@@ -43,13 +43,7 @@ if (!$can_edit) {
$setlimit = true;
$limit = param_integer('limit', 0);
$userlimit = get_account_preference($USER->get('id'), 'viewsperpage');
if ($limit > 0 && $limit != $userlimit) {
$USER->set_account_preference('viewsperpage', $limit);
}
else {
$limit = $userlimit;
}
$limit = user_preferred_limit($limit);
$offset = param_integer('offset', 0);
$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