コード例 #1
0
 /**
  * @covers PagingInfo::getTotalPages
  */
 public function testGetTotalPages()
 {
     $recordPerPage = 10;
     $totalRecords = 53;
     $res = 6;
     $this->paging->setRecordsPerPage($recordPerPage);
     $this->paging->setTotalRows($totalRecords);
     $this->assertEquals($res, $this->paging->getTotalPages());
     $recordPerPage = 53;
     $totalRecords = 10;
     $res = 1;
     $this->paging->setRecordsPerPage($recordPerPage);
     $this->paging->setTotalRows($totalRecords);
     $this->assertEquals($res, $this->paging->getTotalPages());
 }
コード例 #2
0
ファイル: Table.php プロジェクト: fruition-sciences/phpfw
 /**
  * Write the links to the various pages, including the 'prev' and 'next'
  * links.
  */
 protected function writePageLinks()
 {
     $linksCount = Config::getInstance()->getInt("tablePaging/maxLinksCount", 10);
     $pageNumParamName = PagingInfoPrefs::getPageNumberParamName($this->getName());
     $recordsPerPageParamName = PagingInfoPrefs::getRecordsPerPageParamName($this->getName());
     $pageLink = new Link(Href::current());
     $pageLink->set("class", "pageNumber");
     $arrowLink = new Link(Href::current());
     $arrowLink->set("class", "arrows");
     $totalPages = $this->pagingInfo->getTotalPages();
     $lastLinkablePage = min($totalPages, $this->pagingInfo->getPageNumber() + $linksCount);
     $lastLinkIsShown = $lastLinkablePage == $totalPages;
     $i = max($this->pagingInfo->getPageNumber() - $linksCount, 0);
     $firstLinkIsShown = $i == 0;
     if (!$firstLinkIsShown) {
         echo $arrowLink->setTitle("First")->setParam($pageNumParamName, 0);
         echo " | ";
     }
     if ($this->pagingInfo->getPageNumber() > 0) {
         echo $arrowLink->setTitle("Previous")->setParam($pageNumParamName, $this->pagingInfo->getPageNumber() - 1);
         echo " ";
     }
     if (!$firstLinkIsShown) {
         echo "... ";
     }
     // If there's only one page available, don't write anything
     if ($i == $lastLinkablePage - 1) {
         echo " ";
         return;
     }
     while ($i < $lastLinkablePage) {
         if ($i == $this->pagingInfo->getPageNumber()) {
             // Write current page number (not a link)
             $currentPageSpan = new HTMLElement("span");
             $currentPageSpan->set("class", "currentPage");
             $currentPageSpan->setBody($i + 1);
             echo $currentPageSpan;
         } else {
             // Write a link to this page
             $pageLink->setParam($pageNumParamName, $i);
             $pageLink->setTitle($i + 1);
             echo $pageLink;
         }
         echo "&nbsp;";
         $i++;
     }
     if (!$lastLinkIsShown) {
         echo "...";
     }
     //echo ($this->pagingInfo->getFirstRecord()+1) . " - " . ($this->pagingInfo->getFirstRecord() + $this->rowCount) . " of " . $this->pagingInfo->getTotalRows();
     if (!$this->pagingInfo->isLastPage()) {
         echo " ";
         echo $arrowLink->setTitle("Next")->setParam($pageNumParamName, $this->pagingInfo->getPageNumber() + 1);
     }
     if (!$lastLinkIsShown) {
         echo "&nbsp;|&nbsp;";
         echo $arrowLink->setTitle("Last")->setParam($pageNumParamName, $totalPages - 1);
     }
 }