diff --git a/Core/API/Parameter/Parameter.class.php b/Core/API/Parameter/Parameter.class.php index 70843b6..7ea8ef1 100644 --- a/Core/API/Parameter/Parameter.class.php +++ b/Core/API/Parameter/Parameter.class.php @@ -77,7 +77,12 @@ class Parameter { public function getTypeName(): string { $typeName = Parameter::names[$this->type] ?? "INVALID"; if ($this->choices) { - $typeName .= ", choices: " . json_encode($this->choices); + $typeName .= ", choices=" . json_encode($this->choices); + } + + $format = $this->getSwaggerFormat(); + if ($format && $this->type !== self::TYPE_EMAIL) { + $typeName .= ", format='$format'"; } return $typeName; diff --git a/Core/API/Traits/Pagination.trait.php b/Core/API/Traits/Pagination.trait.php index f46adf9..9a3edeb 100644 --- a/Core/API/Traits/Pagination.trait.php +++ b/Core/API/Traits/Pagination.trait.php @@ -12,7 +12,8 @@ use Core\Objects\DatabaseEntity\User; trait Pagination { - static function getPaginationParameters(array $orderColumns, string $defaultOrderBy = "id", string $defaultSortOrder = "asc"): array { + function getPaginationParameters(array $orderColumns, string $defaultOrderBy = "id", string $defaultSortOrder = "asc"): array { + $this->paginationOrderColumns = $orderColumns; return [ 'page' => new Parameter('page', Parameter::TYPE_INT, true, 1), 'count' => new Parameter('count', Parameter::TYPE_INT, true, 20), diff --git a/Core/Driver/SQL/Expression/Coalesce.class.php b/Core/Driver/SQL/Expression/Coalesce.class.php new file mode 100644 index 0000000..d84a70e --- /dev/null +++ b/Core/Driver/SQL/Expression/Coalesce.class.php @@ -0,0 +1,25 @@ +values = $values; + } + + function getExpression(SQL $sql, array &$params): string { + $values = implode(",", array_map(function ($value) use ($sql, &$params) { + if (is_string($value)) { + return $sql->columnName($value); + } else { + return $sql->addValue($value, $params); + } + }, $this->values)); + return "COALESCE($values)"; + } +} \ No newline at end of file diff --git a/Core/Driver/SQL/Expression/NullIf.class.php b/Core/Driver/SQL/Expression/NullIf.class.php new file mode 100644 index 0000000..42f751a --- /dev/null +++ b/Core/Driver/SQL/Expression/NullIf.class.php @@ -0,0 +1,22 @@ +lhs = $lhs; + $this->rhs = $rhs; + } + + function getExpression(SQL $sql, array &$params): string { + $lhs = $sql->addValue($this->lhs, $params); + $rhs = $sql->addValue($this->rhs, $params); + return "NULLIF($lhs, $rhs)"; + } +} \ No newline at end of file diff --git a/Core/Objects/DatabaseEntity/Controller/DatabaseEntity.class.php b/Core/Objects/DatabaseEntity/Controller/DatabaseEntity.class.php index 1b2f5e6..4a40ad2 100644 --- a/Core/Objects/DatabaseEntity/Controller/DatabaseEntity.class.php +++ b/Core/Objects/DatabaseEntity/Controller/DatabaseEntity.class.php @@ -109,7 +109,7 @@ abstract class DatabaseEntity implements ArrayAccess, JsonSerializable { } } - if ($propertyNames === null) { + if ($propertyNames === null && !empty($this->customData)) { $jsonArray = array_merge($jsonArray, $this->customData); } diff --git a/Core/Objects/DatabaseEntity/Controller/DatabaseEntityHandler.php b/Core/Objects/DatabaseEntity/Controller/DatabaseEntityHandler.php index 859b16f..c194f22 100644 --- a/Core/Objects/DatabaseEntity/Controller/DatabaseEntityHandler.php +++ b/Core/Objects/DatabaseEntity/Controller/DatabaseEntityHandler.php @@ -74,6 +74,9 @@ class DatabaseEntityHandler implements Persistable { } public function init() { + $className = $this->entityClass->getName(); + + $uniqueColumns = self::getAttribute($this->entityClass, Unique::class); if ($uniqueColumns) { $this->constraints[] = new \Core\Driver\SQL\Constraint\Unique($uniqueColumns->getColumns()); diff --git a/Core/Objects/DatabaseEntity/Controller/NMRelation.class.php b/Core/Objects/DatabaseEntity/Controller/NMRelation.class.php index de48ae7..4ed0439 100644 --- a/Core/Objects/DatabaseEntity/Controller/NMRelation.class.php +++ b/Core/Objects/DatabaseEntity/Controller/NMRelation.class.php @@ -58,9 +58,9 @@ class NMRelation implements Persistable { public function getOtherHandler(DatabaseEntityHandler $handler): DatabaseEntityHandler { if ($handler === $this->thisHandler) { - return $this->thisHandler; - } else { return $this->otherHandler; + } else { + return $this->thisHandler; } } } \ No newline at end of file