pagination + sql expressions + frontend improvements
This commit is contained in:
@@ -18,7 +18,7 @@ trait Pagination {
|
||||
return [
|
||||
'page' => new Parameter('page', Parameter::TYPE_INT, true, 1),
|
||||
'count' => new Parameter('count', Parameter::TYPE_INT, true, 25),
|
||||
'orderBy' => new StringType('orderBy', -1, true, $defaultOrderBy, $orderColumns),
|
||||
'orderBy' => new StringType('orderBy', -1, true, $defaultOrderBy, array_values($orderColumns)),
|
||||
'sortOrder' => new StringType('sortOrder', -1, true, $defaultSortOrder, ['asc', 'desc']),
|
||||
];
|
||||
}
|
||||
@@ -36,7 +36,7 @@ trait Pagination {
|
||||
}
|
||||
|
||||
$pageCount = intval(ceil($this->entityCount / $this->pageSize));
|
||||
$this->page = min($this->page, $pageCount); // number of pages changed due to pageSize / filter
|
||||
$this->page = max(1, min($this->page, $pageCount)); // number of pages changed due to pageSize / filter
|
||||
|
||||
$this->result["pagination"] = [
|
||||
"current" => $this->page,
|
||||
@@ -91,18 +91,22 @@ trait Pagination {
|
||||
}
|
||||
|
||||
if ($orderBy) {
|
||||
$handler = $baseQuery->getHandler();
|
||||
$baseTable = $handler->getTableName();
|
||||
$sortColumn = DatabaseEntityHandler::buildColumnName($orderBy);
|
||||
$fullyQualifiedColumn = "$baseTable.$sortColumn";
|
||||
$selectedColumns = $baseQuery->getSelectValues();
|
||||
|
||||
if (in_array($sortColumn, $selectedColumns)) {
|
||||
$sortColumn = array_search($orderBy, $this->paginationOrderColumns);
|
||||
if (is_string($sortColumn)) {
|
||||
$entityQuery->orderBy($sortColumn);
|
||||
} else if (in_array($fullyQualifiedColumn, $selectedColumns)) {
|
||||
$entityQuery->orderBy($fullyQualifiedColumn);
|
||||
} else {
|
||||
$entityQuery->orderBy($orderBy);
|
||||
$handler = $baseQuery->getHandler();
|
||||
$baseTable = $handler->getTableName();
|
||||
$sortColumn = DatabaseEntityHandler::buildColumnName($orderBy);
|
||||
$fullyQualifiedColumn = "$baseTable.$sortColumn";
|
||||
$selectedColumns = $baseQuery->getSelectValues();
|
||||
if (in_array($sortColumn, $selectedColumns)) {
|
||||
$entityQuery->orderBy($sortColumn);
|
||||
} else if (in_array($fullyQualifiedColumn, $selectedColumns)) {
|
||||
$entityQuery->orderBy($fullyQualifiedColumn);
|
||||
} else {
|
||||
$entityQuery->orderBy($orderBy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
28
Core/Driver/SQL/Expression/AbstractFunction.class.php
Normal file
28
Core/Driver/SQL/Expression/AbstractFunction.class.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Core\Driver\SQL\Expression;
|
||||
|
||||
use Core\Driver\SQL\SQL;
|
||||
|
||||
abstract class AbstractFunction extends Expression {
|
||||
|
||||
private string $functionName;
|
||||
private mixed $value;
|
||||
|
||||
public function __construct(string $functionName, mixed $value) {
|
||||
$this->functionName = $functionName;
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
public function getExpression(SQL $sql, array &$params): string {
|
||||
return $this->functionName . "(" . $sql->addValue($this->getValue(), $params) . ")";
|
||||
}
|
||||
|
||||
public function getFunctionName(): string {
|
||||
return $this->functionName;
|
||||
}
|
||||
|
||||
public function getValue(): mixed {
|
||||
return $this->value;
|
||||
}
|
||||
}
|
||||
@@ -2,21 +2,10 @@
|
||||
|
||||
namespace Core\Driver\SQL\Expression;
|
||||
|
||||
use Core\Driver\SQL\SQL;
|
||||
|
||||
class Distinct extends Expression {
|
||||
|
||||
private mixed $value;
|
||||
class Distinct extends AbstractFunction {
|
||||
|
||||
public function __construct(mixed $value) {
|
||||
$this->value = $value;
|
||||
parent::__construct("DISTINCT", $value);
|
||||
}
|
||||
|
||||
public function getValue(): mixed {
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
function getExpression(SQL $sql, array &$params): string {
|
||||
return "DISTINCT(" . $sql->addValue($this->getValue(), $params) . ")";
|
||||
}
|
||||
}
|
||||
11
Core/Driver/SQL/Expression/Lower.class.php
Normal file
11
Core/Driver/SQL/Expression/Lower.class.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Core\Driver\SQL\Expression;
|
||||
|
||||
class Lower extends AbstractFunction {
|
||||
|
||||
public function __construct(mixed $value) {
|
||||
parent::__construct("LOWER", $value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,15 +2,10 @@
|
||||
|
||||
namespace Core\Driver\SQL\Expression;
|
||||
|
||||
use Core\Driver\SQL\SQL;
|
||||
class Sum extends AbstractFunction {
|
||||
|
||||
class Sum extends Alias {
|
||||
|
||||
public function __construct(mixed $value, string $alias) {
|
||||
parent::__construct($value, $alias);
|
||||
public function __construct(mixed $value) {
|
||||
parent::__construct("SUM", $value);
|
||||
}
|
||||
|
||||
protected function addValue(SQL $sql, array &$params): string {
|
||||
return "SUM(" . $sql->addValue($this->getValue(), $params) . ")";
|
||||
}
|
||||
}
|
||||
11
Core/Driver/SQL/Expression/Upper.class.php
Normal file
11
Core/Driver/SQL/Expression/Upper.class.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Core\Driver\SQL\Expression;
|
||||
|
||||
class Upper extends AbstractFunction {
|
||||
|
||||
public function __construct(mixed $value) {
|
||||
parent::__construct("UPPER", $value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -35,6 +35,7 @@ return [
|
||||
"rename" => "Umbenennen",
|
||||
"remove" => "Entfernen",
|
||||
"change" => "Bearbeiten",
|
||||
"close" => "Schließen",
|
||||
"reset" => "Zurücksetzen",
|
||||
"move" => "Verschieben",
|
||||
"delete" => "Löschen",
|
||||
|
||||
@@ -27,6 +27,7 @@ return [
|
||||
"request" => "Request",
|
||||
"cancel" => "Cancel",
|
||||
"confirm" => "Confirm",
|
||||
"close" => "Close",
|
||||
"ok" => "OK",
|
||||
"remove" => "Remove",
|
||||
"change" => "Change",
|
||||
|
||||
@@ -146,12 +146,12 @@ class User extends DatabaseEntity {
|
||||
return !empty($this->fullName) ? $this->fullName : $this->name;
|
||||
}
|
||||
|
||||
public static function buildSQLDisplayName(SQL $sql, string $joinColumn): Alias {
|
||||
public static function buildSQLDisplayName(SQL $sql, string $joinColumn, string $alias = "user"): Alias {
|
||||
return new Alias(
|
||||
$sql->select(new Coalesce(
|
||||
new NullIf(new Column("User.full_name"), ""),
|
||||
new NullIf(new Column("User.name"), ""))
|
||||
)->from("User")->whereEq("User.id", new Column($joinColumn)),
|
||||
"user");
|
||||
$alias);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user