From 7d4ab545058fbea3d2bb07815ee2b588ae300549 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Wed, 22 Feb 2023 11:51:10 +0200 Subject: [PATCH] greatest/least expression --- application/Espo/ORM/Query/Part/Expression.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/application/Espo/ORM/Query/Part/Expression.php b/application/Espo/ORM/Query/Part/Expression.php index fa66cdd0ab..5b47f4ef3e 100644 --- a/application/Espo/ORM/Query/Part/Expression.php +++ b/application/Espo/ORM/Query/Part/Expression.php @@ -48,7 +48,7 @@ class Expression implements WhereItem throw new RuntimeException("Expression can't be empty."); } - if (substr($expression, -1) === ':') { + if (str_ends_with($expression, ':')) { throw new RuntimeException("Expression should not end with `:`."); } @@ -653,6 +653,22 @@ class Expression implements WhereItem return self::composeFunction('ROUND', $number, $precision); } + /** + * 'GREATEST' function. A max value from a list of expressions. + */ + public static function greatest(Expression ...$expressionList): self + { + return self::composeFunction('GREATEST', ...$expressionList); + } + + /** + * 'LEAST' function. A min value from a list of expressions. + */ + public static function least(Expression ...$expressionList): self + { + return self::composeFunction('LEAST', ...$expressionList); + } + /** * 'AND' operator. Returns TRUE if all arguments are TRUE. */