web/lib/Zend/Service/Technorati/DailyCountsResultSet.php
changeset 64 162c1de6545a
parent 19 1c2f13fd785c
child 68 ecaf28ffe26e
equal deleted inserted replaced
63:5b37998e522e 64:162c1de6545a
       
     1 <?php
       
     2 /**
       
     3  * Zend Framework
       
     4  *
       
     5  * LICENSE
       
     6  *
       
     7  * This source file is subject to the new BSD license that is bundled
       
     8  * with this package in the file LICENSE.txt.
       
     9  * It is also available through the world-wide-web at this URL:
       
    10  * http://framework.zend.com/license/new-bsd
       
    11  * If you did not receive a copy of the license and are unable to
       
    12  * obtain it through the world-wide-web, please send an email
       
    13  * to license@zend.com so we can send you a copy immediately.
       
    14  *
       
    15  * @category   Zend
       
    16  * @package    Zend_Service
       
    17  * @subpackage Technorati
       
    18  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    20  * @version    $Id: DailyCountsResultSet.php 20096 2010-01-06 02:05:09Z bkarwin $
       
    21  */
       
    22 
       
    23 
       
    24 /**
       
    25  * @see Zend_Date
       
    26  */
       
    27 require_once 'Zend/Date.php';
       
    28 
       
    29 /**
       
    30  * @see Zend_Service_Technorati_ResultSet
       
    31  */
       
    32 require_once 'Zend/Service/Technorati/ResultSet.php';
       
    33 
       
    34 /**
       
    35  * @see Zend_Service_Technorati_Utils
       
    36  */
       
    37 require_once 'Zend/Service/Technorati/Utils.php';
       
    38 
       
    39 
       
    40 /**
       
    41  * Represents a Technorati Tag query result set.
       
    42  *
       
    43  * @category   Zend
       
    44  * @package    Zend_Service
       
    45  * @subpackage Technorati
       
    46  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    47  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    48  */
       
    49 class Zend_Service_Technorati_DailyCountsResultSet extends Zend_Service_Technorati_ResultSet
       
    50 {
       
    51     /**
       
    52      * Technorati search URL for given query.
       
    53      *
       
    54      * @var     Zend_Uri_Http
       
    55      * @access  protected
       
    56      */
       
    57     protected $_searchUrl;
       
    58 
       
    59     /**
       
    60      * Number of days for which counts provided.
       
    61      *
       
    62      * @var     Zend_Service_Technorati_Weblog
       
    63      * @access  protected
       
    64      */
       
    65     protected $_days;
       
    66 
       
    67     /**
       
    68      * Parses the search response and retrieve the results for iteration.
       
    69      *
       
    70      * @param   DomDocument $dom    the ReST fragment for this object
       
    71      * @param   array $options      query options as associative array
       
    72      */
       
    73     public function __construct(DomDocument $dom, $options = array())
       
    74     {
       
    75         parent::__construct($dom, $options);
       
    76 
       
    77         // default locale prevent Zend_Date to fail
       
    78         // when script is executed via shell
       
    79         // Zend_Locale::setDefault('en');
       
    80 
       
    81         $result = $this->_xpath->query('/tapi/document/result/days/text()');
       
    82         if ($result->length == 1) $this->_days = (int) $result->item(0)->data;
       
    83 
       
    84         $result = $this->_xpath->query('/tapi/document/result/searchurl/text()');
       
    85         if ($result->length == 1) {
       
    86             $this->_searchUrl = Zend_Service_Technorati_Utils::normalizeUriHttp($result->item(0)->data);
       
    87         }
       
    88 
       
    89         $this->_totalResultsReturned  = (int) $this->_xpath->evaluate("count(/tapi/document/items/item)");
       
    90         $this->_totalResultsAvailable = (int) $this->getDays();
       
    91     }
       
    92 
       
    93 
       
    94     /**
       
    95      * Returns the search URL for given query.
       
    96      *
       
    97      * @return  Zend_Uri_Http
       
    98      */
       
    99     public function getSearchUrl() {
       
   100         return $this->_searchUrl;
       
   101     }
       
   102 
       
   103     /**
       
   104      * Returns the number of days for which counts provided.
       
   105      *
       
   106      * @return  int
       
   107      */
       
   108     public function getDays() {
       
   109         return $this->_days;
       
   110     }
       
   111 
       
   112     /**
       
   113      * Implements Zend_Service_Technorati_ResultSet::current().
       
   114      *
       
   115      * @return Zend_Service_Technorati_DailyCountsResult current result
       
   116      */
       
   117     public function current()
       
   118     {
       
   119         /**
       
   120          * @see Zend_Service_Technorati_DailyCountsResult
       
   121          */
       
   122         require_once 'Zend/Service/Technorati/DailyCountsResult.php';
       
   123         return new Zend_Service_Technorati_DailyCountsResult($this->_results->item($this->_currentIndex));
       
   124     }
       
   125 }