├── MakerLabsPagerBundle.php ├── README.md ├── Resources ├── public │ └── css │ │ ├── clean.css │ │ └── round.css ├── views │ └── Pager │ │ ├── paginate.html.twig │ │ └── paginate.html.php └── config │ └── services.xml ├── Adapter ├── PagerAdapterInterface.php ├── ArrayAdapter.php └── DoctrineOrmAdapter.php ├── DependencyInjection ├── Configuration.php └── MakerLabsPagerExtension.php ├── LICENSE ├── Tests ├── Adapter │ └── ArrayAdapterTest.php └── PagerTest.php ├── Twig └── Extension │ └── PagerExtension.php ├── Templating └── Helper │ └── PagerHelper.php └── Pager.php /MakerLabsPagerBundle.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace MakerLabs\PagerBundle\Adapter; 13 | 14 | /** 15 | * Pager adapter interface 16 | * 17 | * @author Marcin Butlak 18 | */ 19 | interface PagerAdapterInterface extends \Countable 20 | { 21 | /** 22 | * Returns the list of results 23 | * 24 | * @return array 25 | */ 26 | function getResults($offset, $limit); 27 | } 28 | -------------------------------------------------------------------------------- /Resources/public/css/round.css: -------------------------------------------------------------------------------- 1 | .pager 2 | { 3 | list-style: none; 4 | 5 | margin: 0px; 6 | 7 | padding: 0px; 8 | } 9 | 10 | .pager:after 11 | { 12 | content: "."; 13 | display: block; 14 | height: 0; 15 | clear: left; 16 | visibility: hidden; 17 | } 18 | 19 | .pager li 20 | { 21 | float: left; 22 | 23 | padding: 0px; 24 | 25 | margin-right: 5px; 26 | } 27 | 28 | .pager a, 29 | .pager b 30 | { 31 | color: #fff; 32 | 33 | display: block; 34 | 35 | padding: 5px; 36 | 37 | text-decoration: none; 38 | 39 | font-weight: normal; 40 | 41 | background-color: #ccc; 42 | 43 | border: 1px solid #aaa; 44 | 45 | border-radius: 5px; 46 | } 47 | 48 | .pager a:hover, 49 | .pager b 50 | { 51 | background-color: #ff9346; 52 | } -------------------------------------------------------------------------------- /Resources/views/Pager/paginate.html.twig: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /DependencyInjection/Configuration.php: -------------------------------------------------------------------------------- 1 | root('maker_labs_pager'); 22 | 23 | // Here you should define the parameters that are allowed to 24 | // configure your bundle. See the documentation linked above for 25 | // more information on that topic. 26 | 27 | return $treeBuilder; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /DependencyInjection/MakerLabsPagerExtension.php: -------------------------------------------------------------------------------- 1 | processConfiguration($configuration, $configs); 24 | 25 | $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); 26 | $loader->load('services.xml'); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011,2012 Marcin Butlak 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is furnished 8 | to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /Tests/Adapter/ArrayAdapterTest.php: -------------------------------------------------------------------------------- 1 | array = array('one', 'two', 'three'); 23 | 24 | $this->adapter = new ArrayAdapter($this->array); 25 | } 26 | 27 | public function testOffset() 28 | { 29 | $this->assertEquals($this->array[0], $this->adapter[0]); 30 | } 31 | 32 | public function testCount() 33 | { 34 | $this->assertEquals(count($this->array), count($this->adapter)); 35 | } 36 | 37 | public function testUnsetIsset() 38 | { 39 | unset($this->adapter[1]); 40 | 41 | $this->assertFalse(isset($this->adapter[1])); 42 | } 43 | 44 | public function testGetResults() 45 | { 46 | $this->assertEquals(array_slice($this->array, 1, 2), $this->adapter->getResults(1, 2)); 47 | } 48 | } -------------------------------------------------------------------------------- /Resources/views/Pager/paginate.html.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Resources/config/services.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | MakerLabs\PagerBundle\Templating\Helper\PagerHelper 9 | MakerLabs\PagerBundle\Twig\Extension\PagerExtension 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Adapter/ArrayAdapter.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace MakerLabs\PagerBundle\Adapter; 13 | 14 | use MakerLabs\PagerBundle\Adapter\PagerAdapterInterface; 15 | 16 | /** 17 | * Pager array adapter 18 | * 19 | * @author Marcin Butlak 20 | */ 21 | class ArrayAdapter implements PagerAdapterInterface, \Iterator, \ArrayAccess 22 | { 23 | protected $array; 24 | protected $cursor = 0; 25 | protected $count = null; 26 | 27 | public function __construct(array $array) 28 | { 29 | $this->array = $array; 30 | } 31 | 32 | public function count() 33 | { 34 | if (null === $this->count) { 35 | $this->count = count($this->array); 36 | } 37 | 38 | return $this->count; 39 | } 40 | 41 | public function getResults($offset, $limit) 42 | { 43 | return array_slice($this->array, $offset, $limit); 44 | } 45 | 46 | public function isEmpty() 47 | { 48 | return empty($this->array); 49 | } 50 | 51 | public function offsetExists($offset) 52 | { 53 | return isset($this->array[$offset]); 54 | } 55 | 56 | public function offsetGet($offset) 57 | { 58 | return $this->array[$offset]; 59 | } 60 | 61 | public function offsetSet($offset, $value) 62 | { 63 | $this->array[$offset] = $value; 64 | } 65 | 66 | public function offsetUnset($offset) 67 | { 68 | unset($this->array[$offset]); 69 | 70 | $this->totalItems = null; 71 | } 72 | 73 | public function current() 74 | { 75 | return $this->offsetGet($this->cursor); 76 | } 77 | 78 | public function key() 79 | { 80 | return $this->cursor; 81 | } 82 | 83 | public function next() 84 | { 85 | $this->cursor++; 86 | } 87 | 88 | public function rewind() 89 | { 90 | $this->cursor = 0; 91 | } 92 | 93 | public function valid() 94 | { 95 | return $this->offsetExists($this->cursor); 96 | } 97 | } -------------------------------------------------------------------------------- /Twig/Extension/PagerExtension.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace MakerLabs\PagerBundle\Twig\Extension; 13 | 14 | use MakerLabs\PagerBundle\Pager; 15 | use Symfony\Component\Routing\RouterInterface; 16 | use Symfony\Component\DependencyInjection\ContainerInterface; 17 | 18 | /** 19 | * PagerExtension extends Twig with pagination capabilities. 20 | * 21 | * @author Marcin Butlak 22 | */ 23 | class PagerExtension extends \Twig_Extension 24 | { 25 | /** 26 | * 27 | * @var RouterInterface 28 | */ 29 | protected $router; 30 | /** 31 | * 32 | * @var \Twig_Environment 33 | */ 34 | protected $environment; 35 | 36 | public function __construct(RouterInterface $router) 37 | { 38 | $this->router = $router; 39 | } 40 | 41 | public function initRuntime(\Twig_Environment $environment) 42 | { 43 | $this->environment = $environment; 44 | } 45 | 46 | public function getFunctions() 47 | { 48 | return array( 49 | 'paginate' => new \Twig_Function_Method($this, 'paginate', array('is_safe' => array('html'))), 50 | 'paginate_path' => new \Twig_Function_Method($this, 'path', array('is_safe' => array('html'))), 51 | ); 52 | } 53 | 54 | public function paginate(Pager $pager, $route, array $parameters = array(), $template = 'MakerLabsPagerBundle:Pager:paginate.html.twig') 55 | { 56 | return $this->environment->render($template, array('pager' => $pager, 'route' => $route, 'parameters' => $parameters)); 57 | } 58 | 59 | public function path($route, $page, array $parameters = array()) 60 | { 61 | if (isset($parameters['_page'])) { 62 | $parameters[$parameters['_page']] = $page; 63 | 64 | unset($parameters['_page']); 65 | } else { 66 | $parameters['page'] = $page; 67 | } 68 | 69 | return $this->router->generate($route, $parameters); 70 | } 71 | 72 | public function getName() 73 | { 74 | return 'pager'; 75 | } 76 | } -------------------------------------------------------------------------------- /Templating/Helper/PagerHelper.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace MakerLabs\PagerBundle\Templating\Helper; 13 | 14 | use Symfony\Component\Templating\Helper\Helper; 15 | use Symfony\Component\Templating\EngineInterface; 16 | use Symfony\Component\Routing\RouterInterface; 17 | use MakerLabs\PagerBundle\Pager; 18 | 19 | /** 20 | * 21 | * @author Marcin Butlak 22 | */ 23 | class PagerHelper extends Helper 24 | { 25 | /** 26 | * 27 | * @var EngineInterface 28 | */ 29 | protected $engine; 30 | /** 31 | * 32 | * @var RouterInterface 33 | */ 34 | protected $router; 35 | 36 | /** 37 | * Constructor 38 | * 39 | * @param EngineInterface $engine The template engine service 40 | * @param RouterInterface $router The router service 41 | */ 42 | public function __construct(EngineInterface $engine, RouterInterface $router) 43 | { 44 | $this->engine = $engine; 45 | 46 | $this->router = $router; 47 | } 48 | 49 | /** 50 | * Renders the HTML for a given pager 51 | * 52 | * @param Pager $pager A Pager instance 53 | * @param string $route The route name 54 | * @param array $parameters Additional route parameters 55 | * @param string $template The template name 56 | * @return string The html markup 57 | */ 58 | public function paginate(Pager $pager, $route, array $parameters = array(), $template = 'MakerLabsPagerBundle:Pager:paginate.html.php') 59 | { 60 | return $this->engine->render($template, array('pager' => $pager, 'route' => $route, 'parameters' => $parameters)); 61 | } 62 | 63 | /** 64 | * Generates a URL for a given route and page 65 | * 66 | * @param string $route Route name 67 | * @param int $page Page number 68 | * @param array $parameters Optional route parameters 69 | * @return string The url path 70 | */ 71 | public function path($route, $page, array $parameters = array()) 72 | { 73 | if (isset($parameters['_page'])) { 74 | $parameters[$parameters['_page']] = $page; 75 | 76 | unset($parameters['_page']); 77 | } else { 78 | $parameters['page'] = $page; 79 | } 80 | 81 | return $this->router->generate($route, $parameters); 82 | } 83 | 84 | public function getName() 85 | { 86 | return 'pager'; 87 | } 88 | } -------------------------------------------------------------------------------- /Adapter/DoctrineOrmAdapter.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace MakerLabs\PagerBundle\Adapter; 13 | 14 | use MakerLabs\PagerBundle\Adapter\PagerAdapterInterface; 15 | use Doctrine\ORM\QueryBuilder; 16 | 17 | /** 18 | * 19 | * @author Marcin Butlak 20 | */ 21 | class DoctrineOrmAdapter implements PagerAdapterInterface 22 | { 23 | protected $queryBuilder; 24 | protected $hydrationMode; 25 | protected $countQueryBuilder = null; 26 | protected $query = null; 27 | protected $count = null; 28 | 29 | public function __construct(QueryBuilder $qb, $hydration_mode = null) 30 | { 31 | $this->queryBuilder = $qb; 32 | 33 | $this->hydrationMode = $hydration_mode; 34 | } 35 | 36 | /** 37 | * Returns the count query instance 38 | * 39 | * @return QueryBuilder 40 | */ 41 | public function getCountQueryBuilder() 42 | { 43 | if (null === $this->countQueryBuilder || $this->queryBuilder->getState() == QueryBuilder::STATE_DIRTY) { 44 | $a = $this->queryBuilder->getRootAlias(); 45 | 46 | $qb = clone $this->queryBuilder; 47 | 48 | if ($qb->getDQLPart('groupBy')) { 49 | $qb->resetDQLPart('groupBy')->select('COUNT(DISTINCT ' . $a . ')'); 50 | } else { 51 | $qb->select('COUNT(' . $a . ')'); 52 | } 53 | 54 | $qb->resetDQLPart('orderBy')->setMaxResults(null)->setFirstResult(null); 55 | 56 | $this->countQueryBuilder = $qb; 57 | } 58 | 59 | return $this->countQueryBuilder; 60 | } 61 | 62 | public function getQueryBuilder() 63 | { 64 | return $this->queryBuilder; 65 | } 66 | 67 | /** 68 | * Returns the total number of results 69 | * 70 | * @return integer 71 | */ 72 | public function count() 73 | { 74 | if (null === $this->count || $this->getCountQueryBuilder()->getState() == QueryBuilder::STATE_DIRTY) { 75 | $this->count = $this->getCountQueryBuilder()->getQuery()->getSingleScalarResult(); 76 | $this->getQuery(); 77 | } 78 | 79 | return $this->count; 80 | } 81 | 82 | /** 83 | * Returns the list of results 84 | * 85 | * @return array 86 | */ 87 | public function getResults($offset, $limit) 88 | { 89 | return $this->getQuery()->setFirstResult($offset)->setMaxResults($limit)->execute(array(), $this->hydrationMode); 90 | } 91 | 92 | protected function getQuery() 93 | { 94 | if (null === $this->query || $this->queryBuilder->getState() == QueryBuilder::STATE_DIRTY) { 95 | $this->query = $this->queryBuilder->getQuery(); 96 | } 97 | 98 | return $this->query; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /Tests/PagerTest.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace MakerLabs\PagerBundle\Test; 13 | 14 | use MakerLabs\PagerBundle\Pager; 15 | 16 | /** 17 | * 18 | * @author Marcin Butlak 19 | */ 20 | class PagerTest extends \PHPUnit_Framework_TestCase 21 | { 22 | /** 23 | * 24 | * @var \PHPUnit_Framework_MockObject_MockObject 25 | */ 26 | private $adapter; 27 | /** 28 | * 29 | * @var Pager 30 | */ 31 | private $pager; 32 | 33 | protected function setUp() 34 | { 35 | $this->adapter = $this->getMock('MakerLabs\PagerBundle\Adapter\PagerAdapterInterface'); 36 | 37 | $this->adapter->expects($this->any()) 38 | ->method('count') 39 | ->will($this->returnValue(100)); 40 | 41 | $this->pager = new Pager($this->adapter); 42 | } 43 | 44 | public function testConstructor() 45 | { 46 | $pager = new Pager($this->adapter, array('page' => 2, 'limit' => 30)); 47 | 48 | $this->assertEquals(2, $pager->getPage()); 49 | 50 | $this->assertEquals(30, $pager->getLimit()); 51 | } 52 | 53 | public function testNoResults() 54 | { 55 | $adapter = $this->getMock('MakerLabs\PagerBundle\Adapter\PagerAdapterInterface'); 56 | 57 | $adapter->expects($this->any()) 58 | ->method('count') 59 | ->will($this->returnValue(0)); 60 | 61 | $pager = new Pager($adapter); 62 | 63 | $this->assertEquals(1, $pager->getLastPage()); 64 | 65 | $this->assertEquals(false, $pager->hasResults()); 66 | } 67 | 68 | public function testDefaults() 69 | { 70 | $this->assertEquals(1, $this->pager->getPage()); 71 | 72 | $this->assertEquals(20, $this->pager->getLimit()); 73 | 74 | $this->assertEquals(1, $this->pager->getFirstPage()); 75 | 76 | $this->assertEquals(true, $this->pager->isFirstPage()); 77 | 78 | $this->assertEquals(5, $this->pager->getLastPage()); 79 | 80 | $this->assertEquals(false, $this->pager->isLastPage()); 81 | 82 | $this->assertEquals(2, $this->pager->getNextPage()); 83 | 84 | $this->assertEquals(1, $this->pager->getPreviousPage()); 85 | 86 | $this->assertEquals(true, $this->pager->isPaginable()); 87 | } 88 | 89 | public function testIsLastPage() 90 | { 91 | $this->pager->setPage(5); 92 | 93 | $this->assertEquals(true, $this->pager->isLastPage()); 94 | } 95 | 96 | public function testNotLastPage() 97 | { 98 | $this->pager->setPage(2); 99 | 100 | $this->assertEquals(false, $this->pager->isLastPage()); 101 | } 102 | 103 | public function testNotFirstPage() 104 | { 105 | $this->pager->setPage(5); 106 | 107 | $this->assertEquals(false, $this->pager->isFirstPage()); 108 | } 109 | 110 | public function testOutOfRangeLimit() 111 | { 112 | $this->pager->setPage(200); 113 | 114 | $this->assertEquals(5, $this->pager->getPage()); 115 | 116 | $this->pager->setPage(-100); 117 | 118 | $this->assertEquals(1, $this->pager->getPage()); 119 | 120 | $this->pager->setLimit(-100); 121 | 122 | $this->assertEquals(1, $this->pager->getLimit()); 123 | } 124 | 125 | public function testResults() 126 | { 127 | $this->assertEquals(true, $this->pager->hasResults()); 128 | 129 | $this->adapter->expects($this->any()) 130 | ->method('getResults') 131 | ->with($this->equalTo(40), $this->equalTo(40)); 132 | 133 | $this->pager->setPage(2)->setLimit(40); 134 | 135 | $this->pager->getResults(); 136 | } 137 | 138 | public function testIsNotPaginable() 139 | { 140 | $this->pager->setLimit(100); 141 | 142 | $this->assertEquals(false, $this->pager->isPaginable()); 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /Pager.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | namespace MakerLabs\PagerBundle; 13 | 14 | use MakerLabs\PagerBundle\Adapter\PagerAdapterInterface; 15 | 16 | /** 17 | * Pager 18 | * 19 | * @author Marcin Butlak 20 | */ 21 | class Pager 22 | { 23 | /** 24 | * 25 | * @var integer 26 | */ 27 | protected $page = 1; 28 | 29 | /** 30 | * 31 | * @var integer 32 | */ 33 | protected $limit = 20; 34 | 35 | /** 36 | * Constructor 37 | * 38 | * @param PagerAdapterInterface $adapter The pager adapter 39 | * @param array $options Additional options 40 | */ 41 | public function __construct(PagerAdapterInterface $adapter, array $options = array()) 42 | { 43 | $this->adapter = $adapter; 44 | 45 | if (isset($options['limit'])) { 46 | $this->setLimit($options['limit']); 47 | } 48 | 49 | if (isset($options['page'])) { 50 | $this->setPage($options['page']); 51 | } 52 | } 53 | 54 | /** 55 | * Sets the current page number 56 | * 57 | * @param integer $page The current page number 58 | * @return Pager instance 59 | */ 60 | public function setPage($page) 61 | { 62 | $this->page = min($page > 0 ? $page : $this->getFirstPage(), $this->getLastPage()); 63 | 64 | return $this; 65 | } 66 | 67 | /** 68 | * Returns the current page number 69 | * 70 | * @return integer 71 | */ 72 | public function getPage() 73 | { 74 | return $this->page; 75 | } 76 | 77 | /** 78 | * Sets the results limit for one page 79 | * 80 | * @param integer $limit 81 | * @return Pager instance 82 | */ 83 | public function setLimit($limit) 84 | { 85 | $this->limit = $limit > 0 ? $limit : 1; 86 | 87 | $this->setPage($this->page); 88 | 89 | return $this; 90 | } 91 | 92 | /** 93 | * Returns the current results limit for one page 94 | * 95 | * @return integer 96 | */ 97 | public function getLimit() 98 | { 99 | return $this->limit; 100 | } 101 | 102 | /** 103 | * Returns the next page number 104 | * 105 | * @return integer 106 | */ 107 | public function getNextPage() 108 | { 109 | return $this->page < $this->getLastPage() ? $this->page + 1 : $this->getLastPage(); 110 | } 111 | 112 | /** 113 | * Returns the previous page number 114 | * 115 | * @return integer 116 | */ 117 | public function getPreviousPage() 118 | { 119 | return $this->page > $this->getFirstPage() ? $this->page - 1 : $this->getFirstPage(); 120 | } 121 | 122 | /** 123 | * Returns true if the current page is first 124 | * 125 | * @return boolean 126 | */ 127 | public function isFirstPage() 128 | { 129 | return $this->page == 1; 130 | } 131 | 132 | /** 133 | * Returns the first page number 134 | * 135 | * @return integer 136 | */ 137 | public function getFirstPage() 138 | { 139 | return 1; 140 | } 141 | 142 | /** 143 | * Returns true if the current page is last 144 | * 145 | * @return boolean 146 | */ 147 | public function isLastPage() 148 | { 149 | return $this->page == $this->getLastPage(); 150 | } 151 | 152 | /** 153 | * Returns the last page number 154 | * 155 | * @return integer 156 | */ 157 | public function getLastPage() 158 | { 159 | return $this->hasResults() ? ceil($this->adapter->count() / $this->limit) : $this->getFirstPage(); 160 | } 161 | 162 | /** 163 | * Returns true if the current result set requires pagination 164 | * 165 | * @return boolean 166 | */ 167 | public function isPaginable() 168 | { 169 | return $this->adapter->count() > $this->limit; 170 | } 171 | 172 | /** 173 | * Generates a page list 174 | * 175 | * @param integer $pages Number of pages to generate 176 | * @return array The page list 177 | */ 178 | public function getPages($pages = 10) 179 | { 180 | $tmp = $this->page - floor($pages / 2); 181 | 182 | $begin = $tmp > $this->getFirstPage() ? $tmp : $this->getFirstPage(); 183 | 184 | $end = min($begin + $pages - 1, $this->getLastPage()); 185 | 186 | return range($begin, $end, 1); 187 | } 188 | 189 | /** 190 | * Returns true if the current result set is not empty 191 | * 192 | * @return boolean 193 | */ 194 | public function hasResults() 195 | { 196 | return $this->adapter->count() > 0; 197 | } 198 | 199 | /** 200 | * 201 | * Returns results list for the current page and limit 202 | * 203 | * @return array 204 | */ 205 | public function getResults() 206 | { 207 | return $this->hasResults() ? $this->adapter->getResults(($this->page - 1) * $this->limit, $this->limit) : array(); 208 | } 209 | 210 | /** 211 | * Returns the current adapter instance 212 | * 213 | * @return PagerAdapterInterface 214 | */ 215 | public function getAdapter() 216 | { 217 | return $this->adapter; 218 | } 219 | } 220 | --------------------------------------------------------------------------------