|
1 <?php |
|
2 |
|
3 /** |
|
4 * Zend Framework |
|
5 * |
|
6 * LICENSE |
|
7 * |
|
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. |
|
15 * |
|
16 * @category Zend |
|
17 * @package Zend_Gdata |
|
18 * @subpackage App |
|
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 |
|
21 * @version $Id: Entry.php 20096 2010-01-06 02:05:09Z bkarwin $ |
|
22 */ |
|
23 |
|
24 /** |
|
25 * @see Zend_Gdata_App_FeedEntryParent |
|
26 */ |
|
27 require_once 'Zend/Gdata/App/FeedEntryParent.php'; |
|
28 |
|
29 /** |
|
30 * @see Zend_Gdata_App_Extension_Content |
|
31 */ |
|
32 require_once 'Zend/Gdata/App/Extension/Content.php'; |
|
33 |
|
34 /** |
|
35 * @see Zend_Gdata_App_Extension_Edited |
|
36 */ |
|
37 require_once 'Zend/Gdata/App/Extension/Edited.php'; |
|
38 |
|
39 /** |
|
40 * @see Zend_Gdata_App_Extension_Published |
|
41 */ |
|
42 require_once 'Zend/Gdata/App/Extension/Published.php'; |
|
43 |
|
44 /** |
|
45 * @see Zend_Gdata_App_Extension_Source |
|
46 */ |
|
47 require_once 'Zend/Gdata/App/Extension/Source.php'; |
|
48 |
|
49 /** |
|
50 * @see Zend_Gdata_App_Extension_Summary |
|
51 */ |
|
52 require_once 'Zend/Gdata/App/Extension/Summary.php'; |
|
53 |
|
54 /** |
|
55 * @see Zend_Gdata_App_Extension_Control |
|
56 */ |
|
57 require_once 'Zend/Gdata/App/Extension/Control.php'; |
|
58 |
|
59 /** |
|
60 * Concrete class for working with Atom entries. |
|
61 * |
|
62 * @category Zend |
|
63 * @package Zend_Gdata |
|
64 * @subpackage App |
|
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 |
|
67 */ |
|
68 class Zend_Gdata_App_Entry extends Zend_Gdata_App_FeedEntryParent |
|
69 { |
|
70 |
|
71 /** |
|
72 * Root XML element for Atom entries. |
|
73 * |
|
74 * @var string |
|
75 */ |
|
76 protected $_rootElement = 'entry'; |
|
77 |
|
78 /** |
|
79 * Class name for each entry in this feed* |
|
80 * |
|
81 * @var string |
|
82 */ |
|
83 protected $_entryClassName = 'Zend_Gdata_App_Entry'; |
|
84 |
|
85 /** |
|
86 * atom:content element |
|
87 * |
|
88 * @var Zend_Gdata_App_Extension_Content |
|
89 */ |
|
90 protected $_content = null; |
|
91 |
|
92 /** |
|
93 * atom:published element |
|
94 * |
|
95 * @var Zend_Gdata_App_Extension_Published |
|
96 */ |
|
97 protected $_published = null; |
|
98 |
|
99 /** |
|
100 * atom:source element |
|
101 * |
|
102 * @var Zend_Gdata_App_Extension_Source |
|
103 */ |
|
104 protected $_source = null; |
|
105 |
|
106 /** |
|
107 * atom:summary element |
|
108 * |
|
109 * @var Zend_Gdata_App_Extension_Summary |
|
110 */ |
|
111 protected $_summary = null; |
|
112 |
|
113 /** |
|
114 * app:control element |
|
115 * |
|
116 * @var Zend_Gdata_App_Extension_Control |
|
117 */ |
|
118 protected $_control = null; |
|
119 |
|
120 /** |
|
121 * app:edited element |
|
122 * |
|
123 * @var Zend_Gdata_App_Extension_Edited |
|
124 */ |
|
125 protected $_edited = null; |
|
126 |
|
127 public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null) |
|
128 { |
|
129 $element = parent::getDOM($doc, $majorVersion, $minorVersion); |
|
130 if ($this->_content != null) { |
|
131 $element->appendChild($this->_content->getDOM($element->ownerDocument)); |
|
132 } |
|
133 if ($this->_published != null) { |
|
134 $element->appendChild($this->_published->getDOM($element->ownerDocument)); |
|
135 } |
|
136 if ($this->_source != null) { |
|
137 $element->appendChild($this->_source->getDOM($element->ownerDocument)); |
|
138 } |
|
139 if ($this->_summary != null) { |
|
140 $element->appendChild($this->_summary->getDOM($element->ownerDocument)); |
|
141 } |
|
142 if ($this->_control != null) { |
|
143 $element->appendChild($this->_control->getDOM($element->ownerDocument)); |
|
144 } |
|
145 if ($this->_edited != null) { |
|
146 $element->appendChild($this->_edited->getDOM($element->ownerDocument)); |
|
147 } |
|
148 return $element; |
|
149 } |
|
150 |
|
151 protected function takeChildFromDOM($child) |
|
152 { |
|
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; |
|
159 break; |
|
160 case $this->lookupNamespace('atom') . ':' . 'published': |
|
161 $published = new Zend_Gdata_App_Extension_Published(); |
|
162 $published->transferFromDOM($child); |
|
163 $this->_published = $published; |
|
164 break; |
|
165 case $this->lookupNamespace('atom') . ':' . 'source': |
|
166 $source = new Zend_Gdata_App_Extension_Source(); |
|
167 $source->transferFromDOM($child); |
|
168 $this->_source = $source; |
|
169 break; |
|
170 case $this->lookupNamespace('atom') . ':' . 'summary': |
|
171 $summary = new Zend_Gdata_App_Extension_Summary(); |
|
172 $summary->transferFromDOM($child); |
|
173 $this->_summary = $summary; |
|
174 break; |
|
175 case $this->lookupNamespace('app') . ':' . 'control': |
|
176 $control = new Zend_Gdata_App_Extension_Control(); |
|
177 $control->transferFromDOM($child); |
|
178 $this->_control = $control; |
|
179 break; |
|
180 case $this->lookupNamespace('app') . ':' . 'edited': |
|
181 $edited = new Zend_Gdata_App_Extension_Edited(); |
|
182 $edited->transferFromDOM($child); |
|
183 $this->_edited = $edited; |
|
184 break; |
|
185 default: |
|
186 parent::takeChildFromDOM($child); |
|
187 break; |
|
188 } |
|
189 } |
|
190 |
|
191 /** |
|
192 * Uploads changes in this entry to the server using Zend_Gdata_App |
|
193 * |
|
194 * @param string|null $uri The URI to send requests to, or null if $data |
|
195 * contains the URI. |
|
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 |
|
203 */ |
|
204 public function save($uri = null, $className = null, $extraHeaders = array()) |
|
205 { |
|
206 return $this->getService()->updateEntry($this, |
|
207 $uri, |
|
208 $className, |
|
209 $extraHeaders); |
|
210 } |
|
211 |
|
212 /** |
|
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. |
|
216 * |
|
217 * @return void |
|
218 * @throws Zend_Gdata_App_Exception |
|
219 */ |
|
220 public function delete() |
|
221 { |
|
222 $this->getService()->delete($this); |
|
223 } |
|
224 |
|
225 /** |
|
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. |
|
229 * |
|
230 * @param string|null The URI to send requests to, or null if $data |
|
231 * contains the URI. |
|
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 |
|
234 * be used. |
|
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 |
|
240 */ |
|
241 public function reload($uri = null, $className = null, $extraHeaders = array()) |
|
242 { |
|
243 // Get URI |
|
244 $editLink = $this->getEditLink(); |
|
245 if (($uri === null) && $editLink != null) { |
|
246 $uri = $editLink->getHref(); |
|
247 } |
|
248 |
|
249 // Set classname to current class, if not otherwise set |
|
250 if ($className === null) { |
|
251 $className = get_class($this); |
|
252 } |
|
253 |
|
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; |
|
260 } |
|
261 |
|
262 // If an HTTP 304 status (Not Modified)is returned, then we return |
|
263 // null. |
|
264 $result = null; |
|
265 try { |
|
266 $result = $this->service->importUrl($uri, $className, $extraHeaders); |
|
267 } catch (Zend_Gdata_App_HttpException $e) { |
|
268 if ($e->getResponse()->getStatus() != '304') |
|
269 throw $e; |
|
270 } |
|
271 |
|
272 return $result; |
|
273 } |
|
274 |
|
275 /** |
|
276 * Gets the value of the atom:content element |
|
277 * |
|
278 * @return Zend_Gdata_App_Extension_Content |
|
279 */ |
|
280 public function getContent() |
|
281 { |
|
282 return $this->_content; |
|
283 } |
|
284 |
|
285 /** |
|
286 * Sets the value of the atom:content element |
|
287 * |
|
288 * @param Zend_Gdata_App_Extension_Content $value |
|
289 * @return Zend_Gdata_App_Entry Provides a fluent interface |
|
290 */ |
|
291 public function setContent($value) |
|
292 { |
|
293 $this->_content = $value; |
|
294 return $this; |
|
295 } |
|
296 |
|
297 /** |
|
298 * Sets the value of the atom:published element |
|
299 * This represents the publishing date for an entry |
|
300 * |
|
301 * @return Zend_Gdata_App_Extension_Published |
|
302 */ |
|
303 public function getPublished() |
|
304 { |
|
305 return $this->_published; |
|
306 } |
|
307 |
|
308 /** |
|
309 * Sets the value of the atom:published element |
|
310 * This represents the publishing date for an entry |
|
311 * |
|
312 * @param Zend_Gdata_App_Extension_Published $value |
|
313 * @return Zend_Gdata_App_Entry Provides a fluent interface |
|
314 */ |
|
315 public function setPublished($value) |
|
316 { |
|
317 $this->_published = $value; |
|
318 return $this; |
|
319 } |
|
320 |
|
321 /** |
|
322 * Gets the value of the atom:source element |
|
323 * |
|
324 * @return Zend_Gdata_App_Extension_Source |
|
325 */ |
|
326 public function getSource() |
|
327 { |
|
328 return $this->_source; |
|
329 } |
|
330 |
|
331 /** |
|
332 * Sets the value of the atom:source element |
|
333 * |
|
334 * @param Zend_Gdata_App_Extension_Source $value |
|
335 * @return Zend_Gdata_App_Entry Provides a fluent interface |
|
336 */ |
|
337 public function setSource($value) |
|
338 { |
|
339 $this->_source = $value; |
|
340 return $this; |
|
341 } |
|
342 |
|
343 /** |
|
344 * Gets the value of the atom:summary element |
|
345 * This represents a textual summary of this entry's content |
|
346 * |
|
347 * @return Zend_Gdata_App_Extension_Summary |
|
348 */ |
|
349 public function getSummary() |
|
350 { |
|
351 return $this->_summary; |
|
352 } |
|
353 |
|
354 /** |
|
355 * Sets the value of the atom:summary element |
|
356 * This represents a textual summary of this entry's content |
|
357 * |
|
358 * @param Zend_Gdata_App_Extension_Summary $value |
|
359 * @return Zend_Gdata_App_Entry Provides a fluent interface |
|
360 */ |
|
361 public function setSummary($value) |
|
362 { |
|
363 $this->_summary = $value; |
|
364 return $this; |
|
365 } |
|
366 |
|
367 /** |
|
368 * Gets the value of the app:control element |
|
369 * |
|
370 * @return Zend_Gdata_App_Extension_Control |
|
371 */ |
|
372 public function getControl() |
|
373 { |
|
374 return $this->_control; |
|
375 } |
|
376 |
|
377 /** |
|
378 * Sets the value of the app:control element |
|
379 * |
|
380 * @param Zend_Gdata_App_Extension_Control $value |
|
381 * @return Zend_Gdata_App_Entry Provides a fluent interface |
|
382 */ |
|
383 public function setControl($value) |
|
384 { |
|
385 $this->_control = $value; |
|
386 return $this; |
|
387 } |
|
388 |
|
389 } |