Example #1
0
    /**
     * Search
     *
     * @param string $query
     * @param integer $offset
     * @param integer $limit
     * @param string $scope
     * @return Zym_Service_Scribd_Search_Result
     */
    public function search($query, $offset, $limit = null, $scope = null)
    {
        $options = array(
            'query' => $query,
            'num_start' => $offset
        );

        if ($limit !== null) {
            $options['num_results'] = $limit;
        }

        if ($scope !== null) {
            $options['scope'] = $scope;
        }

        $response = $this->_restGet(
        	'docs.search',
            $options
        );

        $return = array();

        $list = (array) $this->_simpleXmlToArray($response->result_set);
        if (isset($list['result']['doc_id'])) {

            // So one exists
            if (isset($response->result_set->result)) {
                $doc      = new self();
                $doc->setScribdClient($this->getScribdClient());

        	    $return[] = $doc->setFromArray($list['result']);
            }
        } else if (is_array($list)) {
            foreach ($list as $results) {
                foreach ($results as $result) {
                    $doc      = new self();
                    $doc->setScribdClient($this->getScribdClient());

            	    $return[] = $doc->setFromArray($result);
                }
            }
        }

        /**
         * @see Zym_Service_Scribd_Search_Result
         */
        require_once 'Zym/Service/Scribd/Search/Result.php';
        $results = new Zym_Service_Scribd_Search_Result(
            $return,
            (int)$response->result_set['totalResultsAvailable'],
            (int)$response->result_set['firstResultPosition']
        );

        return $results;
    }