File indexing completed on 2024-05-26 06:03:02

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 App
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_App_FeedEntryParent
0026  */
0027 // require_once 'Zend/Gdata/App/FeedEntryParent.php';
0028 
0029 /**
0030  * @see Zend_Gdata_App_Extension_Content
0031  */
0032 // require_once 'Zend/Gdata/App/Extension/Content.php';
0033 
0034 /**
0035  * @see Zend_Gdata_App_Extension_Edited
0036  */
0037 // require_once 'Zend/Gdata/App/Extension/Edited.php';
0038 
0039 /**
0040  * @see Zend_Gdata_App_Extension_Published
0041  */
0042 // require_once 'Zend/Gdata/App/Extension/Published.php';
0043 
0044 /**
0045  * @see Zend_Gdata_App_Extension_Source
0046  */
0047 // require_once 'Zend/Gdata/App/Extension/Source.php';
0048 
0049 /**
0050  * @see Zend_Gdata_App_Extension_Summary
0051  */
0052 // require_once 'Zend/Gdata/App/Extension/Summary.php';
0053 
0054 /**
0055  * @see Zend_Gdata_App_Extension_Control
0056  */
0057 // require_once 'Zend/Gdata/App/Extension/Control.php';
0058 
0059 /**
0060  * Concrete class for working with Atom entries.
0061  *
0062  * @category   Zend
0063  * @package    Zend_Gdata
0064  * @subpackage App
0065  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0066  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0067  */
0068 class Zend_Gdata_App_Entry extends Zend_Gdata_App_FeedEntryParent
0069 {
0070 
0071     /**
0072      * Root XML element for Atom entries.
0073      *
0074      * @var string
0075      */
0076     protected $_rootElement = 'entry';
0077 
0078     /**
0079      * Class name for each entry in this feed*
0080      *
0081      * @var string
0082      */
0083     protected $_entryClassName = 'Zend_Gdata_App_Entry';
0084 
0085     /**
0086      * atom:content element
0087      *
0088      * @var Zend_Gdata_App_Extension_Content
0089      */
0090     protected $_content = null;
0091 
0092     /**
0093      * atom:published element
0094      *
0095      * @var Zend_Gdata_App_Extension_Published
0096      */
0097     protected $_published = null;
0098 
0099     /**
0100      * atom:source element
0101      *
0102      * @var Zend_Gdata_App_Extension_Source
0103      */
0104     protected $_source = null;
0105 
0106     /**
0107      * atom:summary element
0108      *
0109      * @var Zend_Gdata_App_Extension_Summary
0110      */
0111     protected $_summary = null;
0112 
0113     /**
0114      * app:control element
0115      *
0116      * @var Zend_Gdata_App_Extension_Control
0117      */
0118     protected $_control = null;
0119 
0120     /**
0121      * app:edited element
0122      *
0123      * @var Zend_Gdata_App_Extension_Edited
0124      */
0125     protected $_edited = null;
0126 
0127     public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
0128     {
0129         $element = parent::getDOM($doc, $majorVersion, $minorVersion);
0130         if ($this->_content != null) {
0131             $element->appendChild($this->_content->getDOM($element->ownerDocument));
0132         }
0133         if ($this->_published != null) {
0134             $element->appendChild($this->_published->getDOM($element->ownerDocument));
0135         }
0136         if ($this->_source != null) {
0137             $element->appendChild($this->_source->getDOM($element->ownerDocument));
0138         }
0139         if ($this->_summary != null) {
0140             $element->appendChild($this->_summary->getDOM($element->ownerDocument));
0141         }
0142         if ($this->_control != null) {
0143             $element->appendChild($this->_control->getDOM($element->ownerDocument));
0144         }
0145         if ($this->_edited != null) {
0146             $element->appendChild($this->_edited->getDOM($element->ownerDocument));
0147         }
0148         return $element;
0149     }
0150 
0151     protected function takeChildFromDOM($child)
0152     {
0153         $absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
0154         switch ($absoluteNodeName) {
0155         case $this->lookupNamespace('atom') . ':' . 'content':
0156             $content = new Zend_Gdata_App_Extension_Content();
0157             $content->transferFromDOM($child);
0158             $this->_content = $content;
0159             break;
0160         case $this->lookupNamespace('atom') . ':' . 'published':
0161             $published = new Zend_Gdata_App_Extension_Published();
0162             $published->transferFromDOM($child);
0163             $this->_published = $published;
0164             break;
0165         case $this->lookupNamespace('atom') . ':' . 'source':
0166             $source = new Zend_Gdata_App_Extension_Source();
0167             $source->transferFromDOM($child);
0168             $this->_source = $source;
0169             break;
0170         case $this->lookupNamespace('atom') . ':' . 'summary':
0171             $summary = new Zend_Gdata_App_Extension_Summary();
0172             $summary->transferFromDOM($child);
0173             $this->_summary = $summary;
0174             break;
0175         case $this->lookupNamespace('app') . ':' . 'control':
0176             $control = new Zend_Gdata_App_Extension_Control();
0177             $control->transferFromDOM($child);
0178             $this->_control = $control;
0179             break;
0180         case $this->lookupNamespace('app') . ':' . 'edited':
0181             $edited = new Zend_Gdata_App_Extension_Edited();
0182             $edited->transferFromDOM($child);
0183             $this->_edited = $edited;
0184             break;
0185         default:
0186             parent::takeChildFromDOM($child);
0187             break;
0188         }
0189     }
0190 
0191     /**
0192      * Uploads changes in this entry to the server using Zend_Gdata_App
0193      *
0194      * @param string|null $uri The URI to send requests to, or null if $data
0195      *        contains the URI.
0196      * @param string|null $className The name of the class that should we
0197      *        deserializing the server response. If null, then
0198      *        'Zend_Gdata_App_Entry' will be used.
0199      * @param array $extraHeaders Extra headers to add to the request, as an
0200      *        array of string-based key/value pairs.
0201      * @return Zend_Gdata_App_Entry The updated entry.
0202      * @throws Zend_Gdata_App_Exception
0203      */
0204     public function save($uri = null, $className = null, $extraHeaders = array())
0205     {
0206         return $this->getService()->updateEntry($this,
0207                                                 $uri,
0208                                                 $className,
0209                                                 $extraHeaders);
0210     }
0211 
0212     /**
0213      * Deletes this entry to the server using the referenced
0214      * Zend_Http_Client to do a HTTP DELETE to the edit link stored in this
0215      * entry's link collection.
0216      *
0217      * @return void
0218      * @throws Zend_Gdata_App_Exception
0219      */
0220     public function delete()
0221     {
0222         $this->getService()->delete($this);
0223     }
0224 
0225     /**
0226      * Reload the current entry. Returns a new copy of the entry as returned
0227      * by the server, or null if no changes exist. This does not
0228      * modify the current entry instance.
0229      *
0230      * @param string|null The URI to send requests to, or null if $data
0231      *        contains the URI.
0232      * @param string|null The name of the class that should we deserializing
0233      *        the server response. If null, then 'Zend_Gdata_App_Entry' will
0234      *        be used.
0235      * @param array $extraHeaders Extra headers to add to the request, as an
0236      *        array of string-based key/value pairs.
0237      * @return mixed A new instance of the current entry with updated data, or
0238      *         null if the server reports that no changes have been made.
0239      * @throws Zend_Gdata_App_Exception
0240      */
0241     public function reload($uri = null, $className = null, $extraHeaders = array())
0242     {
0243         // Get URI
0244         $editLink = $this->getEditLink();
0245         if (($uri === null) && $editLink != null) {
0246             $uri = $editLink->getHref();
0247         }
0248 
0249         // Set classname to current class, if not otherwise set
0250         if ($className === null) {
0251             $className = get_class($this);
0252         }
0253 
0254         // Append ETag, if present (Gdata v2 and above, only) and doesn't
0255         // conflict with existing headers
0256         if ($this->_etag != null
0257                 && !array_key_exists('If-Match', $extraHeaders)
0258                 && !array_key_exists('If-None-Match', $extraHeaders)) {
0259             $extraHeaders['If-None-Match'] = $this->_etag;
0260         }
0261 
0262         // If an HTTP 304 status (Not Modified)is returned, then we return
0263         // null.
0264         $result = null;
0265         try {
0266             $result = $this->service->importUrl($uri, $className, $extraHeaders);
0267         } catch (Zend_Gdata_App_HttpException $e) {
0268             if ($e->getResponse()->getStatus() != '304')
0269                 throw $e;
0270         }
0271 
0272         return $result;
0273     }
0274 
0275     /**
0276      * Gets the value of the atom:content element
0277      *
0278      * @return Zend_Gdata_App_Extension_Content
0279      */
0280     public function getContent()
0281     {
0282         return $this->_content;
0283     }
0284 
0285     /**
0286      * Sets the value of the atom:content element
0287      *
0288      * @param Zend_Gdata_App_Extension_Content $value
0289      * @return Zend_Gdata_App_Entry Provides a fluent interface
0290      */
0291     public function setContent($value)
0292     {
0293         $this->_content = $value;
0294         return $this;
0295     }
0296 
0297     /**
0298      * Sets the value of the atom:published element
0299      * This represents the publishing date for an entry
0300      *
0301      * @return Zend_Gdata_App_Extension_Published
0302      */
0303     public function getPublished()
0304     {
0305         return $this->_published;
0306     }
0307 
0308     /**
0309      * Sets the value of the atom:published element
0310      * This represents the publishing date for an entry
0311      *
0312      * @param Zend_Gdata_App_Extension_Published $value
0313      * @return Zend_Gdata_App_Entry Provides a fluent interface
0314      */
0315     public function setPublished($value)
0316     {
0317         $this->_published = $value;
0318         return $this;
0319     }
0320 
0321     /**
0322      * Gets the value of the atom:source element
0323      *
0324      * @return Zend_Gdata_App_Extension_Source
0325      */
0326     public function getSource()
0327     {
0328         return $this->_source;
0329     }
0330 
0331     /**
0332      * Sets the value of the atom:source element
0333      *
0334      * @param Zend_Gdata_App_Extension_Source $value
0335      * @return Zend_Gdata_App_Entry Provides a fluent interface
0336      */
0337     public function setSource($value)
0338     {
0339         $this->_source = $value;
0340         return $this;
0341     }
0342 
0343     /**
0344      * Gets the value of the atom:summary element
0345      * This represents a textual summary of this entry's content
0346      *
0347      * @return Zend_Gdata_App_Extension_Summary
0348      */
0349     public function getSummary()
0350     {
0351         return $this->_summary;
0352     }
0353 
0354     /**
0355      * Sets the value of the atom:summary element
0356      * This represents a textual summary of this entry's content
0357      *
0358      * @param Zend_Gdata_App_Extension_Summary $value
0359      * @return Zend_Gdata_App_Entry Provides a fluent interface
0360      */
0361     public function setSummary($value)
0362     {
0363         $this->_summary = $value;
0364         return $this;
0365     }
0366 
0367     /**
0368      * Gets the value of the app:control element
0369      *
0370      * @return Zend_Gdata_App_Extension_Control
0371      */
0372     public function getControl()
0373     {
0374         return $this->_control;
0375     }
0376 
0377     /**
0378      * Sets the value of the app:control element
0379      *
0380      * @param Zend_Gdata_App_Extension_Control $value
0381      * @return Zend_Gdata_App_Entry Provides a fluent interface
0382      */
0383     public function setControl($value)
0384     {
0385         $this->_control = $value;
0386         return $this;
0387     }
0388 
0389 }