serviceManager = $serviceManager; $this->setPageLimit(); $this->setPageRange(); $this->setRoute(); return $this; } public function setPageLimit($limit = 0) { $this->pageLimit = (int)$limit; if(empty($this->pageLimit)) $this->pageLimit = 10; } public function setPageRange($range = 0) { $this->pageRange = (int)$range; if(empty($this->pageRange)) $this->pageRange = 6; } public function setRoute($route = "",$params = "") { if(empty($route)) { $routeMatch = $this->serviceManager->get('Application')->getMvcEvent()->getRouteMatch(); $this->route = str_replace("/wildcard", "", $routeMatch->getMatchedRouteName()); $this->params = []; }else{ $this->route = $route; } if(empty($params)) { if(!isset($routeMatch)) $routeMatch = $this->serviceManager->get('Application')->getMvcEvent()->getRouteMatch(); if (!empty($routeMatch->getParam('__CONTROLLER__'))) $this->params['controller'] = $routeMatch->getParam('__CONTROLLER__'); if (!empty($routeMatch->getParam('action'))) $this->params['action'] = $routeMatch->getParam('action'); if (!empty($routeMatch->getParam('ac'))) $this->params['ac'] = $routeMatch->getParam('ac'); if (!empty($routeMatch->getParam['id'])) $this->params['id'] = $routeMatch->getParam('id'); if (!empty($routeMatch->getParam['uuid'])) $this->params['uuid'] = $routeMatch->getParam('uuid'); }else{ $this->params = $params; } unset($routeMatch); } /** * @param AbstractActionController $ctl * @param mixed $data * @param string $viewPartial * @return bool */ public function add(AbstractActionController $ctl,$data,$viewPartial = "pagination") { $page = $ctl->params()->fromRoute('page'); if(is_array($data)) $data = new ArrayAdapter($data); if($data instanceof Select) { $dbService = $this->serviceManager->get('Db'); $zendDb = $dbService->getZendDb(); $data = new DbSelect($data,$zendDb); } if($data instanceof TableGateway) $data = new DbTableGateway($data,$this->sqlQuery,$this->sqlOrder,$this->sqlGroup,$this->sqlHaving); $paginator = new Zend_Paginator($data); $paginator->setCurrentPageNumber($page) ->setItemCountPerPage($this->pageLimit) ->setPageRange($this->pageRange); $pagination = $ctl->getServiceLocator()->get('viewhelpermanager')->get('PaginationControl'); $pageSliding = $pagination( $paginator, 'Sliding', $viewPartial, ['route'=>$this->route,'params'=>$this->params] ); $ctl->ViewModel->setVariable('pagination',$pageSliding); $ctl->ViewModel->setVariable('paginator',$paginator); return true; } }