code/pagetypes/BrowseCataloguePage.php
/**
     * Searches the catalogue. This is either a browse type search or a search with the keyword the user entered.
     * The record position needs to passed in order for the pagination to work (this is not a page number).
     *
     * @return Array
     */
Searches the catalogue. This is either a browse type search or a search with the keyword the user entered.
The record position needs to passed in order for the pagination to work (this is not a page number).

@return Array
Searches the catalogue . This is either a browse type search or a search with the keyword the user entered . The record position needs to passed in order for the pagination to work ( this is not a page number ) . @return Array
protected function searchCatalogue()
    {
        $mdArray = array();
        $pagination = array();
        $startPosition = (($this->PageNumber - 1) * $this->RecordsPerPage) + 1;
        $outputSchema = $this->OutputSchema ? ' outputSchema="' . $this->OutputSchema . '"' : '';
        $data = '<csw:GetRecords xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml" service="CSW" version="2.0.2" resultType="results"' . $outputSchema . ' maxRecords="' . $this->RecordsPerPage . '" startPosition="' . $startPosition . '">
        <csw:Query typeNames="gmd:MD_Metadata">
            <ogc:SortBy>
                <ogc:SortProperty>
                    <ogc:PropertyName>title</ogc:PropertyName>
                    <ogc:SortOrder>ASC</ogc:SortOrder>
                </ogc:SortProperty>
            </ogc:SortBy>
            <csw:ElementSetName>full</csw:ElementSetName>
            <csw:Constraint version="1.1.0">
                <Filter xmlns="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml">';
        if ($this->SearchKeyword) {
            $wordsToSearchFor = array();
            $wordsToSearchFor = preg_split("/[\s,]+/", $this->SearchKeyword, -1, PREG_SPLIT_NO_EMPTY);
            $data .= "\n<And>\n";
            foreach ($wordsToSearchFor as $word) {
                $data .= '<PropertyIsLike wildCard="%" singleChar="_" escapeChar="\">
                <PropertyName>AnyText</PropertyName>
                <Literal>%' . $word . '%</Literal>
                </PropertyIsLike>' . "\n";
            }
            $data .= "</And>\n";
        }
        $data .= '</Filter>
            </csw:Constraint>
        </csw:Query>
        </csw:GetRecords>';
        try {
            $response = $this->curlRequest($data);
            if ($response->getStatusCode() == 200) {
                $responseBody = $response->getBody();
            } else {
                throw new Exception('Server responsed with error');
            }
        } catch (Exception $e) {
            $this->ErrorMessage = "Sorry, there was an error trying to get the information from the catalogue.";
        }
        if (!$this->ErrorMessage) {
            $responseBody = str_replace("'", "\'", $responseBody);
            $doc  = new DOMDocument();
            try {
                $doc->loadXML($responseBody);
                list($totalRecords, $nextPosition, $mdArray) = $this->{'parseSummary' . $this->Format}($doc);
                $pagination = $this->calculatePagination($totalRecords, $nextPosition);
            } catch (Exception $e) {
                $this->ErrorMessage = "Sorry, there was an error parsing the response from the catalogue.";
            }
        }
        return array($mdArray, $pagination);
    }
protected function searchCatalogue ( ) { $ mdArray = array ( ) ; $ pagination = array ( ) ; $ startPosition = ( ( $ this -> PageNumber - 1 ) * $ this -> RecordsPerPage ) + 1 ; $ outputSchema = $ this -> OutputSchema ? ' outputSchema="' . $ this -> OutputSchema . '"' : '' ; $ data = '<csw:GetRecords xmlns:csw="http://www.opengis.net/cat/csw/2.0.2" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml" service="CSW" version="2.0.2" resultType="results"' . $ outputSchema . ' maxRecords="' . $ this -> RecordsPerPage . '" startPosition="' . $ startPosition . '">
        <csw:Query typeNames="gmd:MD_Metadata">
            <ogc:SortBy>
                <ogc:SortProperty>
                    <ogc:PropertyName>title</ogc:PropertyName>
                    <ogc:SortOrder>ASC</ogc:SortOrder>
                </ogc:SortProperty>
            </ogc:SortBy>
            <csw:ElementSetName>full</csw:ElementSetName>
            <csw:Constraint version="1.1.0">
                <Filter xmlns="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml">' ; if ( $ this -> SearchKeyword ) { $ wordsToSearchFor = array ( ) ; $ wordsToSearchFor = preg_split ( " /[\s,]+/ " , $ this -> SearchKeyword , - 1 , PREG_SPLIT_NO_EMPTY ) ; $ data .= " \n <And> \n " ; foreach ( $ wordsToSearchFor as $ word ) { $ data .= '<PropertyIsLike wildCard="%" singleChar="_" escapeChar="\">
                <PropertyName>AnyText</PropertyName>
                <Literal>%' . $ word . '%</Literal>
                </PropertyIsLike>' . " \n " ; } $ data .= " </And> \n " ; } $ data .= '</Filter>
            </csw:Constraint>
        </csw:Query>
        </csw:GetRecords>' ; try { $ response = $ this -> curlRequest ( $ data ) ; if ( $ response -> getStatusCode ( ) == 200 ) { $ responseBody = $ response -> getBody ( ) ; } else { throw new Exception ( 'Server responsed with error' ) ; } } catch ( Exception $ e ) { $ this -> ErrorMessage = " Sorry, there was an error trying to get the information from the catalogue. " ; } if ( ! $ this -> ErrorMessage ) { $ responseBody = str_replace ( " ' " , " \' " , $ responseBody ) ; $ doc = new DOMDocument ( ) ; try { $ doc -> loadXML ( $ responseBody ) ; list ( $ totalRecords , $ nextPosition , $ mdArray ) = $ this -> { 'parseSummary' . $ this -> Format } ( $ doc ) ; $ pagination = $ this -> calculatePagination ( $ totalRecords , $ nextPosition ) ; } catch ( Exception $ e ) { $ this -> ErrorMessage = " Sorry, there was an error parsing the response from the catalogue. " ; } } return array ( $ mdArray , $ pagination ) ; }
Searches the catalogue.
Searches the catalogue .
// Calculate the start position for the query which is not a page number but record number so // we must convert back from the page number the user sees to a record position. // Put together the xml data for the body of the request which is a POST. // If the user entered a search keyword then we must add items to the constrant. // We must split what the user entered in to individual words // split it by any number of commas or space characters, which include " ", \r, \t, \n and \f // This line from the geocatalogue module. // Get the response which comes back as a restful response. // Escape any single quotes to ensure no issues in the parsing of the XML. // Create a new DOM documents and then load the response as XML in to it. // Try loading the response as XML. // Call function to parse the document. // Call function to calculate the pagination. // Return the records and the pagination information.