Exemplo n.º 1
0
 public function __construct($sql = array())
 {
     $this->sql = $sql;
     // priorize LIMIT clausule
     if (isset($this->sql['limit']) && $this->sql['limit']) {
         $this->limit = $this->sql['limit'];
     }
     $this->total = \Meta\Core\Db::countRows($this->sql);
     $this->pages = max(ceil($this->total / $this->limit), 1);
     $this->page = min($this->pages, filter_input(INPUT_GET, 'page', FILTER_VALIDATE_INT, array('options' => array('default' => 1, 'min_range' => 1))));
     $this->offset = ($this->page - 1) * $this->limit;
     // adjust sql
     $this->sql['limit'] = $this->limit;
     $this->sql['offset'] = $this->offset;
     // define order by
     $this->sortBy = filter_input(INPUT_GET, 'sort');
     $this->sortMode = filter_input(INPUT_GET, 'sortd') == 'desc' ? 'desc' : 'asc';
     if ($this->sortBy) {
         $this->sql['order by'] = $this->sortBy . ' ' . $this->sortMode;
     }
 }