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 diff --git a/source/Ice/Helper/Type/Array.php b/source/Ice/Helper/Type/Array.php index 553b87d1..a3a1f120 100644 --- a/source/Ice/Helper/Type/Array.php +++ b/source/Ice/Helper/Type/Array.php @@ -290,6 +290,9 @@ public static function diffKey(array $old, array $new, $onlyChanges = false) */ public static function diff($old, $new, $onlyChanges = false) { + $old = array_filter($old); // пока так, кому надо - + $new = array_filter($new); // реализует сравнение null-ов ) + $diff = [ 'added' => [], 'deleted' => []