Guest User

Untitled

a guest
May 24th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. <?php
  2. class PaginatedByPage extends Extension {
  3.  
  4. protected $pageNumGetVar = "page";
  5.  
  6. public function PageNums($maxPages = 0){
  7. $ret = new DataObjectSet();
  8. if($maxPages) {
  9. $startPage = ($this->owner->CurrentPage() - floor($maxPages / 2)) - 1;
  10. $endPage = $this->owner->CurrentPage() + floor($maxPages / 2);
  11.  
  12. if($startPage < 0) {
  13. $startPage = 0;
  14. $endPage = $maxPages;
  15. }
  16. if($endPage > $this->owner->TotalPages()) {
  17. $endPage = $this->owner->TotalPages();
  18. $startPage = max(0, $endPage - $maxPages);
  19. }
  20.  
  21. } else {
  22. $startPage = 0;
  23. $endPage = $this->owner->TotalPages();
  24. }
  25.  
  26. for($i=$startPage; $i < $endPage; $i++){
  27. if($i == 0) {
  28. // $link = Should be just the url without parameters.
  29. // How is this done?
  30. $link = HTTP::setGetVar($this->pageNumGetVar, $i + 1);
  31. } else {
  32. $link = HTTP::setGetVar($this->pageNumGetVar, $i + 1);
  33. }
  34. $thePage = new ArrayData(array(
  35. "PageNum" => $i+1,
  36. "Link" => $link,
  37. "CurrentBool" => ($this->owner->CurrentPage() == $i+1)?true:false,
  38. )
  39. );
  40. $ret->push($thePage);
  41. }
  42.  
  43. return $ret;
  44. }
  45.  
  46. public function PageNextLink() {
  47. if($this->owner->pageStart + $this->owner->pageLength < $this->owner->totalSize) {
  48. return HTTP::setGetVar($this->pageNumGetVar, $this->owner->CurrentPage() + 1);
  49. }
  50. }
  51.  
  52. public function PagePrevLink() {
  53. if($this->owner->pageStart - $this->owner->pageLength >= 0) {
  54. return HTTP::setGetVar($this->pageNumGetVar, $this->CurrentPage() - 1);
  55. }
  56. }
  57.  
  58. }
  59. ?>
Add Comment
Please, Sign In to add comment