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