Entry.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  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.
  14. *
  15. * @category Zend
  16. * @package Zend_Gdata
  17. * @subpackage App
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_Gdata_App_FeedEntryParent
  24. */
  25. require_once 'Zend/Gdata/App/FeedEntryParent.php';
  26. /**
  27. * @see Zend_Gdata_App_Extension_Content
  28. */
  29. require_once 'Zend/Gdata/App/Extension/Content.php';
  30. /**
  31. * @see Zend_Gdata_App_Extension_Edited
  32. */
  33. require_once 'Zend/Gdata/App/Extension/Edited.php';
  34. /**
  35. * @see Zend_Gdata_App_Extension_Published
  36. */
  37. require_once 'Zend/Gdata/App/Extension/Published.php';
  38. /**
  39. * @see Zend_Gdata_App_Extension_Source
  40. */
  41. require_once 'Zend/Gdata/App/Extension/Source.php';
  42. /**
  43. * @see Zend_Gdata_App_Extension_Summary
  44. */
  45. require_once 'Zend/Gdata/App/Extension/Summary.php';
  46. /**
  47. * @see Zend_Gdata_App_Extension_Control
  48. */
  49. require_once 'Zend/Gdata/App/Extension/Control.php';
  50. /**
  51. * Concrete class for working with Atom entries.
  52. *
  53. * @category Zend
  54. * @package Zend_Gdata
  55. * @subpackage App
  56. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  57. * @license http://framework.zend.com/license/new-bsd New BSD License
  58. */
  59. class Zend_Gdata_App_Entry extends Zend_Gdata_App_FeedEntryParent
  60. {
  61. /**
  62. * Root XML element for Atom entries.
  63. *
  64. * @var string
  65. */
  66. protected $_rootElement = 'entry';
  67. /**
  68. * Class name for each entry in this feed*
  69. *
  70. * @var string
  71. */
  72. protected $_entryClassName = 'Zend_Gdata_App_Entry';
  73. /**
  74. * atom:content element
  75. *
  76. * @var Zend_Gdata_App_Extension_Content
  77. */
  78. protected $_content = null;
  79. /**
  80. * atom:published element
  81. *
  82. * @var Zend_Gdata_App_Extension_Published
  83. */
  84. protected $_published = null;
  85. /**
  86. * atom:source element
  87. *
  88. * @var Zend_Gdata_App_Extension_Source
  89. */
  90. protected $_source = null;
  91. /**
  92. * atom:summary element
  93. *
  94. * @var Zend_Gdata_App_Extension_Summary
  95. */
  96. protected $_summary = null;
  97. /**
  98. * app:control element
  99. *
  100. * @var Zend_Gdata_App_Extension_Control
  101. */
  102. protected $_control = null;
  103. /**
  104. * app:edited element
  105. *
  106. * @var Zend_Gdata_App_Extension_Edited
  107. */
  108. protected $_edited = null;
  109. public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
  110. {
  111. $element = parent::getDOM($doc, $majorVersion, $minorVersion);
  112. if ($this->_content != null) {
  113. $element->appendChild($this->_content->getDOM($element->ownerDocument));
  114. }
  115. if ($this->_published != null) {
  116. $element->appendChild($this->_published->getDOM($element->ownerDocument));
  117. }
  118. if ($this->_source != null) {
  119. $element->appendChild($this->_source->getDOM($element->ownerDocument));
  120. }
  121. if ($this->_summary != null) {
  122. $element->appendChild($this->_summary->getDOM($element->ownerDocument));
  123. }
  124. if ($this->_control != null) {
  125. $element->appendChild($this->_control->getDOM($element->ownerDocument));
  126. }
  127. if ($this->_edited != null) {
  128. $element->appendChild($this->_edited->getDOM($element->ownerDocument));
  129. }
  130. return $element;
  131. }
  132. protected function takeChildFromDOM($child)
  133. {
  134. $absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
  135. switch ($absoluteNodeName) {
  136. case $this->lookupNamespace('atom') . ':' . 'content':
  137. $content = new Zend_Gdata_App_Extension_Content();
  138. $content->transferFromDOM($child);
  139. $this->_content = $content;
  140. break;
  141. case $this->lookupNamespace('atom') . ':' . 'published':
  142. $published = new Zend_Gdata_App_Extension_Published();
  143. $published->transferFromDOM($child);
  144. $this->_published = $published;
  145. break;
  146. case $this->lookupNamespace('atom') . ':' . 'source':
  147. $source = new Zend_Gdata_App_Extension_Source();
  148. $source->transferFromDOM($child);
  149. $this->_source = $source;
  150. break;
  151. case $this->lookupNamespace('atom') . ':' . 'summary':
  152. $summary = new Zend_Gdata_App_Extension_Summary();
  153. $summary->transferFromDOM($child);
  154. $this->_summary = $summary;
  155. break;
  156. case $this->lookupNamespace('app') . ':' . 'control':
  157. $control = new Zend_Gdata_App_Extension_Control();
  158. $control->transferFromDOM($child);
  159. $this->_control = $control;
  160. break;
  161. case $this->lookupNamespace('app') . ':' . 'edited':
  162. $edited = new Zend_Gdata_App_Extension_Edited();
  163. $edited->transferFromDOM($child);
  164. $this->_edited = $edited;
  165. break;
  166. default:
  167. parent::takeChildFromDOM($child);
  168. break;
  169. }
  170. }
  171. /**
  172. * Uploads changes in this entry to the server using Zend_Gdata_App
  173. *
  174. * @param string|null $uri The URI to send requests to, or null if $data
  175. * contains the URI.
  176. * @param string|null $className The name of the class that should we
  177. * deserializing the server response. If null, then
  178. * 'Zend_Gdata_App_Entry' will be used.
  179. * @param array $extraHeaders Extra headers to add to the request, as an
  180. * array of string-based key/value pairs.
  181. * @return Zend_Gdata_App_Entry The updated entry.
  182. * @throws Zend_Gdata_App_Exception
  183. */
  184. public function save($uri = null, $className = null, $extraHeaders = array())
  185. {
  186. return $this->getService()->updateEntry($this,
  187. $uri,
  188. $className,
  189. $extraHeaders);
  190. }
  191. /**
  192. * Deletes this entry to the server using the referenced
  193. * Zend_Http_Client to do a HTTP DELETE to the edit link stored in this
  194. * entry's link collection.
  195. *
  196. * @return void
  197. * @throws Zend_Gdata_App_Exception
  198. */
  199. public function delete()
  200. {
  201. $this->getService()->delete($this);
  202. }
  203. /**
  204. * Reload the current entry. Returns a new copy of the entry as returned
  205. * by the server, or null if no changes exist. This does not
  206. * modify the current entry instance.
  207. *
  208. * @param string|null The URI to send requests to, or null if $data
  209. * contains the URI.
  210. * @param string|null The name of the class that should we deserializing
  211. * the server response. If null, then 'Zend_Gdata_App_Entry' will
  212. * be used.
  213. * @param array $extraHeaders Extra headers to add to the request, as an
  214. * array of string-based key/value pairs.
  215. * @return mixed A new instance of the current entry with updated data, or
  216. * null if the server reports that no changes have been made.
  217. * @throws Zend_Gdata_App_Exception
  218. */
  219. public function reload($uri = null, $className = null, $extraHeaders = array())
  220. {
  221. // Get URI
  222. $editLink = $this->getEditLink();
  223. if (($uri === null) && $editLink != null) {
  224. $uri = $editLink->getHref();
  225. }
  226. // Set classname to current class, if not otherwise set
  227. if ($className === null) {
  228. $className = get_class($this);
  229. }
  230. // Append ETag, if present (Gdata v2 and above, only) and doesn't
  231. // conflict with existing headers
  232. if ($this->_etag != null
  233. && !array_key_exists('If-Match', $extraHeaders)
  234. && !array_key_exists('If-None-Match', $extraHeaders)) {
  235. $extraHeaders['If-None-Match'] = $this->_etag;
  236. }
  237. // If an HTTP 304 status (Not Modified)is returned, then we return
  238. // null.
  239. $result = null;
  240. try {
  241. $result = $this->service->importUrl($uri, $className, $extraHeaders);
  242. } catch (Zend_Gdata_App_HttpException $e) {
  243. if ($e->getResponse()->getStatus() != '304')
  244. throw $e;
  245. }
  246. return $result;
  247. }
  248. /**
  249. * Gets the value of the atom:content element
  250. *
  251. * @return Zend_Gdata_App_Extension_Content
  252. */
  253. public function getContent()
  254. {
  255. return $this->_content;
  256. }
  257. /**
  258. * Sets the value of the atom:content element
  259. *
  260. * @param Zend_Gdata_App_Extension_Content $value
  261. * @return Zend_Gdata_App_Entry Provides a fluent interface
  262. */
  263. public function setContent($value)
  264. {
  265. $this->_content = $value;
  266. return $this;
  267. }
  268. /**
  269. * Sets the value of the atom:published element
  270. * This represents the publishing date for an entry
  271. *
  272. * @return Zend_Gdata_App_Extension_Published
  273. */
  274. public function getPublished()
  275. {
  276. return $this->_published;
  277. }
  278. /**
  279. * Sets the value of the atom:published element
  280. * This represents the publishing date for an entry
  281. *
  282. * @param Zend_Gdata_App_Extension_Published $value
  283. * @return Zend_Gdata_App_Entry Provides a fluent interface
  284. */
  285. public function setPublished($value)
  286. {
  287. $this->_published = $value;
  288. return $this;
  289. }
  290. /**
  291. * Gets the value of the atom:source element
  292. *
  293. * @return Zend_Gdata_App_Extension_Source
  294. */
  295. public function getSource()
  296. {
  297. return $this->_source;
  298. }
  299. /**
  300. * Sets the value of the atom:source element
  301. *
  302. * @param Zend_Gdata_App_Extension_Source $value
  303. * @return Zend_Gdata_App_Entry Provides a fluent interface
  304. */
  305. public function setSource($value)
  306. {
  307. $this->_source = $value;
  308. return $this;
  309. }
  310. /**
  311. * Gets the value of the atom:summary element
  312. * This represents a textual summary of this entry's content
  313. *
  314. * @return Zend_Gdata_App_Extension_Summary
  315. */
  316. public function getSummary()
  317. {
  318. return $this->_summary;
  319. }
  320. /**
  321. * Sets the value of the atom:summary element
  322. * This represents a textual summary of this entry's content
  323. *
  324. * @param Zend_Gdata_App_Extension_Summary $value
  325. * @return Zend_Gdata_App_Entry Provides a fluent interface
  326. */
  327. public function setSummary($value)
  328. {
  329. $this->_summary = $value;
  330. return $this;
  331. }
  332. /**
  333. * Gets the value of the app:control element
  334. *
  335. * @return Zend_Gdata_App_Extension_Control
  336. */
  337. public function getControl()
  338. {
  339. return $this->_control;
  340. }
  341. /**
  342. * Sets the value of the app:control element
  343. *
  344. * @param Zend_Gdata_App_Extension_Control $value
  345. * @return Zend_Gdata_App_Entry Provides a fluent interface
  346. */
  347. public function setControl($value)
  348. {
  349. $this->_control = $value;
  350. return $this;
  351. }
  352. }