5
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
10
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17
* This software consists of voluntary contributions made by many individuals
18
* and is licensed under the LGPL. For more information, see
19
* <http://www.phpdoctrine.org>.
23
* Doctrine_Pager_Range_Jumping
25
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
28
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
30
* @link www.phpdoctrine.org
33
class Doctrine_Pager_Range_Jumping extends Doctrine_Pager_Range
36
* @var int $_chunkLength Chunk length to be returned
38
private $_chunkLength;
44
* Initialize Doctrine_Pager_Range_Jumping and does custom assignments
48
protected function _initialize()
50
if (isset($this->_options['chunk'])) {
51
$this->_setChunkLength($this->_options['chunk']);
53
throw new Doctrine_Pager_Exception('Missing parameter \'chunk\' that must be define in options.');
61
* Returns the size of the chunk defined
63
* @return int Chunk length
65
public function getChunkLength()
67
return $this->_chunkLength;
74
* Defines the size of the chunk
76
* @param $chunkLength Chunk length
79
protected function _setChunkLength($chunkLength)
81
$this->_chunkLength = $chunkLength;
88
* Calculate and returns an array representing the range around the current page
92
public function rangeAroundPage()
94
$pager = $this->getPager();
96
if ($pager->getExecuted()) {
97
$page = $pager->getPage();
99
// Define initial assignments for StartPage and EndPage
100
$startPage = $page - ($page - 1) % $this->getChunkLength();
101
$endPage = ($startPage + $this->getChunkLength()) - 1;
103
// Check for EndPage out-range
104
if ($endPage > $pager->getLastPage()) {
105
$endPage = $pager->getLastPage();
108
// No need to check for out-range in start, it will never happens
110
return range($startPage, $endPage);
113
throw new Doctrine_Pager_Exception(
114
'Cannot retrieve the range around the page of a not yet executed Pager query'