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
25 * @see Zend_Gdata_App_FeedEntryParent
27 require_once 'Zend/Gdata/App/FeedEntryParent.php';
30 * @see Zend_Gdata_App_Extension_Content
32 require_once 'Zend/Gdata/App/Extension/Content.php';
35 * @see Zend_Gdata_App_Extension_Edited
37 require_once 'Zend/Gdata/App/Extension/Edited.php';
40 * @see Zend_Gdata_App_Extension_Published
42 require_once 'Zend/Gdata/App/Extension/Published.php';
45 * @see Zend_Gdata_App_Extension_Source
47 require_once 'Zend/Gdata/App/Extension/Source.php';
50 * @see Zend_Gdata_App_Extension_Summary
52 require_once 'Zend/Gdata/App/Extension/Summary.php';
55 * @see Zend_Gdata_App_Extension_Control
57 require_once 'Zend/Gdata/App/Extension/Control.php';
60 * Concrete class for working with Atom entries.
65 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
66 * @license http://framework.zend.com/license/new-bsd New BSD License
68 class Zend_Gdata_App_Entry extends Zend_Gdata_App_FeedEntryParent
72 * Root XML element for Atom entries.
76 protected $_rootElement = 'entry';
79 * Class name for each entry in this feed*
83 protected $_entryClassName = 'Zend_Gdata_App_Entry';
86 * atom:content element
88 * @var Zend_Gdata_App_Extension_Content
90 protected $_content = null;
93 * atom:published element
95 * @var Zend_Gdata_App_Extension_Published
97 protected $_published = null;
100 * atom:source element
102 * @var Zend_Gdata_App_Extension_Source
104 protected $_source = null;
107 * atom:summary element
109 * @var Zend_Gdata_App_Extension_Summary
111 protected $_summary = null;
114 * app:control element
116 * @var Zend_Gdata_App_Extension_Control
118 protected $_control = null;
123 * @var Zend_Gdata_App_Extension_Edited
125 protected $_edited = null;
127 public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
129 $element = parent::getDOM($doc, $majorVersion, $minorVersion);
130 if ($this->_content != null) {
131 $element->appendChild($this->_content->getDOM($element->ownerDocument));
133 if ($this->_published != null) {
134 $element->appendChild($this->_published->getDOM($element->ownerDocument));
136 if ($this->_source != null) {
137 $element->appendChild($this->_source->getDOM($element->ownerDocument));
139 if ($this->_summary != null) {
140 $element->appendChild($this->_summary->getDOM($element->ownerDocument));
142 if ($this->_control != null) {
143 $element->appendChild($this->_control->getDOM($element->ownerDocument));
145 if ($this->_edited != null) {
146 $element->appendChild($this->_edited->getDOM($element->ownerDocument));
151 protected function takeChildFromDOM($child)
153 $absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
154 switch ($absoluteNodeName) {
155 case $this->lookupNamespace('atom') . ':' . 'content':
156 $content = new Zend_Gdata_App_Extension_Content();
157 $content->transferFromDOM($child);
158 $this->_content = $content;
160 case $this->lookupNamespace('atom') . ':' . 'published':
161 $published = new Zend_Gdata_App_Extension_Published();
162 $published->transferFromDOM($child);
163 $this->_published = $published;
165 case $this->lookupNamespace('atom') . ':' . 'source':
166 $source = new Zend_Gdata_App_Extension_Source();
167 $source->transferFromDOM($child);
168 $this->_source = $source;
170 case $this->lookupNamespace('atom') . ':' . 'summary':
171 $summary = new Zend_Gdata_App_Extension_Summary();
172 $summary->transferFromDOM($child);
173 $this->_summary = $summary;
175 case $this->lookupNamespace('app') . ':' . 'control':
176 $control = new Zend_Gdata_App_Extension_Control();
177 $control->transferFromDOM($child);
178 $this->_control = $control;
180 case $this->lookupNamespace('app') . ':' . 'edited':
181 $edited = new Zend_Gdata_App_Extension_Edited();
182 $edited->transferFromDOM($child);
183 $this->_edited = $edited;
186 parent::takeChildFromDOM($child);
192 * Uploads changes in this entry to the server using Zend_Gdata_App
194 * @param string|null $uri The URI to send requests to, or null if $data
196 * @param string|null $className The name of the class that should we
197 * deserializing the server response. If null, then
198 * 'Zend_Gdata_App_Entry' will be used.
199 * @param array $extraHeaders Extra headers to add to the request, as an
200 * array of string-based key/value pairs.
201 * @return Zend_Gdata_App_Entry The updated entry.
202 * @throws Zend_Gdata_App_Exception
204 public function save($uri = null, $className = null, $extraHeaders = array())
206 return $this->getService()->updateEntry($this,
213 * Deletes this entry to the server using the referenced
214 * Zend_Http_Client to do a HTTP DELETE to the edit link stored in this
215 * entry's link collection.
218 * @throws Zend_Gdata_App_Exception
220 public function delete()
222 $this->getService()->delete($this);
226 * Reload the current entry. Returns a new copy of the entry as returned
227 * by the server, or null if no changes exist. This does not
228 * modify the current entry instance.
230 * @param string|null The URI to send requests to, or null if $data
232 * @param string|null The name of the class that should we deserializing
233 * the server response. If null, then 'Zend_Gdata_App_Entry' will
235 * @param array $extraHeaders Extra headers to add to the request, as an
236 * array of string-based key/value pairs.
237 * @return mixed A new instance of the current entry with updated data, or
238 * null if the server reports that no changes have been made.
239 * @throws Zend_Gdata_App_Exception
241 public function reload($uri = null, $className = null, $extraHeaders = array())
244 $editLink = $this->getEditLink();
245 if (($uri === null) && $editLink != null) {
246 $uri = $editLink->getHref();
249 // Set classname to current class, if not otherwise set
250 if ($className === null) {
251 $className = get_class($this);
254 // Append ETag, if present (Gdata v2 and above, only) and doesn't
255 // conflict with existing headers
256 if ($this->_etag != null
257 && !array_key_exists('If-Match', $extraHeaders)
258 && !array_key_exists('If-None-Match', $extraHeaders)) {
259 $extraHeaders['If-None-Match'] = $this->_etag;
262 // If an HTTP 304 status (Not Modified)is returned, then we return
266 $result = $this->service->importUrl($uri, $className, $extraHeaders);
267 } catch (Zend_Gdata_App_HttpException $e) {
268 if ($e->getResponse()->getStatus() != '304')
276 * Gets the value of the atom:content element
278 * @return Zend_Gdata_App_Extension_Content
280 public function getContent()
282 return $this->_content;
286 * Sets the value of the atom:content element
288 * @param Zend_Gdata_App_Extension_Content $value
289 * @return Zend_Gdata_App_Entry Provides a fluent interface
291 public function setContent($value)
293 $this->_content = $value;
298 * Sets the value of the atom:published element
299 * This represents the publishing date for an entry
301 * @return Zend_Gdata_App_Extension_Published
303 public function getPublished()
305 return $this->_published;
309 * Sets the value of the atom:published element
310 * This represents the publishing date for an entry
312 * @param Zend_Gdata_App_Extension_Published $value
313 * @return Zend_Gdata_App_Entry Provides a fluent interface
315 public function setPublished($value)
317 $this->_published = $value;
322 * Gets the value of the atom:source element
324 * @return Zend_Gdata_App_Extension_Source
326 public function getSource()
328 return $this->_source;
332 * Sets the value of the atom:source element
334 * @param Zend_Gdata_App_Extension_Source $value
335 * @return Zend_Gdata_App_Entry Provides a fluent interface
337 public function setSource($value)
339 $this->_source = $value;
344 * Gets the value of the atom:summary element
345 * This represents a textual summary of this entry's content
347 * @return Zend_Gdata_App_Extension_Summary
349 public function getSummary()
351 return $this->_summary;
355 * Sets the value of the atom:summary element
356 * This represents a textual summary of this entry's content
358 * @param Zend_Gdata_App_Extension_Summary $value
359 * @return Zend_Gdata_App_Entry Provides a fluent interface
361 public function setSummary($value)
363 $this->_summary = $value;
368 * Gets the value of the app:control element
370 * @return Zend_Gdata_App_Extension_Control
372 public function getControl()
374 return $this->_control;
378 * Sets the value of the app:control element
380 * @param Zend_Gdata_App_Extension_Control $value
381 * @return Zend_Gdata_App_Entry Provides a fluent interface
383 public function setControl($value)
385 $this->_control = $value;