Exemple #1
0
 public function testGetsCurrentItemCount()
 {
     $this->_paginator->setItemCountPerPage(10);
     $this->_paginator->setPageRange(10);
     $this->assertEquals(10, $this->_paginator->getCurrentItemCount());
     $this->_paginator->setCurrentPageNumber(11);
     $this->assertEquals(1, $this->_paginator->getCurrentItemCount());
     $this->_paginator->setCurrentPageNumber(1);
 }
 /**
  * Create the page object used in View - paginator method
  * @access public
  * @return object
  */
 public function getPages()
 {
     $pages = new stdClass();
     $pageCount = $this->_paginator->count();
     $pages->pageCount = $pageCount;
     $pages->itemCountPerPage = $this->_itemCountPerPage;
     $pages->first = 1;
     $pages->current = (int) $this->_currentPage;
     $pages->last = $pageCount;
     // Previous and next
     if ($this->_currentPage - 1 > 0) {
         $pages->previous = $this->_currentPage - 1;
     }
     if ($this->_currentPage + 1 <= $pageCount) {
         $pages->next = $this->_currentPage + 1;
     }
     // Pages in range
     $pageRange = $this->_paginator->getPageRange();
     if ($pageRange > $pageCount) {
         $pageRange = $pageCount;
     }
     $delta = ceil($pageRange / 2);
     if ($this->_currentPage - $delta > $pageCount - $pageRange) {
         $lowerBound = $pageCount - $pageRange + 1;
         $upperBound = $pageCount;
     } else {
         if ($this->_currentPage - $delta < 0) {
             $delta = $this->_currentPage;
         }
         $offset = $this->_currentPage - $delta;
         $lowerBound = $offset + 1;
         $upperBound = $offset + $pageRange;
     }
     $pages->pagesInRange = $this->_paginator->getPagesInRange($lowerBound, $upperBound);
     $pages->firstPageInRange = min($pages->pagesInRange);
     $pages->lastPageInRange = max($pages->pagesInRange);
     // Item numbers
     if ($this->_currentItems == null) {
         $this->getCurrentItems();
     }
     if ($this->_currentItems !== null) {
         $pages->currentItemCount = $this->_paginator->getCurrentItemCount();
         $pages->itemCountPerPage = $this->_paginator->getItemCountPerPage();
         $pages->totalItemCount = $this->_paginator->getTotalItemCount();
         $pages->firstItemNumber = ($this->_currentPage - 1) * $this->_paginator->getItemCountPerPage() + 1;
         $pages->lastItemNumber = $pages->firstItemNumber + $pages->currentItemCount - 1;
     }
     return $pages;
 }
Exemple #3
0
 public function testPaginator()
 {
     $countries = My_ShantyMongo_Country::all();
     $this->assertEquals(239, $countries->count());
     $paginator = new Zend_Paginator(new Shanty_Paginator_Adapter_Mongo($countries));
     $paginator->setItemCountPerPage(10);
     $paginator->setCurrentPageNumber(3);
     $this->assertEquals(24, $paginator->count());
     // Count pages
     $this->assertEquals(239, $paginator->getTotalItemCount());
     // count total items
     $this->assertEquals(10, $paginator->getCurrentItemCount());
     // count items on this page
     $paginator->getCurrentItems()->rewind();
     $firstItem = $paginator->getCurrentItems()->current();
     $this->assertEquals($firstItem->code, 'BB');
     $this->assertEquals($firstItem->name, 'Barbados');
 }
 /** The lister function of all guardian articles
  * @access public
  */
 public function indexAction()
 {
     $page = $this->getParam('page');
     $key = md5('pas' . self::QUERY);
     if (!$this->getCache()->test($key)) {
         $guardian = self::GUARDIANAPI_URL . 'search?q=' . urlencode(self::QUERY) . '&page-size=50&order-by=newest&format=' . self::FORMAT . '&show-fields=all&show-tags=all&show-factboxes=all&show-references=all&api-key=' . $this->_apikey;
         $this->_curl->setUri($guardian);
         $this->_curl->getRequest();
         $articles = $this->_curl->getJson();
         $this->getCache()->save($articles);
     } else {
         $articles = $this->getCache()->load($key);
     }
     $results = array();
     foreach ($articles->response->results as $article) {
         if (isset($article->fields->thumbnail)) {
             $image = $article->fields->thumbnail;
         } else {
             $image = null;
         }
         if (isset($article->fields->standfirst)) {
             $stand = $article->fields->standfirst;
         } else {
             $stand = null;
         }
         $tags = array();
         foreach ($article->tags as $k => $v) {
             $tags[$k] = $v;
         }
         if (isset($article->fields->byline)) {
             $byline = $article->fields->byline;
         } else {
             $byline = null;
         }
         $results[] = array('id' => $article->id, 'headline' => $article->fields->headline, 'byline' => $byline, 'image' => $image, 'pubDate' => $article->webPublicationDate, 'content' => $article->fields->body, 'trailtext' => $article->fields->trailText, 'publication' => $article->fields->publication, 'sectionName' => $article->sectionName, 'linkText' => $article->webTitle, 'standfirst' => $stand, 'section' => $article->sectionName, 'url' => $article->webUrl, 'shortUrl' => $article->fields->shortUrl, 'publication' => $article->fields->publication, 'tags' => $tags);
     }
     $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_Array($results));
     Zend_Paginator::setCache($this->getCache());
     if (isset($page) && $page != "") {
         $paginator->setCurrentPageNumber((int) $page);
     }
     $paginator->setItemCountPerPage(20)->setPageRange(10);
     if (in_array($this->_helper->contextSwitch()->getCurrentContext(), array('xml', 'json', 'rss', 'atom'))) {
         $paginated = array();
         foreach ($paginator as $k => $v) {
             $paginated[$k] = $v;
         }
         $data = array('pageNumber' => $paginator->getCurrentPageNumber(), 'total' => number_format($paginator->getTotalItemCount(), 0), 'itemsReturned' => $paginator->getCurrentItemCount(), 'totalPages' => number_format($paginator->getTotalItemCount() / $paginator->getItemCountPerPage(), 0));
         $this->view->data = $data;
         $this->view->guardianStories = array('guardianStory' => $paginated);
     } else {
         $this->view->data = $paginator;
     }
 }
 public function membersAction()
 {
     $page = $this->_getParam('page');
     if (!$this->_cache->test('members')) {
         $query = 'getMps';
         $output = '&output=xml';
         $key = '&key=' . self::TWFYAPIKEY;
         $twfy = self::TWFYURL . $query . $output . $key;
         $data = Zend_Json::fromXml($this->get($twfy), true);
         $data = json_decode($data);
         $this->_cache->save($data);
     } else {
         $data = $this->_cache->load('members');
     }
     $data2 = array();
     foreach ($data->twfy->match as $a) {
         if (in_array($a->constituency, $this->_remove)) {
             unset($a->name);
             unset($a->person_id);
             unset($a->party);
             unset($a->constituency);
         }
         if (isset($a->name)) {
             $data2[] = array('name' => $a->name, 'person_id' => $a->person_id, 'constituency' => $a->constituency, 'party' => $a->party);
         }
     }
     $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_Array($data2));
     if (isset($page) && $page != "") {
         $paginator->setCurrentPageNumber((int) $page);
     }
     $paginator->setItemCountPerPage(40)->setPageRange(10);
     if (in_array($this->_helper->contextSwitch()->getCurrentContext(), array('xml', 'json'))) {
         $data = array('pageNumber' => $paginator->getCurrentPageNumber(), 'total' => number_format($paginator->getTotalItemCount(), 0), 'itemsReturned' => $paginator->getCurrentItemCount(), 'totalPages' => number_format($paginator->getTotalItemCount() / $paginator->getItemCountPerPage(), 0));
         $this->view->data = $data;
         $members = array();
         foreach ($paginator as $k => $v) {
             $members[] = array();
             $members[$k] = $v;
         }
         $this->view->members = $members;
     } else {
         $this->view->data = $paginator;
     }
 }
Exemple #6
0
 /**
  * Job basic for seo.
  * show all the jobs in the city.
  * @return unknown_type
  */
 function businessAction()
 {
     //echo   "jobs";
     $this->view = $this->_setRequiredParamsToView($this->view);
     $this->view->category = $this->_busType;
     try {
         $this->view->business = $this->getBusiness();
         $this->view->form = $this->getForm($this->view->business, $this->view->location);
         //$values['cat4'] = Location::getStateIdByName($this->view->location->getState());
         //	$values['cat5'] = Location::getCityIdByName($this->view->location->getCity());
         $cat1 = $this->view->paramsHolder->cat1;
         $additonalData = $this->_getAdditionalData($this->view);
         $select = $this->view->business->search($this->view->location, $this->view->limit, $this->view->offset, $this->view->paramsHolder->query, $cat1, $this->view->paramsHolder->cat2, $this->view->paramsHolder->cat3, $this->view->paramsHolder->cat4, $this->view->paramsHolder->cat5, $additonalData);
         if (!empty($select)) {
             logfire('------select: ', $select->__toString());
             $adapter = new Zend_Paginator_Adapter_DbTableSelect($select);
             $paginator = new Zend_Paginator($adapter);
             $paginator->setItemCountPerPage($this->view->limit);
             $paginator->setCurrentPageNumber($this->view->offset);
             Zend_Paginator::setDefaultScrollingStyle('Sliding');
             Zend_View_Helper_PaginationControl::setDefaultViewPartial('sitetemplate/_pagination.phtml');
             $this->view->currentItemCount = $paginator->getCurrentItemCount();
             $this->view->itemCount = $paginator->getTotalItemCount();
             //echo '------currentItemCoutn: ' .  $this->view->currentItemCount;
             $paginator->setView($this->view);
             $this->view->postings = $paginator;
             /*
             foreach($this->view->postings as $key=>$value)
             {
             print_r($value);break;
             }
             */
         }
     } catch (Exception $e) {
         echo $e;
     }
     //$this->renderScript('jobs/index.phtml');
     //  	echo Tag::link('jobsbasic',$this->view->location->toStdClass(),'test');
 }