public function buildCondition($condition)
    {
        static $builders = [
            'NOT' => 'buildNotCondition',
            'AND' => 'buildAndCondition',
            'OR' => 'buildOrCondition',
            'BETWEEN' => 'buildBetweenCondition',
            'NOT BETWEEN' => 'buildBetweenCondition',
            'IN' => 'buildInCondition',
            'NOT IN' => 'buildInCondition',
            'REGEX' => 'buildRegexCondition',
            'LIKE' => 'buildLikeCondition',
        ];

        if (!is_array($condition)) {
            throw new InvalidParamException('Condition should be an array.');
        } elseif (empty($condition)) {
            return [];
        }
        if (isset($condition[0])) { // operator format: operator, operand 1, operand 2, ...
            $operator = strtoupper($condition[0]);
            if (isset($builders[$operator])) {
                $method = $builders[$operator];
            } else {
                $operator = $condition[0];
                $method = 'buildSimpleCondition';
            }
            array_shift($condition);
            return $this->$method($operator, $condition);
        }
        // hash format: 'column1' => 'value1', 'column2' => 'value2', ...
        return $this->buildHashCondition($condition);
    }
public function buildCondition($condition)
    {
        static $builders = [
            'NOT' => 'buildNotCondition',
            'AND' => 'buildAndCondition',
            'OR' => 'buildOrCondition',
            'BETWEEN' => 'buildBetweenCondition',
            'NOT BETWEEN' => 'buildBetweenCondition',
            'IN' => 'buildInCondition',
            'NOT IN' => 'buildInCondition',
            'REGEX' => 'buildRegexCondition',
            'LIKE' => 'buildLikeCondition',
        ];

        if (!is_array($condition)) {
            throw new InvalidParamException('Condition should be an array.');
        } elseif (empty($condition)) {
            return [];
        }
        if (isset($condition[0])) { // operator format: operator, operand 1, operand 2, ...
            $operator = strtoupper($condition[0]);
            if (isset($builders[$operator])) {
                $method = $builders[$operator];
            } else {
                $operator = $condition[0];
                $method = 'buildSimpleCondition';
            }
            array_shift($condition);
            return $this->$method($operator, $condition);
        }
        // hash format: 'column1' => 'value1', 'column2' => 'value2', ...
        return $this->buildHashCondition($condition);
    }
public function buildCondition ( $ condition ) { static $ builders = [ 'NOT' => 'buildNotCondition' , 'AND' => 'buildAndCondition' , 'OR' => 'buildOrCondition' , 'BETWEEN' => 'buildBetweenCondition' , 'NOT BETWEEN' => 'buildBetweenCondition' , 'IN' => 'buildInCondition' , 'NOT IN' => 'buildInCondition' , 'REGEX' => 'buildRegexCondition' , 'LIKE' => 'buildLikeCondition' , ] ; if ( ! is_array ( $ condition ) ) { throw new InvalidParamException ( 'Condition should be an array.' ) ; } elseif ( empty ( $ condition ) ) { return [ ] ; } if ( isset ( $ condition [ 0 ] ) ) { // operator format: operator, operand 1, operand 2, ... $ operator = strtoupper ( $ condition [ 0 ] ) ; if ( isset ( $ builders [ $ operator ] ) ) { $ method = $ builders [ $ operator ] ; } else { $ operator = $ condition [ 0 ] ; $ method = 'buildSimpleCondition' ; } array_shift ( $ condition ) ; return $ this -> $ method ( $ operator , $ condition ) ; } // hash format: 'column1' => 'value1', 'column2' => 'value2', ... return $ this -> buildHashCondition ( $ condition ) ; }
Parses the condition specification and generates the corresponding Mongo condition.
@param array $condition the condition specification. Please refer to [[Query::where()]]
on how to specify a condition.
@return array the generated Mongo condition
@throws InvalidParamException if the condition is in bad format
Parses the condition specification and generates the corresponding Mongo condition .