Esempio n. 1
0
 public function currentPageResults(int $items_per_page = ITEMS_PER_PAGE) : PageResults
 {
     $page = route()->pageIndex();
     //Two Queries:
     $qs = new QueryStack();
     $counter = new SelectStatement();
     $counter->from($this->table);
     $counter->select("COUNT(*) AS total");
     $counter->where($this->parameters);
     $counter->glue($this->glue);
     $qs->add($counter->prepareSQL());
     $this->limit(($page - 1) * $items_per_page . "," . $items_per_page);
     $qs->add($this->prepareSQL());
     if ($qs->execute()) {
         $pageRes = new PageResults();
         $pageRes->setItemsPerPage($items_per_page);
         $pageRes->setCurrentPage($page);
         $pageRes->setTotalItems($qs->results[0][0]->total);
         $pageRes->setItems($qs->results[1]);
         return $pageRes;
     }
     return new PageResults();
 }
Esempio n. 2
0
 public function currentPageResults(int $items_per_page) : PageResults
 {
     $page = (new Route())->pageIndex();
     //Two Queries:
     $qs = new QueryStack();
     $qs->add(new SQLQuery($this->prepareSQLforCount($this->sql), $this->params));
     //Cleaning up this own
     $this->sql = str_replace("limit", "LIMIT", $this->sql);
     $explode = explode("LIMIT", $this->sql);
     $limitString = ($page - 1) * $items_per_page . "," . $items_per_page;
     $this->sql = $explode[0] . " LIMIT " . $limitString;
     $qs->add($this);
     if ($qs->execute()) {
         $pageRes = new PageResults();
         $pageRes->setItemsPerPage($items_per_page);
         $pageRes->setCurrentPage($page);
         $pageRes->setTotalItems($qs->results[0][0]->total);
         $pageRes->setItems($qs->results[1]);
         return $pageRes;
     }
     return new PageResults();
 }