File indexing completed on 2024-12-22 05:36:46

0001 <?php
0002 
0003 /**
0004  * Zend Framework
0005  *
0006  * LICENSE
0007  *
0008  * This source file is subject to the new BSD license that is bundled
0009  * with this package in the file LICENSE.txt.
0010  * It is also available through the world-wide-web at this URL:
0011  * http://framework.zend.com/license/new-bsd
0012  * If you did not receive a copy of the license and are unable to
0013  * obtain it through the world-wide-web, please send an email
0014  * to license@zend.com so we can send you a copy immediately.
0015  *
0016  * @category   Zend
0017  * @package    Zend_Gdata
0018  * @subpackage Gdata
0019  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0020  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0021  * @version    $Id$
0022  */
0023 
0024 /**
0025  * @see Zend_Gdata
0026  */
0027 // require_once 'Zend/Gdata.php';
0028 
0029 /**
0030  * @see Zend_Gdata_App_Feed
0031  */
0032 // require_once 'Zend/Gdata/App/Feed.php';
0033 
0034 /**
0035  * @see Zend_Gdata_Entry
0036  */
0037 // require_once 'Zend/Gdata/Entry.php';
0038 
0039 /**
0040  * @see Zend_Gdata_Extension_OpenSearchTotalResults
0041  */
0042 // require_once 'Zend/Gdata/Extension/OpenSearchTotalResults.php';
0043 
0044 /**
0045  * @see Zend_Gdata_Extension_OpenSearchStartIndex
0046  */
0047 // require_once 'Zend/Gdata/Extension/OpenSearchStartIndex.php';
0048 
0049 /**
0050  * @see Zend_Gdata_Extension_OpenSearchItemsPerPage
0051  */
0052 // require_once 'Zend/Gdata/Extension/OpenSearchItemsPerPage.php';
0053 
0054 /**
0055  * The Gdata flavor of an Atom Feed
0056  *
0057  * @category   Zend
0058  * @package    Zend_Gdata
0059  * @subpackage Gdata
0060  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0061  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0062  */
0063 class Zend_Gdata_Feed extends Zend_Gdata_App_Feed
0064 {
0065 
0066     /**
0067      * The classname for individual feed elements.
0068      *
0069      * @var string
0070      */
0071     protected $_entryClassName = 'Zend_Gdata_Entry';
0072 
0073     /**
0074      * The openSearch:totalResults element
0075      *
0076      * @var Zend_Gdata_Extension_OpenSearchTotalResults|null
0077      */
0078     protected $_totalResults = null;
0079 
0080     /**
0081      * The openSearch:startIndex element
0082      *
0083      * @var Zend_Gdata_Extension_OpenSearchStartIndex|null
0084      */
0085     protected $_startIndex = null;
0086 
0087     /**
0088      * The openSearch:itemsPerPage element
0089      *
0090      * @var Zend_Gdata_Extension_OpenSearchItemsPerPage|null
0091      */
0092     protected $_itemsPerPage = null;
0093 
0094     public function __construct($element = null)
0095     {
0096         $this->registerAllNamespaces(Zend_Gdata::$namespaces);
0097         parent::__construct($element);
0098     }
0099 
0100     public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
0101     {
0102         $element = parent::getDOM($doc, $majorVersion, $minorVersion);
0103         if ($this->_totalResults != null) {
0104             $element->appendChild($this->_totalResults->getDOM($element->ownerDocument));
0105         }
0106         if ($this->_startIndex != null) {
0107             $element->appendChild($this->_startIndex->getDOM($element->ownerDocument));
0108         }
0109         if ($this->_itemsPerPage != null) {
0110             $element->appendChild($this->_itemsPerPage->getDOM($element->ownerDocument));
0111         }
0112 
0113         // ETags are special. We only support them in protocol >= 2.X.
0114         // This will be duplicated by the HTTP ETag header.
0115         if ($majorVersion >= 2) {
0116             if ($this->_etag != null) {
0117                 $element->setAttributeNS($this->lookupNamespace('gd'),
0118                                          'gd:etag',
0119                                          $this->_etag);
0120             }
0121         }
0122 
0123         return $element;
0124     }
0125 
0126     /**
0127      * Creates individual Entry objects of the appropriate type and
0128      * stores them in the $_entry array based upon DOM data.
0129      *
0130      * @param DOMNode $child The DOMNode to process
0131      */
0132     protected function takeChildFromDOM($child)
0133     {
0134         $absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
0135         switch ($absoluteNodeName) {
0136         case $this->lookupNamespace('openSearch') . ':' . 'totalResults':
0137             $totalResults = new Zend_Gdata_Extension_OpenSearchTotalResults();
0138             $totalResults->transferFromDOM($child);
0139             $this->_totalResults = $totalResults;
0140             break;
0141         case $this->lookupNamespace('openSearch') . ':' . 'startIndex':
0142             $startIndex = new Zend_Gdata_Extension_OpenSearchStartIndex();
0143             $startIndex->transferFromDOM($child);
0144             $this->_startIndex = $startIndex;
0145             break;
0146         case $this->lookupNamespace('openSearch') . ':' . 'itemsPerPage':
0147             $itemsPerPage = new Zend_Gdata_Extension_OpenSearchItemsPerPage();
0148             $itemsPerPage->transferFromDOM($child);
0149             $this->_itemsPerPage = $itemsPerPage;
0150             break;
0151         default:
0152             parent::takeChildFromDOM($child);
0153             break;
0154         }
0155     }
0156 
0157     /**
0158      * Given a DOMNode representing an attribute, tries to map the data into
0159      * instance members.  If no mapping is defined, the name and value are
0160      * stored in an array.
0161      *
0162      * @param DOMNode $attribute The DOMNode attribute needed to be handled
0163      */
0164     protected function takeAttributeFromDOM($attribute)
0165     {
0166         switch ($attribute->localName) {
0167         case 'etag':
0168             // ETags are special, since they can be conveyed by either the
0169             // HTTP ETag header or as an XML attribute.
0170             $etag = $attribute->nodeValue;
0171             if ($this->_etag === null) {
0172                 $this->_etag = $etag;
0173             }
0174             elseif ($this->_etag != $etag) {
0175                 // require_once('Zend/Gdata/App/IOException.php');
0176                 throw new Zend_Gdata_App_IOException("ETag mismatch");
0177             }
0178             break;
0179         default:
0180             parent::takeAttributeFromDOM($attribute);
0181             break;
0182         }
0183     }
0184 
0185     /**
0186      *  Set the value of the totalResults property.
0187      *
0188      * @param Zend_Gdata_Extension_OpenSearchTotalResults|null $value The
0189      *        value of the totalResults property. Use null to unset.
0190      * @return Zend_Gdata_Feed Provides a fluent interface.
0191      */
0192     function setTotalResults($value) {
0193         $this->_totalResults = $value;
0194         return $this;
0195     }
0196 
0197     /**
0198      * Get the value of the totalResults property.
0199      *
0200      * @return Zend_Gdata_Extension_OpenSearchTotalResults|null The value of
0201      *         the totalResults property, or null if unset.
0202      */
0203     function getTotalResults() {
0204         return $this->_totalResults;
0205     }
0206 
0207     /**
0208      * Set the start index property for feed paging.
0209      *
0210      * @param Zend_Gdata_Extension_OpenSearchStartIndex|null $value The value
0211      *        for the startIndex property. Use null to unset.
0212      * @return Zend_Gdata_Feed Provides a fluent interface.
0213      */
0214     function setStartIndex($value) {
0215         $this->_startIndex = $value;
0216         return $this;
0217     }
0218 
0219     /**
0220      * Get the value of the startIndex property.
0221      *
0222      * @return Zend_Gdata_Extension_OpenSearchStartIndex|null The value of the
0223      *         startIndex property, or null if unset.
0224      */
0225     function getStartIndex() {
0226         return $this->_startIndex;
0227     }
0228 
0229     /**
0230      * Set the itemsPerPage property.
0231      *
0232      * @param Zend_Gdata_Extension_OpenSearchItemsPerPage|null $value The
0233      *        value for the itemsPerPage property. Use nul to unset.
0234      * @return Zend_Gdata_Feed Provides a fluent interface.
0235      */
0236     function setItemsPerPage($value) {
0237         $this->_itemsPerPage = $value;
0238         return $this;
0239     }
0240 
0241     /**
0242      * Get the value of the itemsPerPage property.
0243      *
0244      * @return Zend_Gdata_Extension_OpenSearchItemsPerPage|null The value of
0245      *         the itemsPerPage property, or null if unset.
0246      */
0247     function getItemsPerPage() {
0248         return $this->_itemsPerPage;
0249     }
0250 
0251 }