DailyCountsResultSet.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_Date
  24. */
  25. require_once 'Zend/Date.php';
  26. /**
  27. * @see Zend_Service_Technorati_ResultSet
  28. */
  29. require_once 'Zend/Service/Technorati/ResultSet.php';
  30. /**
  31. * @see Zend_Service_Technorati_Utils
  32. */
  33. require_once 'Zend/Service/Technorati/Utils.php';
  34. /**
  35. * Represents a Technorati Tag query result set.
  36. *
  37. * @category Zend
  38. * @package Zend_Service
  39. * @subpackage Technorati
  40. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  41. * @license http://framework.zend.com/license/new-bsd New BSD License
  42. */
  43. class Zend_Service_Technorati_DailyCountsResultSet extends Zend_Service_Technorati_ResultSet
  44. {
  45. /**
  46. * Technorati search URL for given query.
  47. *
  48. * @var Zend_Uri_Http
  49. * @access protected
  50. */
  51. protected $_searchUrl;
  52. /**
  53. * Number of days for which counts provided.
  54. *
  55. * @var Zend_Service_Technorati_Weblog
  56. * @access protected
  57. */
  58. protected $_days;
  59. /**
  60. * Parses the search response and retrieve the results for iteration.
  61. *
  62. * @param DomDocument $dom the ReST fragment for this object
  63. * @param array $options query options as associative array
  64. */
  65. public function __construct(DomDocument $dom, $options = array())
  66. {
  67. parent::__construct($dom, $options);
  68. // default locale prevent Zend_Date to fail
  69. // when script is executed via shell
  70. // Zend_Locale::setDefault('en');
  71. $result = $this->_xpath->query('/tapi/document/result/days/text()');
  72. if ($result->length == 1) $this->_days = (int) $result->item(0)->data;
  73. $result = $this->_xpath->query('/tapi/document/result/searchurl/text()');
  74. if ($result->length == 1) {
  75. $this->_searchUrl = Zend_Service_Technorati_Utils::normalizeUriHttp($result->item(0)->data);
  76. }
  77. $this->_totalResultsReturned = (int) $this->_xpath->evaluate("count(/tapi/document/items/item)");
  78. $this->_totalResultsAvailable = (int) $this->getDays();
  79. }
  80. /**
  81. * Returns the search URL for given query.
  82. *
  83. * @return Zend_Uri_Http
  84. */
  85. public function getSearchUrl() {
  86. return $this->_searchUrl;
  87. }
  88. /**
  89. * Returns the number of days for which counts provided.
  90. *
  91. * @return int
  92. */
  93. public function getDays() {
  94. return $this->_days;
  95. }
  96. /**
  97. * Implements Zend_Service_Technorati_ResultSet::current().
  98. *
  99. * @return Zend_Service_Technorati_DailyCountsResult current result
  100. */
  101. public function current()
  102. {
  103. /**
  104. * @see Zend_Service_Technorati_DailyCountsResult
  105. */
  106. require_once 'Zend/Service/Technorati/DailyCountsResult.php';
  107. return new Zend_Service_Technorati_DailyCountsResult($this->_results->item($this->_currentIndex));
  108. }
  109. }