source: trunk/www.guidonia.net/wp/wp-content/plugins/webtv/Drivers/Zend/Gdata/Gbase/ItemEntry.php@ 44

Last change on this file since 44 was 44, checked in by luciano, 14 years ago
File size: 5.6 KB
Line 
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 Gbase
19 * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
20 * @license http://framework.zend.com/license/new-bsd New BSD License
21 */
22
23/**
24 * @see Zend_Gdata_Gbase_Entry
25 */
26require_once 'Zend/Gdata/Gbase/Entry.php';
27
28/**
29 * Concrete class for working with Item entries.
30 *
31 * @link http://code.google.com/apis/base/
32 *
33 * @category Zend
34 * @package Zend_Gdata
35 * @subpackage Gbase
36 * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
37 * @license http://framework.zend.com/license/new-bsd New BSD License
38 */
39class Zend_Gdata_Gbase_ItemEntry extends Zend_Gdata_Gbase_Entry
40{
41 /**
42 * The classname for individual item entry elements.
43 *
44 * @var string
45 */
46 protected $_entryClassName = 'Zend_Gdata_Gbase_ItemEntry';
47
48 /**
49 * Set the value of the itme_type
50 *
51 * @param Zend_Gdata_Gbase_Extension_ItemType $value The desired value for the item_type
52 * @return Zend_Gdata_Gbase_ItemEntry Provides a fluent interface
53 */
54 public function setItemType($value)
55 {
56 $this->addGbaseAttribute('item_type', $value, 'text');
57 return $this;
58 }
59
60 /**
61 * Adds a custom attribute to the entry in the following format:
62 * &lt;g:[$name] type='[$type]'&gt;[$value]&lt;/g:[$name]&gt;
63 *
64 * @param string $name The name of the attribute
65 * @param string $value The text value of the attribute
66 * @param string $type (optional) The type of the attribute.
67 * e.g.: 'text', 'number', 'floatUnit'
68 * @return Zend_Gdata_Gbase_ItemEntry Provides a fluent interface
69 */
70 public function addGbaseAttribute($name, $text, $type = null) {
71 $newBaseAttribute = new Zend_Gdata_Gbase_Extension_BaseAttribute($name, $text, $type);
72 $this->_baseAttributes[] = $newBaseAttribute;
73 return $this;
74 }
75
76 /**
77 * Removes a Base attribute from the current list of Base attributes
78 *
79 * @param Zend_Gdata_Gbase_Extension_BaseAttribute $baseAttribute The attribute to be removed
80 * @return Zend_Gdata_Gbase_ItemEntry Provides a fluent interface
81 */
82 public function removeGbaseAttribute($baseAttribute) {
83 $baseAttributes = $this->_baseAttributes;
84 for ($i = 0; $i < count($this->_baseAttributes); $i++) {
85 if ($this->_baseAttributes[$i] == $baseAttribute) {
86 array_splice($baseAttributes, $i, 1);
87 break;
88 }
89 }
90 $this->_baseAttributes = $baseAttributes;
91 return $this;
92 }
93
94 /**
95 * Uploads changes in this entry to the server using Zend_Gdata_App
96 *
97 * @param boolean $dryRun Whether the transaction is dry run or not.
98 * @param string|null $uri The URI to send requests to, or null if $data
99 * contains the URI.
100 * @param string|null $className The name of the class that should we
101 * deserializing the server response. If null, then
102 * 'Zend_Gdata_App_Entry' will be used.
103 * @param array $extraHeaders Extra headers to add to the request, as an
104 * array of string-based key/value pairs.
105 * @return Zend_Gdata_App_Entry The updated entry
106 * @throws Zend_Gdata_App_Exception
107 */
108 public function save($dryRun = false,
109 $uri = null,
110 $className = null,
111 $extraHeaders = array())
112 {
113 if ($dryRun == true) {
114 $editLink = $this->getEditLink();
115 if ($uri == null && $editLink !== null) {
116 $uri = $editLink->getHref() . '?dry-run=true';
117 }
118 if ($uri === null) {
119 require_once 'Zend/Gdata/App/InvalidArgumentException.php';
120 throw new Zend_Gdata_App_InvalidArgumentException('You must specify an URI which needs deleted.');
121 }
122 $service = new Zend_Gdata_App($this->getHttpClient());
123 return $service->updateEntry($this,
124 $uri,
125 $className,
126 $extraHeaders);
127 } else {
128 parent::save($uri, $className, $extraHeaders);
129 }
130 }
131
132 /**
133 * Deletes this entry to the server using the referenced
134 * Zend_Http_Client to do a HTTP DELETE to the edit link stored in this
135 * entry's link collection.
136 *
137 * @param boolean $dyrRun Whether the transaction is dry run or not
138 * @return void
139 * @throws Zend_Gdata_App_Exception
140 */
141 public function delete($dryRun = false)
142 {
143 $uri = null;
144
145 if ($dryRun == true) {
146 $editLink = $this->getEditLink();
147 if ($editLink !== null) {
148 $uri = $editLink->getHref() . '?dry-run=true';
149 }
150 if ($uri === null) {
151 require_once 'Zend/Gdata/App/InvalidArgumentException.php';
152 throw new Zend_Gdata_App_InvalidArgumentException('You must specify an URI which needs deleted.');
153 }
154 parent::delete($uri);
155 } else {
156 parent::delete();
157 }
158 }
159
160}
Note: See TracBrowser for help on using the repository browser.