mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 22:28:51 +00:00
[ticket/12090] Fix pagination for routes
No clickable "jump to" at the moment, as we can not get the route url by the route name in js yet. Need to find another solution later. PHPBB3-12090
This commit is contained in:
parent
6491477809
commit
275910d8b0
7 changed files with 93 additions and 45 deletions
|
@ -263,6 +263,7 @@ services:
|
||||||
arguments:
|
arguments:
|
||||||
- @template
|
- @template
|
||||||
- @user
|
- @user
|
||||||
|
- @controller.helper
|
||||||
|
|
||||||
path_helper:
|
path_helper:
|
||||||
class: phpbb\path_helper
|
class: phpbb\path_helper
|
||||||
|
|
|
@ -22,11 +22,13 @@ class pagination
|
||||||
*
|
*
|
||||||
* @param \phpbb\template\template $template
|
* @param \phpbb\template\template $template
|
||||||
* @param \phpbb\user $user
|
* @param \phpbb\user $user
|
||||||
|
* @param \phpbb\controller\helper $helper
|
||||||
*/
|
*/
|
||||||
public function __construct(\phpbb\template\template $template, \phpbb\user $user)
|
public function __construct(\phpbb\template\template $template, \phpbb\user $user, \phpbb\controller\helper $helper)
|
||||||
{
|
{
|
||||||
$this->template = $template;
|
$this->template = $template;
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
|
$this->helper = $helper;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -44,9 +46,26 @@ class pagination
|
||||||
*/
|
*/
|
||||||
protected function generate_page_link($base_url, $on_page, $start_name, $per_page)
|
protected function generate_page_link($base_url, $on_page, $start_name, $per_page)
|
||||||
{
|
{
|
||||||
if (strpos($start_name, '%d') !== false)
|
if (!is_string($base_url))
|
||||||
{
|
{
|
||||||
return ($on_page > 1) ? sprintf($base_url, (int) $on_page) : str_replace($start_name, '', $base_url);
|
if (is_array($base_url['routes']))
|
||||||
|
{
|
||||||
|
$route = ($on_page > 1) ? $base_url['routes'][1] : $base_url['routes'][0];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$route = $base_url['routes'];
|
||||||
|
}
|
||||||
|
$params = (isset($base_url['params'])) ? $base_url['params'] : array();
|
||||||
|
$is_amp = (isset($base_url['is_amp'])) ? $base_url['is_amp'] : true;
|
||||||
|
$session_id = (isset($base_url['session_id'])) ? $base_url['session_id'] : false;
|
||||||
|
|
||||||
|
if ($on_page > 1 || !is_array($base_url['routes']))
|
||||||
|
{
|
||||||
|
$params[$start_name] = (int) $on_page;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->helper->route($route, $params, $is_amp, $session_id);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -194,7 +213,8 @@ class pagination
|
||||||
$tpl_prefix = ($tpl_prefix == 'PAGINATION') ? '' : $tpl_prefix . '_';
|
$tpl_prefix = ($tpl_prefix == 'PAGINATION') ? '' : $tpl_prefix . '_';
|
||||||
|
|
||||||
$template_array = array(
|
$template_array = array(
|
||||||
$tpl_prefix . 'BASE_URL' => $base_url,
|
$tpl_prefix . 'BASE_URL' => is_string($base_url) ? $base_url : '',//@todo: Fix this for routes
|
||||||
|
$tpl_prefix . 'START_NAME' => $start_name,
|
||||||
$tpl_prefix . 'PER_PAGE' => $per_page,
|
$tpl_prefix . 'PER_PAGE' => $per_page,
|
||||||
'U_' . $tpl_prefix . 'PREVIOUS_PAGE' => ($on_page != 1) ? $u_previous_page : '',
|
'U_' . $tpl_prefix . 'PREVIOUS_PAGE' => ($on_page != 1) ? $u_previous_page : '',
|
||||||
'U_' . $tpl_prefix . 'NEXT_PAGE' => ($on_page != $total_pages) ? $u_next_page : '',
|
'U_' . $tpl_prefix . 'NEXT_PAGE' => ($on_page != $total_pages) ? $u_next_page : '',
|
||||||
|
|
|
@ -37,17 +37,14 @@ function jumpto(item) {
|
||||||
on_page = item.attr('data-on-page'),
|
on_page = item.attr('data-on-page'),
|
||||||
per_page = item.attr('data-per-page'),
|
per_page = item.attr('data-per-page'),
|
||||||
base_url = item.attr('data-base-url'),
|
base_url = item.attr('data-base-url'),
|
||||||
|
start_name = item.attr('data-start-name'),
|
||||||
page = prompt(jump_page, on_page);
|
page = prompt(jump_page, on_page);
|
||||||
|
|
||||||
if (page !== null && !isNaN(page) && page == Math.floor(page) && page > 0) {
|
if (page !== null && !isNaN(page) && page == Math.floor(page) && page > 0) {
|
||||||
if (base_url.indexOf('%d') === -1) {
|
|
||||||
if (base_url.indexOf('?') === -1) {
|
if (base_url.indexOf('?') === -1) {
|
||||||
document.location.href = base_url + '?start=' + ((page - 1) * per_page);
|
document.location.href = base_url + '?' + start_name + '=' + ((page - 1) * per_page);
|
||||||
} else {
|
} else {
|
||||||
document.location.href = base_url.replace(/&/g, '&') + '&start=' + ((page - 1) * per_page);
|
document.location.href = base_url.replace(/&/g, '&') + '&' + start_name + '=' + ((page - 1) * per_page);
|
||||||
}
|
|
||||||
} else {
|
|
||||||
document.location.href = base_url.replace('%d', page);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
<a href="#" class="pagination-trigger" title="{L_JUMP_TO_PAGE}" data-lang-jump-page="{L_JUMP_PAGE|e('html_attr')}{L_COLON}" data-on-page="{CURRENT_PAGE}" data-per-page="{PER_PAGE}" data-base-url="{BASE_URL|e('html_attr')}">{PAGE_NUMBER}</a> •
|
<!-- IF BASE_URL -->
|
||||||
|
<a href="#" class="pagination-trigger" title="{L_JUMP_TO_PAGE}" data-lang-jump-page="{L_JUMP_PAGE|e('html_attr')}{L_COLON}" data-on-page="{CURRENT_PAGE}" data-per-page="{PER_PAGE}" data-base-url="{BASE_URL|e('html_attr')}" data-base-is-route="{BASE_IS_ROUTE}" data-start-name="{START_NAME}">{PAGE_NUMBER}</a> •
|
||||||
|
<!-- ELSE -->
|
||||||
|
{PAGE_NUMBER} •
|
||||||
|
<!-- ENDIF -->
|
||||||
<ul>
|
<ul>
|
||||||
<!-- BEGIN pagination -->
|
<!-- BEGIN pagination -->
|
||||||
<!-- IF pagination.S_IS_PREV -->
|
<!-- IF pagination.S_IS_PREV -->
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<!-- IF .pagination -->
|
<!-- IF .pagination -->
|
||||||
<b><a href="#" onclick="jumpto(); return false;" title="{L_JUMP_TO_PAGE}">{L_GOTO_PAGE}</a>
|
<!-- IF BASE_URL --><b><a href="#" onclick="jumpto(); return false;" title="{L_JUMP_TO_PAGE}">{L_GOTO_PAGE}</a></b><!-- ENDIF -->
|
||||||
<!-- BEGIN pagination -->
|
<!-- BEGIN pagination -->
|
||||||
<!-- IF pagination.S_IS_PREV --><a href="{pagination.PAGE_URL}">{L_PREVIOUS}</a>
|
<!-- IF pagination.S_IS_PREV --><a href="{pagination.PAGE_URL}">{L_PREVIOUS}</a>
|
||||||
<!-- ELSEIF pagination.S_IS_CURRENT --><strong>{pagination.PAGE_NUMBER}</strong>
|
<!-- ELSEIF pagination.S_IS_CURRENT --><strong>{pagination.PAGE_NUMBER}</strong>
|
||||||
|
|
6
tests/pagination/config/routing.yml
Normal file
6
tests/pagination/config/routing.yml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
core_controller:
|
||||||
|
pattern: /test
|
||||||
|
defaults: { _controller: core_foo.controller:bar, page: 1}
|
||||||
|
core_page_controller:
|
||||||
|
pattern: /test/page/{page}
|
||||||
|
defaults: { _controller: core_foo.controller:bar}
|
|
@ -21,11 +21,25 @@ class phpbb_pagination_pagination_test extends phpbb_template_template_test_case
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$user = $this->getMock('\phpbb\user');
|
|
||||||
$user->expects($this->any())
|
global $phpbb_dispatcher;
|
||||||
|
|
||||||
|
$phpbb_dispatcher = new phpbb_mock_event_dispatcher;
|
||||||
|
$this->user = $this->getMock('\phpbb\user');
|
||||||
|
$this->user->expects($this->any())
|
||||||
->method('lang')
|
->method('lang')
|
||||||
->will($this->returnCallback(array($this, 'return_callback_implode')));
|
->will($this->returnCallback(array($this, 'return_callback_implode')));
|
||||||
$this->pagination = new \phpbb\pagination($this->template, $user);
|
|
||||||
|
$this->finder = new \phpbb\extension\finder(
|
||||||
|
new phpbb_mock_extension_manager(dirname(__FILE__) . '/', array()),
|
||||||
|
new \phpbb\filesystem(),
|
||||||
|
dirname(__FILE__) . '/',
|
||||||
|
new phpbb_mock_cache()
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '1'));
|
||||||
|
$this->helper = new \phpbb\controller\helper($this->finder, $this->template, $this->user, $this->config, dirname(__FILE__) . '/', 'php');
|
||||||
|
$this->pagination = new \phpbb\pagination($this->template, $this->user, $this->helper);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function generate_template_pagination_data()
|
public function generate_template_pagination_data()
|
||||||
|
@ -77,49 +91,55 @@ class phpbb_pagination_pagination_test extends phpbb_template_template_test_case
|
||||||
:u_next:page.php?start=30',
|
:u_next:page.php?start=30',
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'test/page/%d',
|
array('routes' => array(
|
||||||
'/page/%d',
|
'core_controller',
|
||||||
|
'core_page_controller',
|
||||||
|
)),
|
||||||
|
'page',
|
||||||
95,
|
95,
|
||||||
10,
|
10,
|
||||||
10,
|
10,
|
||||||
'pagination
|
'pagination
|
||||||
:per_page:10
|
:per_page:10
|
||||||
:current_page:2
|
:current_page:2
|
||||||
:base_url:test/page/%d
|
:base_url:
|
||||||
:previous::test
|
:previous::' . dirname(__FILE__) . '/' . 'test
|
||||||
:else:1:test
|
:else:1:' . dirname(__FILE__) . '/' . 'test
|
||||||
:current:2:test/page/2
|
:current:2:' . dirname(__FILE__) . '/' . 'test/page/2
|
||||||
:else:3:test/page/3
|
:else:3:' . dirname(__FILE__) . '/' . 'test/page/3
|
||||||
:else:4:test/page/4
|
:else:4:' . dirname(__FILE__) . '/' . 'test/page/4
|
||||||
:else:5:test/page/5
|
:else:5:' . dirname(__FILE__) . '/' . 'test/page/5
|
||||||
:ellipsis:9:test/page/9
|
:ellipsis:9:' . dirname(__FILE__) . '/' . 'test/page/9
|
||||||
:else:10:test/page/10
|
:else:10:' . dirname(__FILE__) . '/' . 'test/page/10
|
||||||
:next::test/page/3
|
:next::' . dirname(__FILE__) . '/' . 'test/page/3
|
||||||
:u_prev:test
|
:u_prev:' . dirname(__FILE__) . '/' . 'test
|
||||||
:u_next:test/page/3',
|
:u_next:' . dirname(__FILE__) . '/' . 'test/page/3',
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'test/page/%d',
|
array('routes' => array(
|
||||||
'/page/%d',
|
'core_controller',
|
||||||
|
'core_page_controller',
|
||||||
|
)),
|
||||||
|
'page',
|
||||||
95,
|
95,
|
||||||
10,
|
10,
|
||||||
20,
|
20,
|
||||||
'pagination
|
'pagination
|
||||||
:per_page:10
|
:per_page:10
|
||||||
:current_page:3
|
:current_page:3
|
||||||
:base_url:test/page/%d
|
:base_url:
|
||||||
:previous::test/page/2
|
:previous::' . dirname(__FILE__) . '/' . 'test/page/2
|
||||||
:else:1:test
|
:else:1:' . dirname(__FILE__) . '/' . 'test
|
||||||
:else:2:test/page/2
|
:else:2:' . dirname(__FILE__) . '/' . 'test/page/2
|
||||||
:current:3:test/page/3
|
:current:3:' . dirname(__FILE__) . '/' . 'test/page/3
|
||||||
:else:4:test/page/4
|
:else:4:' . dirname(__FILE__) . '/' . 'test/page/4
|
||||||
:else:5:test/page/5
|
:else:5:' . dirname(__FILE__) . '/' . 'test/page/5
|
||||||
:else:6:test/page/6
|
:else:6:' . dirname(__FILE__) . '/' . 'test/page/6
|
||||||
:ellipsis:9:test/page/9
|
:ellipsis:9:' . dirname(__FILE__) . '/' . 'test/page/9
|
||||||
:else:10:test/page/10
|
:else:10:' . dirname(__FILE__) . '/' . 'test/page/10
|
||||||
:next::test/page/4
|
:next::' . dirname(__FILE__) . '/' . 'test/page/4
|
||||||
:u_prev:test/page/2
|
:u_prev:' . dirname(__FILE__) . '/' . 'test/page/2
|
||||||
:u_next:test/page/4',
|
:u_next:' . dirname(__FILE__) . '/' . 'test/page/4',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue