public function buildInCondition($operator, $operands)
    {
        if (!isset($operands[0], $operands[1])) {
            throw new InvalidParamException("Operator '$operator' requires two operands.");
        }

        list($column, $values) = $operands;

        $values = (array) $values;
        $operator = $this->normalizeConditionKeyword($operator);

        if (!is_array($column)) {
            $columns = [$column];
            $values = [$column => $values];
        } elseif (count($column) > 1) {
            return $this->buildCompositeInCondition($operator, $column, $values);
        } else {
            $columns = $column;
            $values = [$column[0] => $values];
        }

        $result = [];
        foreach ($columns as $column) {
            if ($column == '_id') {
                $inValues = $this->ensureMongoId($values[$column]);
            } else {
                $inValues = $values[$column];
            }

            $inValues = array_values($inValues);
            if (count($inValues) === 1 && $operator === '$in') {
                $result[$column] = $inValues[0];
            } else {
                $result[$column][$operator] = $inValues;
            }
        }

        return $result;
    }
public function buildInCondition($operator, $operands)
    {
        if (!isset($operands[0], $operands[1])) {
            throw new InvalidParamException("Operator '$operator' requires two operands.");
        }

        list($column, $values) = $operands;

        $values = (array) $values;
        $operator = $this->normalizeConditionKeyword($operator);

        if (!is_array($column)) {
            $columns = [$column];
            $values = [$column => $values];
        } elseif (count($column) > 1) {
            return $this->buildCompositeInCondition($operator, $column, $values);
        } else {
            $columns = $column;
            $values = [$column[0] => $values];
        }

        $result = [];
        foreach ($columns as $column) {
            if ($column == '_id') {
                $inValues = $this->ensureMongoId($values[$column]);
            } else {
                $inValues = $values[$column];
            }

            $inValues = array_values($inValues);
            if (count($inValues) === 1 && $operator === '$in') {
                $result[$column] = $inValues[0];
            } else {
                $result[$column][$operator] = $inValues;
            }
        }

        return $result;
    }
public function buildInCondition ( $ operator , $ operands ) { if ( ! isset ( $ operands [ 0 ] , $ operands [ 1 ] ) ) { throw new InvalidParamException ( "Operator '$operator' requires two operands." ) ; } list ( $ column , $ values ) = $ operands ; $ values = ( array ) $ values ; $ operator = $ this -> normalizeConditionKeyword ( $ operator ) ; if ( ! is_array ( $ column ) ) { $ columns = [ $ column ] ; $ values = [ $ column => $ values ] ; } elseif ( count ( $ column ) > 1 ) { return $ this -> buildCompositeInCondition ( $ operator , $ column , $ values ) ; } else { $ columns = $ column ; $ values = [ $ column [ 0 ] => $ values ] ; } $ result = [ ] ; foreach ( $ columns as $ column ) { if ( $ column == '_id' ) { $ inValues = $ this -> ensureMongoId ( $ values [ $ column ] ) ; } else { $ inValues = $ values [ $ column ] ; } $ inValues = array_values ( $ inValues ) ; if ( count ( $ inValues ) === 1 && $ operator === '$in' ) { $ result [ $ column ] = $ inValues [ 0 ] ; } else { $ result [ $ column ] [ $ operator ] = $ inValues ; } } return $ result ; }
Creates an Mongo condition with the `IN` operator.
@param string $operator the operator to use (e.g. `IN` or `NOT IN`)
@param array $operands the first operand is the column name. If it is an array
a composite IN condition will be generated.
The second operand is an array of values that column value should be among.
@return array the generated Mongo condition.
@throws InvalidParamException if wrong number of operands have been given.
Creates an Mongo condition with the IN operator .