Merge file:///media/external_data/workspace/web/sport-group
[sport-group.git] / library / Zend / Service / Technorati / CosmosResultSet.php
blob045bac9dee339737ef01de4657b01c962dd54d6e
1 <?php
2 /**
3 * Zend Framework
5 * LICENSE
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.
15 * @category Zend
16 * @package Zend_Service
17 * @subpackage Technorati
18 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
20 * @version $Id: CosmosResultSet.php 16211 2009-06-21 19:23:55Z thomas $
24 /**
25 * @see Zend_Service_Technorati_ResultSet
27 require_once 'Zend/Service/Technorati/ResultSet.php';
30 /**
31 * Represents a Technorati Cosmos query result set.
33 * @category Zend
34 * @package Zend_Service
35 * @subpackage Technorati
36 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
37 * @license http://framework.zend.com/license/new-bsd New BSD License
39 class Zend_Service_Technorati_CosmosResultSet extends Zend_Service_Technorati_ResultSet
41 /**
42 * Technorati weblog url, if queried URL is a valid weblog.
44 * @var Zend_Uri_Http
45 * @access protected
47 protected $_url;
49 /**
50 * Technorati weblog, if queried URL is a valid weblog.
52 * @var Zend_Service_Technorati_Weblog
53 * @access protected
55 protected $_weblog;
57 /**
58 * Number of unique blogs linking this blog
60 * @var integer
61 * @access protected
63 protected $_inboundBlogs;
65 /**
66 * Number of incoming links to this blog
68 * @var integer
69 * @access protected
71 protected $_inboundLinks;
73 /**
74 * Parses the search response and retrieve the results for iteration.
76 * @param DomDocument $dom the ReST fragment for this object
77 * @param array $options query options as associative array
79 public function __construct(DomDocument $dom, $options = array())
81 parent::__construct($dom, $options);
83 $result = $this->_xpath->query('/tapi/document/result/inboundlinks/text()');
84 if ($result->length == 1) $this->_inboundLinks = (int) $result->item(0)->data;
86 $result = $this->_xpath->query('/tapi/document/result/inboundblogs/text()');
87 if ($result->length == 1) $this->_inboundBlogs = (int) $result->item(0)->data;
89 $result = $this->_xpath->query('/tapi/document/result/weblog');
90 if ($result->length == 1) {
91 /**
92 * @see Zend_Service_Technorati_Weblog
94 require_once 'Zend/Service/Technorati/Weblog.php';
95 $this->_weblog = new Zend_Service_Technorati_Weblog($result->item(0));
98 $result = $this->_xpath->query('/tapi/document/result/url/text()');
99 if ($result->length == 1) {
100 try {
101 // fetched URL often doens't include schema
102 // and this issue causes the following line to fail
103 $this->_url = Zend_Service_Technorati_Utils::normalizeUriHttp($result->item(0)->data);
104 } catch(Zend_Service_Technorati_Exception $e) {
105 if ($this->getWeblog() instanceof Zend_Service_Technorati_Weblog) {
106 $this->_url = $this->getWeblog()->getUrl();
111 $this->_totalResultsReturned = (int) $this->_xpath->evaluate("count(/tapi/document/item)");
113 // total number of results depends on query type
114 // for now check only getInboundLinks() and getInboundBlogs() value
115 if ((int) $this->getInboundLinks() > 0) {
116 $this->_totalResultsAvailable = $this->getInboundLinks();
117 } elseif ((int) $this->getInboundBlogs() > 0) {
118 $this->_totalResultsAvailable = $this->getInboundBlogs();
119 } else {
120 $this->_totalResultsAvailable = 0;
126 * Returns the weblog URL.
128 * @return Zend_Uri_Http
130 public function getUrl() {
131 return $this->_url;
135 * Returns the weblog.
137 * @return Zend_Service_Technorati_Weblog
139 public function getWeblog() {
140 return $this->_weblog;
144 * Returns number of unique blogs linking this blog.
146 * @return integer the number of inbound blogs
148 public function getInboundBlogs()
150 return $this->_inboundBlogs;
154 * Returns number of incoming links to this blog.
156 * @return integer the number of inbound links
158 public function getInboundLinks()
160 return $this->_inboundLinks;
164 * Implements Zend_Service_Technorati_ResultSet::current().
166 * @return Zend_Service_Technorati_CosmosResult current result
168 public function current()
171 * @see Zend_Service_Technorati_CosmosResult
173 require_once 'Zend/Service/Technorati/CosmosResult.php';
174 return new Zend_Service_Technorati_CosmosResult($this->_results->item($this->_currentIndex));