Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class PaginatedByPage extends Extension {
- protected $pageNumGetVar = "page";
- public function PageNums($maxPages = 0){
- $ret = new DataObjectSet();
- if($maxPages) {
- $startPage = ($this->owner->CurrentPage() - floor($maxPages / 2)) - 1;
- $endPage = $this->owner->CurrentPage() + floor($maxPages / 2);
- if($startPage < 0) {
- $startPage = 0;
- $endPage = $maxPages;
- }
- if($endPage > $this->owner->TotalPages()) {
- $endPage = $this->owner->TotalPages();
- $startPage = max(0, $endPage - $maxPages);
- }
- } else {
- $startPage = 0;
- $endPage = $this->owner->TotalPages();
- }
- for($i=$startPage; $i < $endPage; $i++){
- if($i == 0) {
- // $link = Should be just the url without parameters.
- // How is this done?
- $link = HTTP::setGetVar($this->pageNumGetVar, $i + 1);
- } else {
- $link = HTTP::setGetVar($this->pageNumGetVar, $i + 1);
- }
- $thePage = new ArrayData(array(
- "PageNum" => $i+1,
- "Link" => $link,
- "CurrentBool" => ($this->owner->CurrentPage() == $i+1)?true:false,
- )
- );
- $ret->push($thePage);
- }
- return $ret;
- }
- public function PageNextLink() {
- if($this->owner->pageStart + $this->owner->pageLength < $this->owner->totalSize) {
- return HTTP::setGetVar($this->pageNumGetVar, $this->owner->CurrentPage() + 1);
- }
- }
- public function PagePrevLink() {
- if($this->owner->pageStart - $this->owner->pageLength >= 0) {
- return HTTP::setGetVar($this->pageNumGetVar, $this->CurrentPage() - 1);
- }
- }
- }
- ?>
Add Comment
Please, Sign In to add comment