public function dataAction() { $response = $this->getResponse(); $grid = $this->grid('Application\\Index\\Index', array('-', 'id', 'title', 'category', 'username', 'created_at', '-')); if (isset($this->getSessionContainer()->parent_id)) { $grid['parent_id'] = $this->getSessionContainer()->parent_id; } $result = $this->getResourceTable()->fetchDataGrid($grid); $adapter = new ArrayAdapter($result); $paginator = new Paginator($adapter); $page = ceil(intval($grid['start']) / intval($grid['length'])) + 1; $paginator->setCurrentPageNumber($page); $paginator->setItemCountPerPage(intval($grid['length'])); $data = array(); $data['data'] = array(); foreach ($paginator as $row) { $category = array_key_exists('category', $row) ? $row['category'] : '-'; $title = $row['node_type'] == \Application\Model\Resource::NODE_TYPE_CATEGORY ? '<a href="/admin/resource/parent_id/' . $row['id'] . '" title="' . strip_tags($row['description']) . '">' . strip_tags($row['title']) . '</a>' : '<i>' . strip_tags($row['title']) . '</i>'; $actions = ''; if ($row['url']) { $actions .= '<a class="btn btn-xs btn-outline blue-steel btn-view" href="' . $row['url'] . '" data-id="' . $row['id'] . '" target="_blank">View</a> '; } $actions .= '<a class="btn btn-xs btn-outline red" href="/admin/resource/delete/id/' . $row['id'] . '" onclick="return confirm("Are you sure you wish to delete selected resources?");">Delete</a>'; $data['data'][] = array('<input type="checkbox" name="id[' . $row['id'] . ']" value="' . $row['id'] . '" />', '<a class="btn btn-xs btn-outline blue-steel btn-view" href="/admin/resource/edit/id/' . $row['id'] . '/parent_id/' . $row['parent_id'] . '" title="' . $row['id'] . '">Edit: ' . $row['id'] . '</a>', $title, $category, $row['username'], date('F jS Y', strtotime($row['created_at'])), $actions); } $data['page'] = $page; $data['grid'] = $grid; $data['draw'] = intval($grid['draw']); $data['recordsTotal'] = $paginator->getTotalItemCount(); $data['recordsFiltered'] = $paginator->getTotalItemCount(); $response->setStatusCode(200); $response->setContent(Json::encode($data)); return $response; }
/** * Convert a paginator to array * * @param Paginator $paginator * @param string $key root key for items, leave null to return items in root * @return array */ protected function paginatorToArray(Paginator $paginator, $key = null) { $items = iterator_to_array($paginator->getCurrentItems()); if (null === $key) { return $items; } return array('pages' => $paginator->count(), 'current' => $paginator->getCurrentPageNumber(), 'count' => $paginator->getTotalItemCount(), $key => $items); }
public function getPagination($iPageNumber = 0, $iCountPerPage = 0) { $paginatorAdapter = new DbSelect($this->mAdministratorTb->getSql()->select()->columns(array('id', 'role_id', 'username', 'realname', 'raw_add_time')), $this->mAdministratorTb->getAdapter(), $this->mAdministratorTb->getResultSetPrototype()); $paginator = new Paginator($paginatorAdapter); $paginator->setCurrentPageNumber($iPageNumber)->setItemCountPerPage($iCountPerPage); $aRows = $this->mCore->IteratorToArray($paginator->getCurrentItems()); $iTotal = $paginator->getTotalItemCount(); return json_encode(array('rows' => $aRows, 'total' => $iTotal)); }
public function getPagination($iPageNumber = 0, $iCountPerPage = 0, $aOptions = array()) { $paginatorAdapter = new DbSelect($this->mAuthorityTb->getSql()->select()->where($aOptions), $this->mAuthorityTb->getAdapter(), $this->mAuthorityTb->getResultSetPrototype()); $paginator = new Paginator($paginatorAdapter); $paginator->setCurrentPageNumber($iPageNumber)->setItemCountPerPage($iCountPerPage); $iTotal = $paginator->getTotalItemCount(); $aRows = $this->mCore->IteratorToArray($paginator->getCurrentItems()); return json_encode(array('rows' => $aRows, 'total' => $iTotal)); }
/** * @return \Zend\View\Model\ViewModel */ public function listAction() { $page = $this->params('page'); $templateQuery = $this->getGeneralService()->findFiltered(WebInfo::class, []); $paginator = new Paginator(new PaginatorAdapter(new ORMPaginator($templateQuery, false))); $paginator->setDefaultItemCountPerPage($page === 'all' ? PHP_INT_MAX : 15); $paginator->setCurrentPageNumber($page); $paginator->setPageRange(ceil($paginator->getTotalItemCount() / $paginator->getDefaultItemCountPerPage())); return new ViewModel(['paginator' => $paginator]); }
/** * @return ViewModel */ public function missingAction() { $affiliation = $this->getAffiliationService()->findAffiliationWithMissingLoi(); $page = $this->params('page'); $paginator = new Paginator(new PaginatorAdapter(new ORMPaginator($affiliation, false))); $paginator->setDefaultItemCountPerPage($page === 'all' ? PHP_INT_MAX : 15); $paginator->setCurrentPageNumber($page); $paginator->setPageRange(ceil($paginator->getTotalItemCount() / $paginator->getDefaultItemCountPerPage())); return new ViewModel(['paginator' => $paginator]); }
/** * @return ViewModel */ public function overviewAction() { $which = $this->params('which', CalendarService::WHICH_UPCOMING); $page = $this->params('page', 1); $calendarItems = $this->getCalendarService()->findCalendarItems($which, $this->zfcUserAuthentication()->getIdentity()); $paginator = new Paginator(new PaginatorAdapter(new ORMPaginator($calendarItems))); $paginator->setDefaultItemCountPerPage($page === 'all' ? PHP_INT_MAX : 15); $paginator->setCurrentPageNumber($page); $paginator->setPageRange(ceil($paginator->getTotalItemCount() / $paginator->getDefaultItemCountPerPage())); $whichValues = $this->getCalendarService()->getWhichValues(); return new ViewModel(['enableCalendarContact' => $this->getModuleOptions()->getCommunityCalendarContactEnabled(), 'which' => $which, 'paginator' => $paginator, 'whichValues' => $whichValues]); }
public function fetch($meta = null) { $this->select->from($this->name); $dbSelect = new DbSelect($this->select, $this->tableGateway->getAdapter(), $this->getResultSet()); $paginator = new Paginator($dbSelect); if ($meta) { if (isset($meta['loadAllToFirstPage'])) { $paginator->setItemCountPerPage($paginator->getTotalItemCount()); } } return $this->constructForeignKeys($paginator); }
public function dataAction() { $request = $this->getRequest(); $response = $this->getResponse(); $post = $this->purify($request->getPost()); $actionMessage = array(); if (isset($post->action)) { if (sizeof($post->id)) { if ($post->action == 'mark-delete') { foreach ($post->id as $id) { $this->getActivityTable()->delete(array('id' => $id)); } $actionMessage = array('message' => 'A total of ' . count($post->id) . ' records have been deleted successfully.', 'status' => 'OK'); } } } $grid = $this->grid('Admin\\Activity\\Index', array('-', 'id', 'text', 'username', 'created_at', '-')); $result = $this->getActivityTable()->fetchDataGrid($grid); $adapter = new ArrayAdapter($result); $paginator = new Paginator($adapter); $page = ceil(intval($grid['start']) / intval($grid['length'])) + 1; $paginator->setCurrentPageNumber($page); $paginator->setItemCountPerPage(intval($grid['length'])); $data = array(); $data['data'] = array(); foreach ($paginator as $row) { $data['data'][] = array('<input type="checkbox" name="id[' . $row['id'] . ']" value="' . $row['id'] . '" />', $row['id'], $row['text'], $row['username'], $row['created_at'], '<a href="/admin/activity/view/id/' . $row['id'] . '" class="btn btn-xs btn-outline blue-steel" data-id="' . $row['id'] . '" title="View Activity"><i class="fa fa-search"></i> View</a>'); } $data['page'] = $page; $data['grid'] = $grid; $data['draw'] = intval($grid['draw']); $data['recordsTotal'] = $paginator->getTotalItemCount(); $data['recordsFiltered'] = $paginator->getTotalItemCount(); if (sizeof($actionMessage)) { $data['actionMessage'] = $actionMessage; } $response->setStatusCode(200); $response->setContent(Json::encode($data)); return $response; }
/** * @return \Zend\View\Model\ViewModel */ public function listAction() { $page = $this->params()->fromRoute('page', 1); $filterPlugin = $this->getGeneralFilter(); $contactQuery = $this->getGeneralService()->findEntitiesFiltered('gender', $filterPlugin->getFilter()); $paginator = new Paginator(new PaginatorAdapter(new ORMPaginator($contactQuery, false))); $paginator->setDefaultItemCountPerPage($page === 'all' ? PHP_INT_MAX : 20); $paginator->setCurrentPageNumber($page); $paginator->setPageRange(ceil($paginator->getTotalItemCount() / $paginator->getDefaultItemCountPerPage())); $form = new GenderFilter($this->getGeneralService()); $form->setData(['filter' => $filterPlugin->getFilter()]); return new ViewModel(['paginator' => $paginator, 'form' => $form, 'encodedFilter' => urlencode($filterPlugin->getHash()), 'order' => $filterPlugin->getOrder(), 'direction' => $filterPlugin->getDirection()]); }
/** * @depends testApiAccess */ public function testNewInstance(SearchForm $form) { $adapter = new SearchFormAdapter($form); $this->assertSame(6, $adapter->count()); $pager = new Paginator($adapter); $pager->setCurrentPageNumber(1); $pager->setItemCountPerPage(2); $this->assertSame(6, $pager->getTotalItemCount()); foreach ($pager as $item) { $this->assertInstanceOf('Prismic\\Document', $item); $this->assertSame('pager-test-doc', $item->getType()); } return $pager; }
/** * Return list of resources * * @param callable $queryBuilderCallback * @param callable $queryCallback * @throws \Application\Library\Exception\ValidationException * @return mixed */ public function getList(\Closure $queryBuilderCallback = null, \Closure $queryCallback = null) { $form = new ModelFilterForm(); $form->setData($this->params()->fromQuery()); if (!$form->isValid()) { throw new ValidationException($form->getMessages(), 400); } $limit = $form->getData()['rows']; $page = $form->getData()['page']; $queryBuilder = $this->getEntityManager()->createQueryBuilder(); $queryBuilder->select('c')->from($this->entityClass, 'c'); if (!is_null($queryBuilderCallback)) { $queryBuilderCallback($queryBuilder); } $query = $queryBuilder->getQuery()->setHydrationMode(Query::HYDRATE_ARRAY); if (!is_null($queryCallback)) { $queryCallback($query); } $paginator = new Paginator(new DoctrinePaginator(new ORMPaginator($query))); $paginator->setCurrentPageNumber($page)->setItemCountPerPage($limit); $return = array('page' => $paginator->getCurrentPageNumber(), 'total' => ceil($paginator->getTotalItemCount() / $limit), 'records' => $paginator->getTotalItemCount(), 'rows' => $paginator->getCurrentItems()->getArrayCopy()); return new JsonModel($return); }
/** * @return ViewModel */ public function viewAction() { $organisationService = $this->getOrganisationService()->setOrganisationId($this->params('id')); $page = $this->params()->fromRoute('page', 1); $filterPlugin = $this->getInvoiceFilter(); $invoiceQuery = $this->getInvoiceService()->findEntitiesFiltered('invoice', array_merge($filterPlugin->getFilter(), ['organisation' => [$organisationService->getOrganisation()->getId()]])); $paginator = new Paginator(new PaginatorAdapter(new ORMPaginator($invoiceQuery, false))); $paginator->setDefaultItemCountPerPage($page === 'all' ? PHP_INT_MAX : 15); $paginator->setCurrentPageNumber($page); $paginator->setPageRange(ceil($paginator->getTotalItemCount() / $paginator->getDefaultItemCountPerPage())); $form = new InvoiceFilter($this->getInvoiceService()); $form->setData(['filter' => $filterPlugin->getFilter()]); $projects = $this->getProjectService()->findProjectByOrganisation($organisationService->getOrganisation(), ProjectService::WHICH_ALL); return new ViewModel(['paginator' => $paginator, 'form' => $form, 'encodedFilter' => urlencode($filterPlugin->getHash()), 'order' => $filterPlugin->getOrder(), 'direction' => $filterPlugin->getDirection(), 'organisationService' => $organisationService, 'organisationDoa' => $this->getDoaService()->findDoaByOrganisation($organisationService->getOrganisation()), 'organisationLoi' => $this->getLoiService()->findLoiByOrganisation($organisationService->getOrganisation()), 'projects' => $projects, 'projectService' => $this->getProjectService()]); }
public function dataAction() { $response = $this->getResponse(); $grid = $this->grid('Application\\Index\\Index', array('id', 'title', 'category', 'created_at', '-')); $result = $this->getResourceTable()->fetchResources($grid); $adapter = new ArrayAdapter($result); $paginator = new Paginator($adapter); $page = ceil(intval($grid['start']) / intval($grid['length'])) + 1; $paginator->setCurrentPageNumber($page); $paginator->setItemCountPerPage(intval($grid['length'])); $data = array(); $data['data'] = array(); foreach ($paginator as $row) { $data['data'][] = array($row['id'], '<strong>' . $row['title'] . '</strong><br/>' . $row['description'], $row['category'], $row['created_at'], '<a href="' . $row['url'] . '" class="btn btn-xs default btn-editable btn-view" data-id="' . $row['id'] . '" title="View Resource" target="_blank"><i class="fa fa-search"></i> View</a>'); } $data['page'] = $page; $data['grid'] = $grid; $data['draw'] = intval($grid['draw']); $data['recordsTotal'] = $paginator->getTotalItemCount(); $data['recordsFiltered'] = $paginator->getTotalItemCount(); $response->setStatusCode(200); $response->setContent(Json::encode($data)); return $response; }
/** * * @return string */ public function __invoke(Paginator $paginator) { $content = <<<HTML \t\t<label class="inline control-label">Displaying: </label> \t\t<span> \t\t\t%1\$s - %2\$s of %3\$s \t\t</span> HTML; $limit = $paginator->getItemCountPerPage(); $page = $paginator->getCurrentPageNumber(); $current = $paginator->getCurrentItemCount(); $total = $paginator->getTotalItemCount(); $offset = $limit * $page - $limit; return sprintf($content, intval($offset) + 1, intval($offset) + intval($current), $total); }
/** * @return ViewModel */ public function listAction() { $paginator = null; $searchForm = new Search(); $search = $this->getRequest()->getQuery()->get('search'); $page = $this->getRequest()->getQuery()->get('page'); $searchForm->setData($_GET); if ($this->getRequest()->isGet() && $searchForm->isValid() && !empty($search)) { $contactSearchQuery = $this->getContactService()->searchContacts($search); $paginator = new Paginator(new PaginatorAdapter(new ORMPaginator($contactSearchQuery))); $paginator->setDefaultItemCountPerPage($page === 'all' ? PHP_INT_MAX : 15); $paginator->setCurrentPageNumber($page); $paginator->setPageRange(ceil($paginator->getTotalItemCount() / $paginator->getDefaultItemCountPerPage())); } return new ViewModel(['paginator' => $paginator, 'form' => $searchForm]); }
/** * @return ViewModel */ public function listAction() { if (!is_null($this->params('call'))) { $this->getCallService()->setCallId($this->params('call')); } if (!is_null($this->params('program'))) { $this->getProgramService()->setProgramId($this->params('program')); } $page = $this->params('page'); $projects = $this->getProjectService()->findProjectByContactByProgramOrCall($this->zfcUserAuthentication()->getIdentity(), ProjectService::WHICH_ALL, !$this->getProgramService()->isEmpty() ? $this->getProgramService()->getProgram() : null, !$this->getCallService()->isEmpty() ? $this->getCallService()->getCall() : null, null, $this->params()->fromQuery('q')); $paginator = new Paginator(new PaginatorAdapter(new ORMPaginator($projects, false))); $paginator->setDefaultItemCountPerPage($page === 'all' ? PHP_INT_MAX : 15); $paginator->setCurrentPageNumber($page); $paginator->setPageRange(ceil($paginator->getTotalItemCount() / $paginator->getDefaultItemCountPerPage())); return new ViewModel(['paginator' => $paginator, 'search' => $this->params()->fromQuery('q'), 'calls' => $this->getCallService()->findNonEmptyCalls(), 'callId' => $this->getCallService()->isEmpty() ? null : $this->getCallService()->getCall()->getId(), 'selectedProgramId' => $this->getProgramService()->isEmpty() ? null : $this->getProgramService()->getProgram()->getId()]); }
public function indexAction() { /** @var QueryBuilder $qb */ $qb = $this->getObjectManager()->createQueryBuilder(); $qb->select('w')->from(Word::class, 'w'); $form = new WordSearchForm(); $form->setData($this->params()->fromQuery()); $form->setInputFilter(new WordSearchInputFilter()); // it doesn't matter if the form is not valid, as we would fill in default values anyway. This is just to avoid the default error messages $form->isValid(); // set query, direction and order for the querybuilder $direction = strtolower($form->getData()['d']); $direction = $direction == 'desc' ? 'desc' : 'asc'; $orderBy = strtolower($form->getData()['o']); switch ($orderBy) { case 'created': $order = 'createdAt'; break; case 'updated': $order = 'updatedAt'; break; default: $orderBy = $order = 'word'; break; } $qb->orderBy('w.' . $order, $direction); // no need to avoid SQL injection, as doctrine does this for us $query = $form->getData()['q']; $qb->where('w.word LIKE :query')->setParameter('query', '%' . $query . '%'); $itemsPerPage = 50; // set up the paginator $adapter = new DoctrineAdapter(new ORMPaginator($qb->getQuery())); $paginator = new Paginator($adapter); $paginator->setDefaultItemCountPerPage(50); $page = (int) $this->params()->fromQuery('p'); if ($page != null) { $paginator->setCurrentPageNumber($page); } else { $paginator->setCurrentPageNumber(1); } $pages = $paginator->getTotalItemCount() / $itemsPerPage; $paginator->setPageRange($pages); $viewModel = new ViewModel(); $viewModel->setVariables(['words' => $paginator->getCurrentItems(), 'pageCount' => $paginator->getPageRange() + 1, 'currentPage' => $paginator->getCurrentPageNumber(), 'orderBy' => $orderBy, 'direction' => $direction, 'query' => $query, 'form' => $form]); return $viewModel; }
public function indexAction() { $categories = $this->categoryTable->fetchAll(); $results = array(); $adapter = $this->jobTable->getAdapter(); foreach ($categories as $category) { $select = $this->jobTable->getActiveJobsForPagination($category->id_category, $this->config['job_nb_valid_days']); $paginator = new Paginator(new \Zend\Paginator\Adapter\DbSelect($select, $adapter)); $paginator->setCurrentPageNumber(0); $paginator->setDefaultItemCountPerPage($this->config['nb_job_by_category']); $jobs = $paginator->getCurrentItems(); $activeJobs = $paginator->getTotalItemCount(); $results[] = array('category' => $category, 'job' => $jobs, 'activeJobs' => $activeJobs); } $nbJobByCategory = $this->config['nb_job_by_category']; return new ViewModel(array('results' => $results, 'nbJobByCategory' => $nbJobByCategory)); }
/** * getList * * @return mixed|JsonModel */ public function getList() { //ACCESS CHECK if (!$this->rcmIsAllowed('sites', 'admin')) { $this->getResponse()->setStatusCode(Response::STATUS_CODE_401); return $this->getResponse(); } /** @var \Doctrine\ORM\EntityManagerInterface $entityManager */ $entityManager = $this->getEntityManager(); /** @var \Rcm\Repository\Site $siteRepo */ $siteRepo = $entityManager->getRepository('\\Rcm\\Entity\\Site'); $createQueryBuilder = $siteRepo->createQueryBuilder('site')->select('site')->leftJoin('site.domain', 'domain')->leftJoin('site.country', 'country')->leftJoin('site.language', 'language')->orderBy('domain.domain', 'ASC'); $query = $createQueryBuilder->getQuery(); $searchQuery = $this->params()->fromQuery('q'); if ($searchQuery) { $createQueryBuilder->where($createQueryBuilder->expr()->like('domain.domain', ':searchQuery')); $query = $createQueryBuilder->getQuery(); $query->setParameter('searchQuery', $searchQuery . '%'); } $adaptor = new DoctrinePaginator(new ORMPaginator($query)); $paginator = new Paginator($adaptor); $paginator->setDefaultItemCountPerPage(10); $page = (int) $this->params()->fromQuery('page'); if ($page) { $paginator->setCurrentPageNumber($page); } $pageSize = (int) $this->params()->fromQuery('page_size'); if ($pageSize) { $paginator->setItemCountPerPage($pageSize); } $sitesObjects = $paginator->getCurrentItems(); $sites = []; /** @var \Rcm\Entity\Site $site */ foreach ($sitesObjects as $site) { $sites[] = $site->toArray(); } $list['items'] = $sites; $list['itemCount'] = $paginator->getTotalItemCount(); $list['pageCount'] = $paginator->count(); $list['currentPage'] = $paginator->getCurrentPageNumber(); return new ApiJsonModel($list, 0, 'Success'); }
/** * Display the calendar on the website. * * @return ViewModel */ public function overviewAction() { $which = $this->getEvent()->getRouteMatch()->getParam('which', CalendarService::WHICH_UPCOMING); $page = $this->getEvent()->getRouteMatch()->getParam('page', 1); $year = $this->getEvent()->getRouteMatch()->getParam('year', date("Y")); $birthDays = $this->getContactService()->findContactsWithDateOfBirth(); $calendarItems = $this->getCalendarService()->findCalendarItems($which, $this->zfcUserAuthentication()->getIdentity())->getResult(); $calender = []; $today = new \DateTime(); foreach ($birthDays as $birthDay) { /* * Produce a index which holds the current year */ $dateOfBirth = $birthDay->getDateOfBirth(); $birthDayDate = \DateTime::createFromFormat('Y-m-d', sprintf("%s-%s", date('Y'), $dateOfBirth->format('m-d'))); if ($birthDayDate < $today) { continue; } $index = $birthDayDate->format('Y-m-d'); $calender[$index][] = ['item' => sprintf(_("Birthday of %s (%s)"), $birthDay->getDisplayName(), $birthDay->getDateOfBirth()->format("Y")), 'date' => $birthDayDate]; } /** * @var $calendarItem Calendar */ foreach ($calendarItems as $calendarItem) { if ($calendarItem->getDateFrom() < $today) { continue; } $index = $calendarItem->getDateFrom()->format('Y-m-d'); $calender[$index][] = ['item' => $calendarItem->getCalendar(), 'calendar' => $calendarItem, 'date' => null]; } ksort($calender); $paginator = new Paginator(new ArrayAdapter($calender)); $paginator->setDefaultItemCountPerPage($page === 'all' ? PHP_INT_MAX : PHP_INT_MAX); $paginator->setCurrentPageNumber($page); $paginator->setPageRange(ceil($paginator->getTotalItemCount() / $paginator->getDefaultItemCountPerPage())); $whichValues = $this->getCalendarService()->getWhichValues(); return new ViewModel(['which' => $which, 'paginator' => $paginator, 'whichValues' => $whichValues]); }
/** * * {@inheritdoc} * * @see \ImmutableStateStatusTracker\StorageAdapterInterface::fetchAllJobs() */ public function fetchAllJobs($pageNum = 1) { /** * * @var QueryBuilder $qb */ $qb = $this->_em->createQueryBuilder(); $query = $qb->select('dj')->from('\\ImmutableStateStatusTracker\\StorageAdapter\\Doctrine\\Job', 'dj'); // $qb->setHydrationMode('\Doctrine\ORM\Query::HYDRATE_ARRAY'); $adapter = new DoctrineAdapter(new ORMPaginator($query)); $paginator = new Paginator($adapter); $paginator->setItemCountPerPage(50); $callBackAdapter = new Callback(function ($offset, $itemCountPerPage) use($paginator) { $arrOut = array(); foreach ($paginator->getItemsByPage($offset) as $obj) { $arrOut[] = new Job($obj->getJobId(), $obj->getComponents(), $obj->getCreatedAt()); } return $arrOut; }, function () use($paginator) { return $paginator->getTotalItemCount(); }); $jobPaginator = new Paginator($callBackAdapter); $jobPaginator->setItemCountPerPage(50); return $jobPaginator; }
public function testHasCorrectCountOfAllItemsAfterInit() { $paginator = new Paginator\Paginator(new Adapter\ArrayAdapter(range(1, 101))); $this->assertEquals(101, $paginator->getTotalItemCount()); }
/** * Get the total. * * @return int */ public function getTotal() { return $this->paginator->getTotalItemCount(); }
/** * @return ViewModel */ public function searchAction() { $searchService = $this->getContactSearchService(); $page = $this->params('page', 1); $form = new SearchResult(); $data = array_merge(['query' => '*', 'facet' => []], $this->getRequest()->getQuery()->toArray()); if ($this->getRequest()->isGet()) { $searchService->setSearch($data['query']); if (isset($data['facet'])) { foreach ($data['facet'] as $facetField => $values) { $quotedValues = []; foreach ($values as $value) { $quotedValues[] = sprintf("\"%s\"", $value); } $searchService->addFilterQuery($facetField, implode(' ' . SolariumQuery::QUERY_OPERATOR_OR . ' ', $quotedValues)); } } $form->addSearchResults($searchService->getQuery()->getFacetSet(), $searchService->getResultSet()->getFacetSet()); $form->setData($data); } $paginator = new Paginator(new SolariumPaginator($searchService->getSolrClient(), $searchService->getQuery())); $paginator->setDefaultItemCountPerPage($page === 'all' ? PHP_INT_MAX : 16); $paginator->setCurrentPageNumber($page); $paginator->setPageRange(ceil($paginator->getTotalItemCount() / $paginator->getDefaultItemCountPerPage())); return new ViewModel(['form' => $form, 'paginator' => $paginator, 'queryParams' => http_build_query($data), 'routeName' => $this->getEvent()->getRouteMatch()->getMatchedRouteName(), 'params' => $this->getEvent()->getRouteMatch()->getParams(), 'currentPage' => $page, 'lastPage' => $paginator->getPageRange(), 'showAlwaysFirstAndLast' => true]); }
/** * @param Paginator $paginator * @return array */ public function __invoke(Paginator $paginator) { return ['limit' => $paginator->getItemCountPerPage(), 'offset' => ($paginator->getCurrentPageNumber() - 1) * $paginator->getItemCountPerPage(), 'total' => $paginator->getTotalItemCount()]; }
/** * Create a list of organisations for the current country. * * @param int $page * @throws \InvalidArgumentException * @return string */ public function parseOrganisationList($page) { if (is_null($this->getCountry())) { throw new \InvalidArgumentException("The country cannot be null"); } $organisationQuery = $this->getOrganisationService()->findOrganisationByCountry($this->getCountry(), true, true); $paginator = new Paginator(new PaginatorAdapter(new ORMPaginator($organisationQuery))); $paginator->setDefaultItemCountPerPage($page === 'all' ? PHP_INT_MAX : 15); $paginator->setCurrentPageNumber($page); $paginator->setPageRange(ceil($paginator->getTotalItemCount() / $paginator->getDefaultItemCountPerPage())); return $this->getRenderer()->render('general/partial/list/organisation', ['country' => $this->getCountry(), 'paginator' => $paginator]); }
public function indexAction() { $this->layout('layout/home'); if (isset($_GET['keyword'])) { $str = $_GET['keyword']; $str = trim($str); $list = explode(' ', $str); echo "list : "; var_dump($list); $lenght = sizeof($list); $res = array(); for ($i = 0; $i < sizeof($list); $i++) { $res[$i] = $this->getSearchTable()->search($list[$i]); } //$resfg=$this->getSearchTable()->search($str); // echo "res"; // echo "<pre>"; // print_r($res); // echo "</pre>"; $sort = array(); $sort_num = array(); $i = 0; $j = 0; foreach ($res as $key => $value) { //echo $j."</br>"; $j++; foreach ($value as $val) { //$id=$val->id; $i++; $k = array_search($val, $sort); if ($k) { $sort_num[$k] = $sort_num[$k] + 1; } else { $sort[$i] = $val; $sort_num[$i] = 1; } } } // echo "sort_num"; // echo "<pre>"; // print_r($sort_num); // echo "</pre>"; $ressort = array(); foreach ($sort_num as $key => $val) { if ($val == $lenght) { $l = 0; $ressort[$key] = $sort[$key]; $l++; } } // echo "eclip"; // echo "<pre>"; // print_r($ressort); // echo "</pre>"; $page = $this->params()->fromRoute('page', 0) ? (int) $this->params()->fromRoute('page', 0) : 1; $paginator = new \Zend\Paginator\Paginator(new \Zend\Paginator\Adapter\ArrayAdapter($ressort)); //$paginator = new Paginator(); $paginator->setCurrentPageNumber((int) $page); // set the number of items per page to 10 $paginator->setItemCountPerPage(30); $this->layout()->count = $paginator->getTotalItemCount(); //var_dump($paginator); return new ViewModel(array('paginator' => $paginator)); } }
/** * @return ViewModel */ public function noFinancialAction() { $page = $this->params()->fromRoute('page', 1); $filterPlugin = $this->getOrganisationFilter(); $organisationQuery = $this->getOrganisationService()->findActiveOrganisationWithoutFinancial($filterPlugin->getFilter()); $paginator = new Paginator(new PaginatorAdapter(new ORMPaginator($organisationQuery, false))); $paginator->setDefaultItemCountPerPage($page === 'all' ? PHP_INT_MAX : 15); $paginator->setCurrentPageNumber($page); $paginator->setPageRange(ceil($paginator->getTotalItemCount() / $paginator->getDefaultItemCountPerPage())); $form = new OrganisationFilter($this->getOrganisationService()); $form->setData(['filter' => $filterPlugin->getFilter()]); return new ViewModel(['paginator' => $paginator, 'form' => $form, 'encodedFilter' => urlencode($filterPlugin->getHash()), 'order' => $filterPlugin->getOrder(), 'direction' => $filterPlugin->getDirection()]); }
/** * @param int $page * * @return string */ public function parseProjectList($page = 1) { //if call is not empty $whichProjects = $this->getProjectService()->getOptions()->getProjectHasVersions() ? ProjectService::WHICH_ONLY_ACTIVE : ProjectService::WHICH_ALL; $whichTemplate = $this->getProjectService()->getOptions()->getProjectHasVersions() ? 'project/partial/list/project' : 'project/partial/list/project_eu'; if (!$this->getCallService()->isEmpty()) { $cacheKey = 'call_' . $this->getCallService()->getCall()->getId(); $projectQuery = $this->getProjectService()->findProjectsByCall($this->getCallService()->getCall(), $whichProjects); } elseif (!$this->getProgramService()->isEmpty()) { $cacheKey = 'program_' . $this->getProgramService()->getProgram()->getId(); $projectQuery = $this->getProjectService()->findProjectByProgram($this->getProgramService()->getProgram(), $whichProjects); } else { $cacheKey = 'all'; $projectQuery = $this->getProjectService()->findAllProjects($whichProjects); } //Push the yearSpan into the navigation $this->getServiceLocator()->get('content_update_navigation_service')->updateNavigationWithCalls($this->getRouteMatch()->getParam('docRef'), $this->getCallService()->findNonEmptyCalls(), (int) $this->getRouteMatch()->getParam('call')); $success = false; $config = $this->getConfig(); $key = $config['cache_key'] . '-project-list-html-' . $cacheKey . '-page-' . $page; $html = $this->getCache()->getItem($key, $success); if (!$success) { $paginator = new Paginator(new PaginatorAdapter(new ORMPaginator($projectQuery, false))); $paginator->setDefaultItemCountPerPage($page === 'all' ? PHP_INT_MAX : 15); $paginator->setCurrentPageNumber($page); $paginator->setPageRange(ceil($paginator->getTotalItemCount() / $paginator->getDefaultItemCountPerPage())); $html = $this->getZfcTwigRenderer()->render($whichTemplate, ['paginator' => $paginator]); $this->getCache()->setItem($key, $html); } return $html; }