Applies a condition based on column-value pairs.

@param array $data data to be filtered
@param array $condition the condition specification

@return array filtered data
431975
public function filterHashCondition(array $data, $condition)
    {
        foreach ($condition as $column => $value) {
            if (is_array($value)) {
                // IN condition
                $data = $this->filterInCondition($data, 'IN', [$column, $value]);
            } else {
                $data = array_filter($data, function ($row) use ($column, $value) {
                    if ($value instanceof \Closure) {
                        return call_user_func($value, $row[$column]);
                    }

                    return $row[$column] == $value;
                });
            }
        }

        return $data;
    }
917806
private function isArray(array $condition)
    {
        // 三项数组
        $sqls = $prepared = $params = [];

        // 看来是有多个条件,逐个处理吧
        foreach ($condition as $key => $value) {
            $ret = $this->item($key, $value);
            if ($ret) {
                list($itemSql, $itemPrepare, $itemParam) = $ret;
                $sqls[] = $itemSql;
                $prepared[] = $itemPrepare;

                if (is_array($itemParam)) {
                    $params = array_merge($params, $itemParam);
                } else {
                    $params[] = $itemParam;
                }
            }
        }

        // 三项数组
        $this->sql = implode(' ' . $this->operator . ' ', $sqls);
        $this->prepare = implode(' ' . $this->operator . ' ', $prepared);
        $this->param = $params;
    }
590525
public function addCondition( $condition )
	{
		if( is_array( $condition ) )
			return $this->addConditions( $condition );
		if( in_array( $condition, $this->conditions ) )
			return FALSE;
		$this->conditions[] = $condition;
		return TRUE;
	}
382986
public function update($table, $data, $condition)
    {
        if ( empty($condition) ) return false;
        $_T_fields = $this->getTableFields($table);
        $_keys = '';
        foreach ( $data as $_key => $_val ) {

            //过滤不存在的字段
            if ( !in_array($_key, $_T_fields) ) continue;
            if ( is_null($_val) ) {
                $_val = 'NULL';
            } else {
                $_val = "'{$_val}'";
            }
            $_keys .= $_keys == ''? "`{$_key}`={$_val}" : ", `{$_key}`={$_val}";
        }
        if ( $_keys !== '' ) {
            $_query = "UPDATE {$table} SET " . $_keys . $condition;
            $result = $this->execute($_query);
            if ( $result != false ) {
                return $result->rowCount() > 0 ? $result->rowCount() : true;
            }
        }
        return false;
    }
237209
public function viewIf($condition, string $name, array $data = null)
    {
        return $this->addIf($condition, View::create($name, $data));
    }
1201423
public function createCondition(array $condition): ConditionInterface
    {
        foreach ($this->conditionNameToConditionClassMap as $conditionName => $conditionClass) {
            if (isset($condition[$conditionName])) {
                return new $conditionClass($condition['command'], $condition[$conditionName]);
            }
        }

        throw new ConditionNotFoundException(sprintf('Condition could not be found, available conditions are: %s', implode(', ', $this->conditionNameToConditionClassMap)));
    }
18257
public static function findAllArray($condition = [],$orderBy = []) {
        return self::find()->where($condition)->asArray()->orderBy($orderBy)->all(static::getDb());
    }
425330
protected function applyRule(array $data)
    {
        if (!($class = ArrayHelper::get($data, 'class')) || !(class_exists($class))) {
            return false;
        }
        $rule = new $class;
        if (!$rule instanceof Rule) {
            return false;
        }
        if ($ruleExist = $this->authManager->getRule($rule->name)) {
            return $ruleExist;
        }
        if ($this->authManager->add($rule)) {
            return $rule;
        }
        return false;
    }
1025546
public function setData(Condition $condition, $data)
    {
        $this->clearData();
        $this->addData($condition, $data);
    }
296781
public static function whereAndClause($tableName, $data, $condition)
    {
        $where = "";
        $counter = 0;
        $arraySize = count($data);

        if ($data !== null) {
            foreach ($data as $key => $value)
            {
                $counter++;
                $columnName = self::checkColumn($tableName, self::sanitize($key));
                $where .= $tableName.'.'.$columnName ." = '".self::sanitize($value)."'";
                if ($arraySize > $counter)
                {
                    $where .= " " . $condition . " ";
                }
            }
        } else {
            $where = "";
        }

        return $where;
    }
191975
public function itemId(array $condition, array $data)
    {
        if (!isset($data['product_id']) || !isset($data['bundle'])) {
            return false;
        }

        if (!is_array($data['bundle'])) {
            $data['bundle'] = explode(',', (string) $data['bundle']);
        }

        return $this->compare($data['bundle'], $condition['value'], $condition['operator']);
    }
262558
protected static function filterValues(array $data)
    {
        $returnValue = array();
        foreach ($data as $d) {
            if ($d !== null) {
                $returnValue[] = $d->getValue();
            } else {
                $returnValue[] = $d;
            }
        }

        return $returnValue;
    }
276445
protected function applyConditions(array $where)
    {
        foreach ($where as $field => $value) {
            if (is_array($value)) {
                list($field, $condition, $val) = $value;
                $this->model = $this->model->where($field, $condition, $val);
            } else {
                $this->model = $this->model->where($field, '=', $value);
            }
        }
    }
577107
public function orIn(string $condition, array $values): self
    {
        return $this->orWith($this->unpackCondition($condition, \count($values)), ...$values);
    }
863259
private function createConditionExpressions(array $conditions) : array
    {
        $conditionExpressions = [];

        foreach ($conditions as $condition) {
            if ($condition instanceof ICondition) {
                $this->addUnnamedPlaceholderValues($condition->getParameters());
                $conditionExpressions[] = $condition->getSql();
            } elseif (is_string($condition)) {
                $conditionExpressions[] = $condition;
            } else {
                throw new InvalidArgumentException('Condition must either be string or ICondition object');
            }
        }

        return $conditionExpressions;
    }
1363732
public function filter(array $data): array
    {
        /* @var array|DataInterface[] $result */
        $result = [];
        foreach ($data as $item) {
            $key = implode('|', $item->getKeys());
            if (!isset($result[$key]) || $result[$key]->getOrder() < $item->getOrder()) {
                $result[$key] = $item;
            }
        }
        return array_values($result);
    }
1233341
public function inc($table, $data, $condition)
    {
        $collection = $this->db->selectCollection($table);
        $result = $collection->update(
            MongoQueryBuilder::where($condition),
            array('$inc' => self::filterData($data)),
            $this->getOptions());

        return ($result['ok'] == 1 && $result['n'] > 0);
    }