2
0

Entry.php 11 KB

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