Example #1
0
 public function __construct(Query $query)
 {
     $this->query = $query;
     // priorize LIMIT clausule
     if (!$query->limit) {
         $query->limit = 20;
         // default pagination rows
     }
     $this->total = $query->countRows();
     $this->pages = max(ceil($this->total / $this->query->limit), 1);
     $this->page = min($this->pages, filter_input(INPUT_GET, 'page', FILTER_VALIDATE_INT, array('options' => array('default' => 1, 'min_range' => 1))));
     $this->query->offset = ($this->page - 1) * $this->query->limit;
     // define order by
     $this->sortBy = filter_input(INPUT_GET, 'sort');
     $this->sortMode = filter_input(INPUT_GET, 'sortd') == 'desc' ? 'desc' : 'asc';
     if ($this->sortBy) {
         $this->query->order = $this->sortBy . ' ' . $this->sortMode;
     }
 }