function select($aql = null, $clause = null) { if ($aql) { $this->aql = $aql; } if ($clause) { $this->clause = $clause; } //pagination settings $default_limit = if_not($this->clause['default_limit'], 25); if (!$_GET['limit' . $this->i]) { $_GET['limit' . $this->i] = $default_limit; } $this->offset = $_GET['page' . $this->i] * $_GET['limit' . $this->i] - $_GET['limit' . $this->i]; $this->clause['limit'] = $_GET['limit' . $this->i]; $this->clause['offset'] = $this->offset; $this->rs = aql::select($this->aql, $this->clause); $this->first_row = $this->offset + 1; $this->last_row = count($this->rs) + $this->first_row - 1; $c = aql::sql($this->aql, $this->clause); $c = sql($c['sql_count']); $this->total_rows = $c->Fields('count'); $this->num_pages = ceil($this->total_rows / $_GET['limit' . $this->i]); return $this->rs; }
/** * Generates the sql queries * This is the last step before execution * @return $this */ public function makeQueries() { $sql = aql::sql($this->aql, array('limit' => $this->limit, 'where' => $this->where, 'order by' => $this->order_by, 'offset' => $this->offset)); $this->count_sql = preg_replace('/\\bcount\\(\\*\\)/', "count(distinct {$sql['primary_table']}.id)", $sql['sql_count']); $this->query_sql = $sql['sql_list']; return $this; }