protected function setUp() { if (!extension_loaded('pdo_sqlite')) { $this->markTestSkipped('Pdo_Sqlite extension is not loaded'); } $this->_adapter = new \Zend\Db\Adapter\Pdo\Sqlite(array( 'dbname' => __DIR__ . '/_files/test.sqlite' )); $this->_query = $this->_adapter->select()->from('test'); $this->_testCollection = range(1, 101); $this->_paginator = Paginator\Paginator::factory($this->_testCollection); $this->_config = new Config\Xml(__DIR__ . '/_files/config.xml'); // get a fresh new copy of ViewRenderer in each tests $this->front = FrontController::getInstance(); $this->front->resetInstance(); $this->broker = $this->front->getHelperBroker(); $fO = array('lifetime' => 3600, 'automatic_serialization' => true); $bO = array('cache_dir'=> $this->_getTmpDir()); $this->_cache = \Zend\Cache\Cache::factory('Core', 'File', $fO, $bO); Paginator\Paginator::setCache($this->_cache); $this->_restorePaginatorDefaults(); }
protected function setUp() { $this->select = new Sql\Select(); $this->select->from('test'); $this->testCollection = range(1, 101); $this->paginator = new Paginator\Paginator(new Paginator\Adapter\ArrayAdapter($this->testCollection)); $this->config = Config\Factory::fromFile(__DIR__ . '/_files/config.xml', true); $this->cache = CacheFactory::adapterFactory('memory', array('memory_limit' => 0)); Paginator\Paginator::setCache($this->cache); $this->_restorePaginatorDefaults(); }
/** * Mostra os posts cadastrados * @return void */ public function indexAction() { $adapter = $this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter'); $sql = new Sql($adapter); $select = $sql->select()->from('posts'); $paginatorAdapter = new PaginatorDbSelectAdapter($select, $sql); $paginator = new Paginator($paginatorAdapter); $paginator->setCurrentPageNumber($this->params()->fromRoute('page')); $paginator->setItemCountPerPage($this->params()->fromRoute('itens', 50)); $cache = $this->getServiceLocator()->get('Cache'); $paginator->setCache($cache); return new ViewModel(array('posts' => $paginator)); }
/** * Mostra os posts cadastrados * @return void */ public function indexAction() { $post = $this->getTable('Application\\Model\\Post'); $sql = $post->getSql(); $select = $sql->select(); $paginatorAdapter = new PaginatorDbSelectAdapter($select, $sql); $paginator = new Paginator($paginatorAdapter); $cache = $this->getServiceLocator()->get('Cache'); $cache = $this->getService('Cache'); $paginator->setCache($cache); $paginator->setCurrentPageNumber($this->params()->fromRoute('page')); $paginator->setItemCountPerPage(10); return new ViewModel(array('posts' => $paginator)); }
protected function setUp() { if (!extension_loaded('pdo_sqlite')) { $this->markTestSkipped('Pdo_Sqlite extension is not loaded'); } $this->_adapter = new DbAdapter\Adapter(array('driver' => 'Pdo_Sqlite', 'database' => __DIR__ . '/_files/test.sqlite')); $this->_query = new Sql\Select(); $this->_query->from('test'); $this->_testCollection = range(1, 101); $this->_paginator = Paginator\Paginator::factory($this->_testCollection); $this->_config = Config\Factory::fromFile(__DIR__ . '/_files/config.xml', true); $this->_cache = CacheFactory::adapterFactory('memory', array('memory_limit' => 0)); Paginator\Paginator::setCache($this->_cache); $this->_restorePaginatorDefaults(); }
protected function setUp() { if (!extension_loaded('pdo_sqlite')) { $this->markTestSkipped('Pdo_Sqlite extension is not loaded'); } $this->_adapter = new \Zend\Db\Adapter\Pdo\Sqlite(array('dbname' => __DIR__ . '/_files/test.sqlite')); $this->_query = $this->_adapter->select()->from('test'); $this->_testCollection = range(1, 101); $this->_paginator = Paginator\Paginator::factory($this->_testCollection); $this->_config = new Config\Xml(__DIR__ . '/_files/config.xml'); $this->_cache = CacheFactory::factory(array('adapter' => array('name' => 'filesystem', 'options' => array('ttl' => 3600, 'cache_dir' => $this->_getTmpDir())), 'plugins' => array(array('name' => 'serializer', 'options' => array('serializer' => 'php_serialize'))))); $this->_cache->clear(CacheAdapter::MATCH_ALL); Paginator\Paginator::setCache($this->_cache); $this->_restorePaginatorDefaults(); }
protected function setUp() { if (!extension_loaded('pdo_sqlite')) { $this->markTestSkipped('Pdo_Sqlite extension is not loaded'); } $this->_adapter = new \Zend\Db\Adapter\Pdo\Sqlite(array('dbname' => __DIR__ . '/_files/test.sqlite')); $this->_query = $this->_adapter->select()->from('test'); $this->_testCollection = range(1, 101); $this->_paginator = Paginator\Paginator::factory($this->_testCollection); $this->_config = Config\Factory::fromFile(__DIR__ . '/_files/config.xml', true); $this->_cache = CacheFactory::adapterFactory('memory', array('memory_limit' => 0)); $this->_cache->clear(CacheAdapter::MATCH_ALL); Paginator\Paginator::setCache($this->_cache); $this->_restorePaginatorDefaults(); }
/** * @author VanCK * @param ServiceLocatorInterface $serviceLocator * @return \Zend\Cache\StorageFactory */ public function createService(ServiceLocatorInterface $serviceLocator) { $cache = StorageFactory::factory(array('adapter' => array('name' => 'filesystem', 'options' => array('cache_dir' => BASE_PATH . '/data/cache', 'ttl' => 100)), 'plugins' => array(array('name' => 'serializer', 'options' => [])))); \Zend\Paginator\Paginator::setCache($cache); return $cache; }
/** * An internal method for getting paginated results from querybuilder * @param QueryBuilder $queryBuilder * @param PaginationParameters $paginationParameters * @param $resultKey Deprecated, use HIDDEN keyword instead * @return \Zend\Paginator\Paginator */ public function getPaginatedResult(QueryBuilder $queryBuilder, PaginationParameters $paginationParameters, $resultKey = null) { if ($paginationParameters->getOrder() != null && $paginationParameters->getSort() != null) { if (!is_array($paginationParameters->getSort()) && !is_array($paginationParameters->getOrder())) { $sort = array($paginationParameters->getSort()); $order = array($paginationParameters->getOrder()); } else { if (count($paginationParameters->getSort()) != count($paginationParameters->getOrder())) { throw new \InvalidArgumentException('Sort and order arrays must be the same length'); } $sort = $paginationParameters->getSort(); $order = $paginationParameters->getOrder(); } foreach ($sort as $key => $oneSortField) { if (!strstr($oneSortField, '.')) { $alias = $queryBuilder->getRootAlias() . '.'; } else { $alias = ''; } $queryBuilder->addOrderBy($alias . $oneSortField, $order[$key]); } } if ($paginationParameters->getFilters() != null) { foreach ($paginationParameters->getFilters() as $field => $value) { if ($value == '' || $queryBuilder->getParameter($field) != null) { continue; } if (!strstr($field, '.')) { $entityField = $queryBuilder->getRootAlias() . '.' . $field; } else { $entityField = $field; } if (is_array($value)) { $queryBuilder->andWhere($entityField . ' IN (\'' . implode("', '", $value) . '\')'); } else { $queryBuilder->andWhere($entityField . ' = :' . str_replace('.', '_', $field))->setParameter(str_replace('.', '_', $field), $value); } } } if ($this->usedPaginator == null) { $paginatorTool = new \Doctrine\ORM\Tools\Pagination\Paginator($queryBuilder); } else { $paginatorTool = $this->usedPaginator; } $paginator = new Paginator(new Adapter\DoctrinePaginator($paginatorTool)); $paginator->setItemCountPerPage($paginationParameters->getItemCountPerPage()); $paginator->setCurrentPageNumber($paginationParameters->getCurrentPageNumber()); if ($paginationParameters->getCache() != null) { $paginator->setCache($paginationParameters->getCache()); } if ($resultKey !== null) { foreach ($paginator as &$itemElement) { $itemElement = $itemElement[$resultKey]; } } return $paginator; }