UserOverview

This commit is contained in:
2020-06-15 21:14:59 +02:00
parent e5d504b6c7
commit 7124038b5b
7 changed files with 211 additions and 9 deletions

View File

@@ -12,6 +12,7 @@ class Select extends Query {
private array $conditions;
private array $joins;
private array $orderColumns;
private array $groupColumns;
private bool $sortAscending;
private int $limit;
private int $offset;
@@ -23,6 +24,7 @@ class Select extends Query {
$this->conditions = array();
$this->joins = array();
$this->orderColumns = array();
$this->groupColumns = array();
$this->limit = 0;
$this->offset = 0;
$this->sortAscending = true;
@@ -48,6 +50,11 @@ class Select extends Query {
return $this;
}
public function groupBy(...$columns) {
$this->groupColumns = $columns;
return $this;
}
public function orderBy(...$columns) {
$this->orderColumns = $columns;
return $this;
@@ -85,5 +92,6 @@ class Select extends Query {
public function getOrderBy() { return $this->orderColumns; }
public function getLimit() { return $this->limit; }
public function getOffset() { return $this->offset; }
public function getGroupBy() { return $this->groupColumns; }
}

View File

@@ -180,6 +180,12 @@ abstract class SQL {
}
}
$groupBy = "";
$groupColumns = $select->getGroupBy();
if (!empty($groupColumns)) {
$groupBy = " GROUP BY " . $this->columnName($groupColumns);
}
$orderBy = "";
$orderColumns = $select->getOrderBy();
if (!empty($orderColumns)) {
@@ -189,7 +195,7 @@ abstract class SQL {
$limit = ($select->getLimit() > 0 ? (" LIMIT " . $select->getLimit()) : "");
$offset = ($select->getOffset() > 0 ? (" OFFSET " . $select->getOffset()) : "");
$query = "SELECT $columns FROM $tables$joinStr$where$orderBy$limit$offset";
$query = "SELECT $columns FROM $tables$joinStr$where$groupBy$orderBy$limit$offset";
if($select->dump) { var_dump($query); var_dump($params); }
return $this->execute($query, $params, true);
}
@@ -280,8 +286,9 @@ abstract class SQL {
if (is_null($col)) {
return new Keyword("COUNT(*) AS count");
} else {
$countCol = strtolower(str_replace(".","_", $col)) . "_count";
$col = $this->columnName($col);
return new Keyword("COUNT($col) AS count");
return new Keyword("COUNT($col) AS $countCol");
}
}