ZF-8072: Add getItemsByPageRange function

Description

My use case for this function is I was displaying a large dataset on a page using Zend_Paginator, but wanted the capability to export a page range as CSV. Here is the class I wrote that extends Zend_Paginator:


class My_Paginator extends Zend_Paginator
{
    /**
     * Returns the items for a given page range.
     *
     * @return Traversable
     */
    public function getItemsByPageRange($startPageNumber, $endPageNumber)
    {
        $startPageNumber = $this->normalizePageNumber($startPageNumber);
        $endPageNumber = $this->normalizePageNumber($endPageNumber);
        
        if ($startPageNumber >= $endPageNumber) {
            return $this->getItemsByPage($startPageNumber);
        }
        
    $offset = ($startPageNumber - 1) * $this->_itemCountPerPage;
        
    $itemCountPerPage = (($endPageNumber + 1) - $startPageNumber) * $this->_itemCountPerPage;
        
        $items = $this->_adapter->getItems($offset, $itemCountPerPage);

        $chunks = array_chunk($items, $this->_itemCountPerPage);
        
        for ($i=$startPageNumber; $i<$endPageNumber; $i++) {
            $chunk = each($chunks);
            if (!$chunk instanceof Traversable) {
                $chunk = new ArrayIterator($chunk);
            }
            $this->_pageItems[$i] = $chunk;
        }
        
        if (!$items instanceof Traversable) {
            $items = new ArrayIterator($items);
        }
        
        return $items;
    }
}

Comments

Bulk change of all issues last updated before 1st January 2010 as "Won't Fix".

Feel free to re-open and provide a patch if you want to fix this issue.