Skip to content
Snippets Groups Projects
Commit 5c9d1a92 authored by catch's avatar catch
Browse files

Issue #2798521 by jamesrward, Manuel Garcia, mikeker, Lendude,...

Issue #2798521 by jamesrward, Manuel Garcia, mikeker, Lendude, przemek_leczycki, aklump, dawehner: Views result summary returns float number when using the mini pager
parent 99a55f04
No related branches found
No related tags found
No related merge requests found
......@@ -47,14 +47,17 @@ public function summaryTitle() {
public function query() {
parent::query();
// Don't query for the next page if we have a pager that has a limited
// amount of pages.
if ($this->getItemsPerPage() > 0 && (empty($this->options['total_pages']) || ($this->getCurrentPage() < $this->options['total_pages']))) {
// Increase the items in the query in order to be able to find out whether
// there is another page.
$limit = $this->view->query->getLimit();
$limit += 1;
$this->view->query->setLimit($limit);
// Only modify the query if we don't want to do a total row count
if (!$this->view->get_total_rows) {
// Don't query for the next page if we have a pager that has a limited
// amount of pages.
if ($this->getItemsPerPage() > 0 && (empty($this->options['total_pages']) || ($this->getCurrentPage() < $this->options['total_pages']))) {
// Increase the items in the query in order to be able to find out
// whether there is another page.
$limit = $this->view->query->getLimit();
$limit += 1;
$this->view->query->setLimit($limit);
}
}
}
......@@ -69,19 +72,16 @@ public function useCountQuery() {
* {@inheritdoc}
*/
public function postExecute(&$result) {
// In query() one more item might have been retrieved than necessary. If so,
// the next link needs to be displayed and the item removed.
if ($this->getItemsPerPage() > 0 && count($result) > $this->getItemsPerPage()) {
array_pop($result);
// Make sure the pager shows the next link by setting the total items to
// the biggest possible number but prevent failing calculations like
// ceil(PHP_INT_MAX) we take PHP_INT_MAX / 2.
$total = PHP_INT_MAX / 2;
// Only modify the result if we didn't do a total row count
if (!$this->view->get_total_rows) {
$this->total_items = $this->getCurrentPage() * $this->getItemsPerPage() + count($result);
// query() checks if we need a next link by setting limit 1 record past
// this page If we got the extra record we need to remove it before we
// render the result.
if ($this->getItemsPerPage() > 0 && count($result) > $this->getItemsPerPage()) {
array_pop($result);
}
}
else {
$total = $this->getCurrentPage() * $this->getItemsPerPage() + count($result);
}
$this->total_items = $total;
}
/**
......
......@@ -70,6 +70,18 @@ public function testMiniPagerRender() {
$this->assertText($this->nodes[18]->label());
$this->assertText($this->nodes[19]->label());
// Test @total value in result summary
$view = Views::getView('test_mini_pager');
$view->setDisplay('page_4');
$this->executeView($view);
$this->assertIdentical($view->get_total_rows, TRUE, 'The query was set to calculate the total number of rows.');
$this->assertEqual(count($this->nodes), $view->total_rows, 'The total row count is equal to the number of nodes.');
$this->drupalGet('test_mini_pager_total', array('query' => array('page' => 1)));
$this->assertText('of ' . count($this->nodes), 'The first page shows the total row count.');
$this->drupalGet('test_mini_pager_total', array('query' => array('page' => 6)));
$this->assertText('of ' . count($this->nodes), 'The last page shows the total row count.');
// Test a mini pager with just one item per page.
$this->drupalGet('test_mini_pager_one');
$this->assertText('››');
......
......@@ -118,3 +118,26 @@ display:
type: mini
options:
items_per_page: 0
page_4:
display_plugin: page
id: page_4
display_title: 'Page 4'
position: 4
display_options:
display_extenders: { }
path: test_mini_pager_total
empty: { }
defaults:
empty: false
header: false
header:
result:
id: result
table: views
field: result
relationship: none
group_type: group
admin_label: ''
empty: false
content: 'Displaying @start - @end of @total'
plugin_id: result
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment