Commit 40eed097 authored by Richard Mansfield's avatar Richard Mansfield Committed by Gerrit Code Review
Browse files

Merge changes I7bf296a1,I0e697596

* changes:
  Pagination changes
  lib/web.php: Changes to build_pagination()
parents 0ed68e00 634b54dc
......@@ -143,6 +143,8 @@ $pagination = build_pagination(array(
'count' => $groups['count'],
'limit' => $groupsperpage,
'offset' => $offset,
'jumplinks' => 6,
'numbersincludeprevnext' => 2,
'resultcounttextsingular' => get_string('group', 'group'),
'resultcounttextplural' => get_string('groups', 'group'),
));
......
......@@ -88,6 +88,8 @@ $pagination = build_pagination(array(
'count' => $results['count'],
'limit' => $groupsperpage,
'offset' => $offset,
'jumplinks' => 6,
'numbersincludeprevnext' => 2,
'resultcounttextsingular' => get_string('group', 'group'),
'resultcounttextplural' => get_string('groups', 'group'),
));
......
......@@ -224,6 +224,8 @@ $pagination = build_pagination(array(
'count' => $forum->topiccount,
'limit' => $topicsperpage,
'offset' => $offset,
'jumplinks' => 6,
'numbersincludeprevnext' => 2,
'resultcounttextsingular' => get_string('topiclower', 'interaction.forum'),
'resultcounttextplural' => get_string('topicslower', 'interaction.forum')
));
......
......@@ -1098,6 +1098,8 @@ function activitylist_html($type='all', $limit=10, $offset=0) {
'count' => $count,
'limit' => $limit,
'offset' => $offset,
'jumplinks' => 6,
'numbersincludeprevnext' => 2,
));
$result = array(
......
......@@ -1168,6 +1168,8 @@ function build_grouplist_html($query, $limit, $offset, &$count=null) {
'count' => $count,
'limit' => $limit,
'offset' => $offset,
'jumplinks' => 6,
'numbersincludeprevnext' => 2,
'resultcounttextsingular' => get_string('group', 'group'),
'resultcounttextplural' => get_string('groups', 'group'),
));
......@@ -1238,6 +1240,8 @@ function group_get_membersearch_data($results, $group, $query, $membershiptype)
'count' => $results['count'],
'limit' => $results['limit'],
'offset' => $results['offset'],
'jumplinks' => 8,
'numbersincludeprevnext' => 2,
'datatable' => 'membersearchresults',
'jsonscript' => 'group/membersearchresults.json.php',
'firsttext' => '',
......
......@@ -761,6 +761,7 @@ function build_institutions_html($filter, $showdefault, $query, $limit, $offset,
'count' => $count,
'limit' => $limit,
'offset' => $offset,
'jumplinks' => 4,
'resultcounttextsingular' => get_string('institution', 'admin'),
'resultcounttextplural' => get_string('institutions', 'admin'),
));
......
......@@ -2723,6 +2723,8 @@ function build_portfolio_search_html(&$data) {
'count' => $data->count,
'limit' => $data->limit,
'offset' => $data->offset,
'jumplinks' => 6,
'numbersincludeprevnext' => 2,
'numbersincludefirstlast' => false,
'resultcounttextsingular' => get_string('result'),
'resultcounttextplural' => get_string('results'),
......
......@@ -282,6 +282,8 @@ function build_admin_user_search_results($search, $offset, $limit) {
'url' => $searchurl,
'count' => $results['count'],
'limit' => $limit,
'jumplinks' => 8,
'numbersincludeprevnext' => 2,
'offset' => $offset,
'datatable' => 'searchresults',
'jsonscript' => 'admin/users/search.json.php',
......
......@@ -1575,6 +1575,8 @@ function build_userlist_html(&$data, $page, $admingroups) {
'count' => $data['count'],
'limit' => $data['limit'],
'offset' => $data['offset'],
'jumplinks' => 6,
'numbersincludeprevnext' => 2,
'resultcounttextsingular' => $resultcounttextsingular,
'resultcounttextplural' => $resultcounttextplural,
'extradata' => array('page' => $page),
......
......@@ -2550,6 +2550,8 @@ class View {
'count' => $data->count,
'limit' => $limit,
'offset' => $offset,
'jumplinks' => 6,
'numbersincludeprevnext' => 2,
));
return array($searchform, $data, $pagination);
......@@ -3294,6 +3296,8 @@ class View {
'count' => $results->count,
'limit' => $search->limit,
'offset' => $search->offset,
'jumplinks' => 6,
'numbersincludeprevnext' => 2,
'offsetname' => 'viewoffset',
'firsttext' => '',
'previoustext' => '',
......
......@@ -2933,6 +2933,10 @@ function str_shorten_text($str, $maxlen=100, $truncate=false) {
* - lasttext: The text to use for the 'last page' link
* - numbersincludefirstlast: Whether the page numbering should include links
* for the first and last pages
* - numbersincludeprevnext: The number of pagelinks, adjacent the the current page,
* to include per side
* - jumplinks: The maximum number of page jump links to have between first- and current-,
and current- and last page
* - resultcounttextsingular: The text to use for 'result'
* - resultcounttextplural: The text to use for 'results'
*
......@@ -2986,7 +2990,10 @@ function build_pagination($params) {
$params['numbersincludefirstlast'] = true;
}
if (!isset($params['numbersincludeprevnext'])) {
$params['numbersincludeprevnext'] = true;
$params['numbersincludeprevnext'] = 1;
}
else {
$params['numbersincludeprevnext'] = (int) $params['numbersincludeprevnext'];
}
if (!isset($params['extradata'])) {
......@@ -3008,8 +3015,8 @@ function build_pagination($params) {
if (!empty($params['lastpage'])) {
$page = $last;
}
$next = min($last, $page + 1);
$prev = max(0, $page - 1);
$next = min($last, $page + 1);
// Build a list of what pagenumbers will be put between the previous/next links
$pagenumbers = array();
......@@ -3019,44 +3026,58 @@ function build_pagination($params) {
$pagenumbers[] = 0;
}
$maxjumplinks = 8;
$betweenpages = $pages - 2; // pages between first and last page
$maxjumplinks = isset($params['jumplinks']) ? (int) $params['jumplinks'] : 0;
// Pages between first page and current page
$betweencount = $prev;
$jumplinks = $betweenpages ? $maxjumplinks * ($betweencount / $betweenpages) : 0;
$jumpcount = $jumplinks ? $betweencount / $jumplinks : 0;
$jumpcount = $jumpcount < $jumplinks ? $jumplinks : $jumpcount;
// Jump pages between first page and current page
$betweencount = $page;
$jumplinks = $pages ? round($maxjumplinks * ($betweencount / $pages)) : 0;
$jumpcount = $jumplinks ? round($betweencount / ($jumplinks + 1)) : 0;
$gapcount = 1;
for ($bc = 0; $bc < $betweencount; $bc++) {
if ($gapcount > $jumpcount) {
$pagenumbers[] = $bc;
$gapcount = 0;
if ($jumpcount > 1) {
for ($bc = 1; $bc < $betweencount; $bc++) {
if ($gapcount > $jumpcount) {
$pagenumbers[] = $bc;
$gapcount = 1;
}
$gapcount++;
}
$gapcount++;
}
// Current page with adjacent prev and next pages
if ($params['numbersincludeprevnext']) {
$pagenumbers[] = $prev;
if ($params['numbersincludeprevnext'] > 0) {
for ($i=$params['numbersincludeprevnext']; $i > 0; $i--) {
$prevlink = $page - $i;
if ($prevlink < 0) {
break;
}
$pagenumbers[] = $prevlink;
}
unset($prevlink);
}
$pagenumbers[] = $page;
if ($params['numbersincludeprevnext']) {
$pagenumbers[] = $next;
if ($params['numbersincludeprevnext'] > 0) {
for ($i = 1; $i <= $params['numbersincludeprevnext']; $i++) {
$nextlink = $page + $i;
if ($nextlink > $last) {
break;
}
$pagenumbers[] = $nextlink;
}
}
// Pages between current and last
$betweencount = $last - $next;
$jumplinks = $betweenpages ? $maxjumplinks * ($betweencount / $betweenpages) : 0;
$jumpcount = $jumplinks ? $betweencount / $jumplinks : 0;
$jumpcount = $jumpcount < $jumplinks ? $jumplinks : $jumpcount;
// Jump pages between current and last
$betweencount = $pages - $page;
$jumplinks = $pages ? round($maxjumplinks * ($betweencount / $pages)) : 0;
$jumpcount = $jumplinks ? round($betweencount / ($jumplinks + 1)) : 0;
$gapcount = 1;
for ($bc = $next; $bc < $last; $bc++) {
if ($gapcount > $jumpcount) {
$pagenumbers[] = $bc;
$gapcount = 0;
if ($jumpcount > 1) {
for ($bc = $page; $bc < $last; $bc++) {
if ($gapcount > $jumpcount) {
$pagenumbers[] = $bc;
$gapcount = 1;
}
$gapcount++;
}
$gapcount++;
}
// Last page
......@@ -3064,6 +3085,7 @@ function build_pagination($params) {
$pagenumbers[] = $last;
}
$pagenumbers = array_unique($pagenumbers);
sort($pagenumbers);
// Build the first/previous links
$isfirst = $page == 0;
......
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