8 * This source file is subject to the new BSD license that is bundled
9 * with this package in the file LICENSE.txt.
10 * It is also available through the world-wide-web at this URL:
11 * http://framework.zend.com/license/new-bsd
12 * If you did not receive a copy of the license and are unable to
13 * obtain it through the world-wide-web, please send an email
14 * to license@zend.com so we can send you a copy immediately.
19 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
20 * @license http://framework.zend.com/license/new-bsd New BSD License
27 require_once 'Zend/Gdata.php';
30 * @see Zend_Gdata_App_Feed
32 require_once 'Zend/Gdata/App/Feed.php';
35 * @see Zend_Gdata_Entry
37 require_once 'Zend/Gdata/Entry.php';
40 * @see Zend_Gdata_Extension_OpenSearchTotalResults
42 require_once 'Zend/Gdata/Extension/OpenSearchTotalResults.php';
45 * @see Zend_Gdata_Extension_OpenSearchStartIndex
47 require_once 'Zend/Gdata/Extension/OpenSearchStartIndex.php';
50 * @see Zend_Gdata_Extension_OpenSearchItemsPerPage
52 require_once 'Zend/Gdata/Extension/OpenSearchItemsPerPage.php';
55 * The Gdata flavor of an Atom Feed
60 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
61 * @license http://framework.zend.com/license/new-bsd New BSD License
63 class Zend_Gdata_Feed extends Zend_Gdata_App_Feed
67 * The classname for individual feed elements.
71 protected $_entryClassName = 'Zend_Gdata_Entry';
74 * The openSearch:totalResults element
76 * @var Zend_Gdata_Extension_OpenSearchTotalResults|null
78 protected $_totalResults = null;
81 * The openSearch:startIndex element
83 * @var Zend_Gdata_Extension_OpenSearchStartIndex|null
85 protected $_startIndex = null;
88 * The openSearch:itemsPerPage element
90 * @var Zend_Gdata_Extension_OpenSearchItemsPerPage|null
92 protected $_itemsPerPage = null;
94 public function __construct($element = null)
96 $this->registerAllNamespaces(Zend_Gdata::$namespaces);
97 parent::__construct($element);
100 public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
102 $element = parent::getDOM($doc, $majorVersion, $minorVersion);
103 if ($this->_totalResults != null) {
104 $element->appendChild($this->_totalResults->getDOM($element->ownerDocument));
106 if ($this->_startIndex != null) {
107 $element->appendChild($this->_startIndex->getDOM($element->ownerDocument));
109 if ($this->_itemsPerPage != null) {
110 $element->appendChild($this->_itemsPerPage->getDOM($element->ownerDocument));
113 // ETags are special. We only support them in protocol >= 2.X.
114 // This will be duplicated by the HTTP ETag header.
115 if ($majorVersion >= 2) {
116 if ($this->_etag != null) {
117 $element->setAttributeNS($this->lookupNamespace('gd'),
127 * Creates individual Entry objects of the appropriate type and
128 * stores them in the $_entry array based upon DOM data.
130 * @param DOMNode $child The DOMNode to process
132 protected function takeChildFromDOM($child)
134 $absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
135 switch ($absoluteNodeName) {
136 case $this->lookupNamespace('openSearch') . ':' . 'totalResults':
137 $totalResults = new Zend_Gdata_Extension_OpenSearchTotalResults();
138 $totalResults->transferFromDOM($child);
139 $this->_totalResults = $totalResults;
141 case $this->lookupNamespace('openSearch') . ':' . 'startIndex':
142 $startIndex = new Zend_Gdata_Extension_OpenSearchStartIndex();
143 $startIndex->transferFromDOM($child);
144 $this->_startIndex = $startIndex;
146 case $this->lookupNamespace('openSearch') . ':' . 'itemsPerPage':
147 $itemsPerPage = new Zend_Gdata_Extension_OpenSearchItemsPerPage();
148 $itemsPerPage->transferFromDOM($child);
149 $this->_itemsPerPage = $itemsPerPage;
152 parent::takeChildFromDOM($child);
158 * Given a DOMNode representing an attribute, tries to map the data into
159 * instance members. If no mapping is defined, the name and value are
160 * stored in an array.
162 * @param DOMNode $attribute The DOMNode attribute needed to be handled
164 protected function takeAttributeFromDOM($attribute)
166 switch ($attribute->localName) {
168 // ETags are special, since they can be conveyed by either the
169 // HTTP ETag header or as an XML attribute.
170 $etag = $attribute->nodeValue;
171 if ($this->_etag === null) {
172 $this->_etag = $etag;
174 elseif ($this->_etag != $etag) {
175 require_once('Zend/Gdata/App/IOException.php');
176 throw new Zend_Gdata_App_IOException("ETag mismatch");
180 parent::takeAttributeFromDOM($attribute);
186 * Set the value of the totalResults property.
188 * @param Zend_Gdata_Extension_OpenSearchTotalResults|null $value The
189 * value of the totalResults property. Use null to unset.
190 * @return Zend_Gdata_Feed Provides a fluent interface.
192 function setTotalResults($value) {
193 $this->_totalResults = $value;
198 * Get the value of the totalResults property.
200 * @return Zend_Gdata_Extension_OpenSearchTotalResults|null The value of
201 * the totalResults property, or null if unset.
203 function getTotalResults() {
204 return $this->_totalResults;
208 * Set the start index property for feed paging.
210 * @param Zend_Gdata_Extension_OpenSearchStartIndex|null $value The value
211 * for the startIndex property. Use null to unset.
212 * @return Zend_Gdata_Feed Provides a fluent interface.
214 function setStartIndex($value) {
215 $this->_startIndex = $value;
220 * Get the value of the startIndex property.
222 * @return Zend_Gdata_Extension_OpenSearchStartIndex|null The value of the
223 * startIndex property, or null if unset.
225 function getStartIndex() {
226 return $this->_startIndex;
230 * Set the itemsPerPage property.
232 * @param Zend_Gdata_Extension_OpenSearchItemsPerPage|null $value The
233 * value for the itemsPerPage property. Use nul to unset.
234 * @return Zend_Gdata_Feed Provides a fluent interface.
236 function setItemsPerPage($value) {
237 $this->_itemsPerPage = $value;
242 * Get the value of the itemsPerPage property.
244 * @return Zend_Gdata_Extension_OpenSearchItemsPerPage|null The value of
245 * the itemsPerPage property, or null if unset.
247 function getItemsPerPage() {
248 return $this->_itemsPerPage;