Example #1
0
 /**
  * From the passed arguements all public variables of this class can be derived and will be set.
  *
  *
  * @param int $currentPage The current page being paginated.
  * @param int $totalItems The total items being paginated.
  * @param int $limit The limit used in the query for results to be paginated.
  */
 public function __construct($currentPage, $totalItems, $limit)
 {
     self::$paginateUsed = true;
     if (\App::configKeyExists('paginate')) {
         $this->format = \App::config('paginate');
     }
     //if
     if ($currentPage == 0) {
         $currentPage = 1;
     }
     //if
     $this->uri = explode('?', $_SERVER['REQUEST_URI'])[0];
     $currentPageFormat = $this->fromFormat($currentPage);
     if (strpos($this->uri, $currentPageFormat) === false) {
         if (substr($this->format, 0, 1) == '/' && substr($this->uri, -1) == '/') {
             $this->uri = rtrim($this->uri, '/');
         }
         //elif
         $this->uri .= $currentPageFormat;
     }
     //if
     //public vars
     $this->currentPage = $currentPage;
     $this->limit = $limit;
     $this->totalItems = $totalItems;
     $this->totalPages = ceil($this->totalItems / $this->limit);
     $this->perPage = $limit;
     $this->total = $this->totalItems;
     $this->first = ($this->currentPage - 1) * $this->limit + 1;
     if ($this->totalPages != $this->currentPage) {
         $this->totalDisplayed = $this->limit;
     } else {
         $this->totalDisplayed = $this->totalItems % $this->limit;
         if ($this->totalDisplayed == 0) {
             $this->totalDisplayed = $this->limit;
         }
         //if
     }
     //el
     $this->last = $this->first + $this->totalDisplayed - 1;
     if ($this->totalPages < $this->currentPage) {
         self::$pageDoesNotExist = true;
     }
     //if
     $this->firstUrl = $this->getPageUrl(1);
     $this->currentUrl = $this->getPageUrl($this->currentPage);
     $this->lastUrl = $this->getPageUrl($this->totalPages);
     if (!self::$pageDoesNotExist) {
         $domain = \App::domain();
         if ($currentPage != 1) {
             $this->prevUrl = $this->getPageUrl($currentPage - 1);
             \View::headExtra("<link rel='prev' href='{$domain}{$this->prevUrl}'>");
         }
         //if
         if ($this->currentPage != $this->totalPages && $this->totalPages != 0) {
             $this->nextUrl = $this->getPageUrl($currentPage + 1);
             \View::headExtra("<link rel='next' href='{$domain}{$this->nextUrl}'>");
         }
         //if
         if ($currentPage == 1 && $this->uri != $this->currentUrl) {
             \View::headExtra("<link rel='canonical' href='{$domain}{$this->currentUrl}'/>");
         }
         //if
     }
     //if
 }