protected function buildViewQuery( array $options )
    {
        // Return empty query string, if no options has been passed
        if ( $options === array() )
        {
            return '';
        }

        $queryString = '?';
        foreach ( $options as $key => $value )
        {
            switch ( $key )
            {
                case 'key':
                case 'startkey':
                case 'endkey':
                    // These values has to be valid JSON encoded strings, so we
                    // just encode the passed data, whatever it is, as CouchDB
                    // may use complex datatypes as a key, like arrays or
                    // objects.
                    $queryString .= $key . '=' . urlencode( json_encode( $value ) );
                    break;

                case 'startkey_docid':
                    // The docidstartkey is handled differently then the other
                    // keys and is just passed as a string, because it always
                    // is and can only be a string.
                    $queryString .= $key . '=' . urlencode( (string) $value );
                    break;

                case 'reduce':
                case 'group':
                case 'update':
                case 'descending':
                case 'include_docs':
                    // These two values may only contain boolean values, passed
                    // as "true" or "false". We just perform a typical PHP
                    // boolean typecast to transform the values.
                    $queryString .= $key . '=' . ( $value ? 'true' : 'false' );
                    break;

                case 'skip':
                case 'group_level':
                    // Theses options accept integers defining the limits of
                    // the query. We try to typecast to int.
                    $queryString .= $key . '=' . ( (int) $value );
                    break;

                case 'count': // CouchDB 0.8. compat
                case 'limit':
                    // Theses options accept integers defining the limits of
                    // the query. We try to typecast to int.
                    $queryString .= 'limit=' . ( (int) $value );
                    break;

                default:
                    throw new phpillowNoSuchPropertyException( $key );
            }

            $queryString .= '&';
        }

        // Return query string, but remove appended '&' first.
        return substr( $queryString, 0, -1 );
    }
protected function buildViewQuery( array $options )
    {
        // Return empty query string, if no options has been passed
        if ( $options === array() )
        {
            return '';
        }

        $queryString = '?';
        foreach ( $options as $key => $value )
        {
            switch ( $key )
            {
                case 'key':
                case 'startkey':
                case 'endkey':
                    // These values has to be valid JSON encoded strings, so we
                    // just encode the passed data, whatever it is, as CouchDB
                    // may use complex datatypes as a key, like arrays or
                    // objects.
                    $queryString .= $key . '=' . urlencode( json_encode( $value ) );
                    break;

                case 'startkey_docid':
                    // The docidstartkey is handled differently then the other
                    // keys and is just passed as a string, because it always
                    // is and can only be a string.
                    $queryString .= $key . '=' . urlencode( (string) $value );
                    break;

                case 'reduce':
                case 'group':
                case 'update':
                case 'descending':
                case 'include_docs':
                    // These two values may only contain boolean values, passed
                    // as "true" or "false". We just perform a typical PHP
                    // boolean typecast to transform the values.
                    $queryString .= $key . '=' . ( $value ? 'true' : 'false' );
                    break;

                case 'skip':
                case 'group_level':
                    // Theses options accept integers defining the limits of
                    // the query. We try to typecast to int.
                    $queryString .= $key . '=' . ( (int) $value );
                    break;

                case 'count': // CouchDB 0.8. compat
                case 'limit':
                    // Theses options accept integers defining the limits of
                    // the query. We try to typecast to int.
                    $queryString .= 'limit=' . ( (int) $value );
                    break;

                default:
                    throw new phpillowNoSuchPropertyException( $key );
            }

            $queryString .= '&';
        }

        // Return query string, but remove appended '&' first.
        return substr( $queryString, 0, -1 );
    }
protected function buildViewQuery ( array $ options ) { // Return empty query string, if no options has been passed if ( $ options === array ( ) ) { return '' ; } $ queryString = '?' ; foreach ( $ options as $ key => $ value ) { switch ( $ key ) { case 'key' : case 'startkey' : case 'endkey' : // These values has to be valid JSON encoded strings, so we // just encode the passed data, whatever it is, as CouchDB // may use complex datatypes as a key, like arrays or // objects. $ queryString .= $ key . '=' . urlencode ( json_encode ( $ value ) ) ; break ; case 'startkey_docid' : // The docidstartkey is handled differently then the other // keys and is just passed as a string, because it always // is and can only be a string. $ queryString .= $ key . '=' . urlencode ( ( string ) $ value ) ; break ; case 'reduce' : case 'group' : case 'update' : case 'descending' : case 'include_docs' : // These two values may only contain boolean values, passed // as "true" or "false". We just perform a typical PHP // boolean typecast to transform the values. $ queryString .= $ key . '=' . ( $ value ? 'true' : 'false' ) ; break ; case 'skip' : case 'group_level' : // Theses options accept integers defining the limits of // the query. We try to typecast to int. $ queryString .= $ key . '=' . ( ( int ) $ value ) ; break ; case 'count' : // CouchDB 0.8. compat case 'limit' : // Theses options accept integers defining the limits of // the query. We try to typecast to int. $ queryString .= 'limit=' . ( ( int ) $ value ) ; break ; default : throw new phpillowNoSuchPropertyException ( $ key ) ; } $ queryString .= '&' ; } // Return query string, but remove appended '&' first. return substr ( $ queryString , 0 , - 1 ) ; }
Build view query string from options

Validates and transformed passed options to limit the view data, to fit
the specifications in the HTTP view API, documented at:
http://wiki.apache.org/couchdb/HTTP_view_API#Querying_Options

@param array $options
@return string
Build view query string from options