From 0d85e2f2d3b126b5b4c2f7b4ba06169e7a06f327 Mon Sep 17 00:00:00 2001 From: dp-ifacesoft Date: Thu, 20 Aug 2020 11:12:46 +0300 Subject: [PATCH] fix func --- source/Ice/Core/QueryBuilder.php | 175 ++++++++++++++++--------------- 1 file changed, 89 insertions(+), 86 deletions(-) diff --git a/source/Ice/Core/QueryBuilder.php b/source/Ice/Core/QueryBuilder.php index 7acdcc22..b6579043 100644 --- a/source/Ice/Core/QueryBuilder.php +++ b/source/Ice/Core/QueryBuilder.php @@ -448,6 +448,81 @@ public function getModelClass() return $this->modelClass; } + /** + * Return table alias for model class for query + * + * @return Model|string + * + * @author dp + * + * @version 0.0 + * @since 0.0 + */ + public function getTableAlias() + { + return $this->tableAlias; + } + + /** + * Set in query part where expression 'in (?)' + * + * @param $fieldName + * @param array $fieldValue + * @param array $modelTableData + * @param string $sqlLogical + * @param bool $isUse + * @return QueryBuilder + * @throws Exception + * @author dp + * + * @version 1.13 + * @since 0.0 + */ + public function in($fieldName, $fieldValue, $modelTableData = [], $sqlLogical = QueryBuilder::SQL_LOGICAL_AND, $isUse = true) + { + if (empty($fieldValue)) { + $fieldValue = [0]; + } + + return $this->where( + [$fieldName => $fieldValue], + $modelTableData, + QueryBuilder::SQL_COMPARISON_KEYWORD_IN, + $sqlLogical, + $isUse + ); + } + + /** + * Set in query part where expression 'not in (?)' + * + * @param $fieldName + * @param array $fieldValue + * @param array $modelTableData + * @param string $sqlLogical + * @param bool $isUse + * @return QueryBuilder + * @throws Exception + * @author dp + * + * @version 1.3 + * @since 0.0 + */ + public function notIn($fieldName, array $fieldValue, $modelTableData = [], $sqlLogical = QueryBuilder::SQL_LOGICAL_AND, $isUse = true) + { + if (empty($fieldValue)) { + $fieldValue = [0]; + } + + return $this->where( + [$fieldName => $fieldValue], + $modelTableData, + QueryBuilder::SQL_COMPARISON_KEYWORD_NOT_IN, + $sqlLogical, + $isUse + ); + } + /** * Append cache validate or invalidate tags for this query builder * @@ -837,36 +912,6 @@ public function ne($fieldName, $fieldValue, $modelTableData = [], $sqlLogical = ); } - /** - * Set in query part where expression 'not in (?)' - * - * @param $fieldName - * @param array $fieldValue - * @param array $modelTableData - * @param string $sqlLogical - * @param bool $isUse - * @return QueryBuilder - * @throws Exception - * @author dp - * - * @version 1.3 - * @since 0.0 - */ - public function notIn($fieldName, array $fieldValue, $modelTableData = [], $sqlLogical = QueryBuilder::SQL_LOGICAL_AND, $isUse = true) - { - if (empty($fieldValue)) { - $fieldValue = [0]; - } - - return $this->where( - [$fieldName => $fieldValue], - $modelTableData, - QueryBuilder::SQL_COMPARISON_KEYWORD_NOT_IN, - $sqlLogical, - $isUse - ); - } - /** * Set in query part where expression '== 1' is boolean true(1) * @@ -1105,21 +1150,6 @@ private function join($joinType, $modelTableData, $condition = null) return $this; } - /** - * Return table alias for model class for query - * - * @return Model|string - * - * @author dp - * - * @version 0.0 - * @since 0.0 - */ - public function getTableAlias() - { - return $this->tableAlias; - } - /** * @param $joinType * @param Model $modelTableData @@ -1311,6 +1341,11 @@ private function addJoin($joinType, $modelTableData, array $joins) return false; } + public function getBindParts() + { + return $this->bindParts; + } + /** * Prepare select query part * @@ -1420,11 +1455,6 @@ public function select($fieldName, $fieldAlias = null, $modelTableData = [], $is return $this; } - public function getBindParts() - { - return $this->bindParts; - } - /** * Return query result for select query * @@ -1753,36 +1783,6 @@ public function inPk(array $value, $modelTableData = [], $sqlLogical = QueryBuil return $this->in(reset($pkFieldNames), $value, $modelTableData, $sqlLogical); } - /** - * Set in query part where expression 'in (?)' - * - * @param $fieldName - * @param array $fieldValue - * @param array $modelTableData - * @param string $sqlLogical - * @param bool $isUse - * @return QueryBuilder - * @throws Exception - * @author dp - * - * @version 1.13 - * @since 0.0 - */ - public function in($fieldName, $fieldValue, $modelTableData = [], $sqlLogical = QueryBuilder::SQL_LOGICAL_AND, $isUse = true) - { - if (empty($fieldValue)) { - $fieldValue = [0]; - } - - return $this->where( - [$fieldName => $fieldValue], - $modelTableData, - QueryBuilder::SQL_COMPARISON_KEYWORD_IN, - $sqlLogical, - $isUse - ); - } - /** * Set flag of get count rows * @@ -2173,11 +2173,6 @@ public function afterSelect($trigger, $params = [], $modelClass = null, $isUse = return $this->addTrigger('afterSelect', $trigger, $params, $modelClass, $isUse); } - public function afterSelectCallback($callback, $params = [], $modelClass = null, $isUse = true) - { - return $this->addTrigger('afterSelect', $callback, $params, $modelClass, $isUse); - } - private function addTrigger($type, $trigger, $params, $modelClass, $isUse) { if (!$isUse) { @@ -2195,6 +2190,11 @@ private function addTrigger($type, $trigger, $params, $modelClass, $isUse) return $this; } + public function afterSelectCallback($callback, $params = [], $modelClass = null, $isUse = true) + { + return $this->addTrigger('afterSelect', $callback, $params, $modelClass, $isUse); + } + public function beforeSelect($trigger, $params = [], $modelClass = null, $isUse = true) { return $this->addTrigger('beforeSelect', $trigger, $params, $modelClass, $isUse); @@ -2452,7 +2452,10 @@ public function func($funcName, $argumentString, $modelTableData = []) $this->select( ($fieldName ? strtoupper($fieldName) : '') . '(' . - (isset($fieldColumns[$argumentString]) ? $tableAlias . '.' . $fieldColumns[$argumentString] : $argumentString) . + (isset($fieldColumns[$argumentString]) + ? $tableAlias . '.' . $fieldColumns[$argumentString] + : ($argumentString === '' ? '""' : $argumentString) + ) . ')', $fieldAlias, $modelTableData