Issues

ZF-7020: Zend_Paginator_ScrollingStyle_Elastic is only "elastic" near first pages, but not near last pages

Description

When using Zend_Paginator_ScrollingStyle_Elastic e. g. with a pageRange of 3 and a number of 10 pages, the following page links are generated:

page 1: [1] 2 3

page 2: 1 [2] 3 4

page 3: 1 2 [3] 4 5

[...]

page 8: 6 7 [8] 9 10

page 9: 6 7 8 [9] 10 (should be 7 8 [9] 10)

page 10: 6 7 8 9 [10] (should be 8 9 [10])

This is easy to fix:


    public function getPages(Zend_Paginator $paginator, $pageRange = null)
    {
        $pageRange  = $paginator->getPageRange();
        $pageNumber = $paginator->getCurrentPageNumber();

        $originalPageRange = $pageRange;
        $pageRange         = $pageRange * 2 - 1;

        if ($originalPageRange + $pageNumber - 1 < $pageRange) {
            $pageRange = $originalPageRange + $pageNumber - 1;
        }

        // start bugfix
        elseif ($originalPageRange + $pageNumber - 1 > count($paginator)) {
            $pageRange = $originalPageRange + count($paginator) - $pageNumber;
        }
        // end bugfix

        return parent::getPages($paginator, $pageRange);
    }

Comments

Set Issue Type from "Improvement" to "Bug"

Closing this issue as not an issue. For an example of an elastic scrollingstyle, see Google's pagination.

Yes, I know Google's pagination. And it works just the way I'd like Zend_Paginator_ScrollingStyle_Elastic to work - but it doesn't.

Google shows you 10 items before the actual page and 9 behind it when being in the middle of the result set. At the end of the result set it shows 10 items before the actual (last) page. Zend_Paginator_ScrollingStyle_Elastic shows 18 items before the actual page when being at the end of the result set at a PageRange of 10 (or 20 at a PageRange of 11 - unlike Google it always shows the same number of items before and after the actual page when being in the middle of the result set).

Maybe you'd like to test it yourself...

Also, maybe you'd like to ask yourself why there is a correction algorithm for the first pages:


        if ($originalPageRange + $pageNumber - 1 < $pageRange) {
            $pageRange = $originalPageRange + $pageNumber - 1;
        }

but not for the last pages...

I asked myself... the answer was that either Matthew or myself put it there in our free time while we contributed to this framework for free.

I double checked Google's behavior. It does some weird things with larger resultsets, so it doesn't completely act like your example does. On smaller resultsets it does do what you describe. Reopening issue.

{quote} I asked myself... the answer was that either Matthew or myself put it there in our free time while we contributed to this framework for free. {quote}

Well, I respect what you are doing, but what has this to do with the issue I described? I reported a bug - this is what the issue tracker is for. You implicitly told me that I was too dumb to recognize an elastic scrolling style when I see one, and I just asked you to take a closer look at it. No need to be huffy...

{quote} It does some weird things with larger resultsets {quote}

That's indeed true. :-) But if you somehow manage to get to the end of the result set, the number of items before the actual page is correct (at least during my tests).

The scrolling behavior mimicked Google for my test set of queries when the component was released. It may be that my test set was not complete, however.

Resolved in r18552. Merged to release-1.9 in r18553