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

Last change on this file since 44 was 44, checked in by luciano, 14 years ago
File size: 6.8 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 Spreadsheets
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_Entry
25 */
26require_once 'Zend/Gdata/Entry.php';
27
28/**
29 * @see Zend_Gdata_Spreadsheets_Extension_Custom
30 */
31require_once 'Zend/Gdata/Spreadsheets/Extension/Custom.php';
32
33/**
34 * Concrete class for working with List entries.
35 *
36 * @category Zend
37 * @package Zend_Gdata
38 * @subpackage Spreadsheets
39 * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
40 * @license http://framework.zend.com/license/new-bsd New BSD License
41 */
42class Zend_Gdata_Spreadsheets_ListEntry extends Zend_Gdata_Entry
43{
44
45 protected $_entryClassName = 'Zend_Gdata_Spreadsheets_ListEntry';
46
47 /**
48 * List of custom row elements (Zend_Gdata_Spreadsheets_Extension_Custom),
49 * indexed by order added to this entry.
50 * @var array
51 */
52 protected $_custom = array();
53
54 /**
55 * List of custom row elements (Zend_Gdata_Spreadsheets_Extension_Custom),
56 * indexed by element name.
57 * @var array
58 */
59 protected $_customByName = array();
60
61 /**
62 * Constructs a new Zend_Gdata_Spreadsheets_ListEntry object.
63 * @param DOMElement $element An existing XML element on which to base this new object.
64 */
65 public function __construct($element = null)
66 {
67 $this->registerAllNamespaces(Zend_Gdata_Spreadsheets::$namespaces);
68 parent::__construct($element);
69 }
70
71 public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
72 {
73 $element = parent::getDOM($doc, $majorVersion, $minorVersion);
74 if (!empty($this->_custom)) {
75 foreach ($this->_custom as $custom) {
76 $element->appendChild($custom->getDOM($element->ownerDocument));
77 }
78 }
79 return $element;
80 }
81
82 protected function takeChildFromDOM($child)
83 {
84 switch ($child->namespaceURI) {
85 case $this->lookupNamespace('gsx');
86 $custom = new Zend_Gdata_Spreadsheets_Extension_Custom($child->localName);
87 $custom->transferFromDOM($child);
88 $this->addCustom($custom);
89 break;
90 default:
91 parent::takeChildFromDOM($child);
92 break;
93 }
94 }
95
96 /**
97 * Gets the row elements contained by this list entry.
98 * @return array The custom row elements in this list entry
99 */
100 public function getCustom()
101 {
102 return $this->_custom;
103 }
104
105 /**
106 * Gets a single row element contained by this list entry using its name.
107 * @param string $name The name of a custom element to return. If null
108 * or not defined, an array containing all custom elements
109 * indexed by name will be returned.
110 * @return mixed If a name is specified, the
111 * Zend_Gdata_Spreadsheets_Extension_Custom element requested,
112 * is returned or null if not found. Otherwise, an array of all
113 * Zend_Gdata_Spreadsheets_Extension_Custom elements is returned
114 * indexed by name.
115 */
116 public function getCustomByName($name = null)
117 {
118 if ($name === null) {
119 return $this->_customByName;
120 } else {
121 if (array_key_exists($name, $this->customByName)) {
122 return $this->_customByName[$name];
123 } else {
124 return null;
125 }
126 }
127 }
128
129 /**
130 * Sets the row elements contained by this list entry. If any
131 * custom row elements were previously stored, they will be overwritten.
132 * @param array $custom The custom row elements to be contained in this
133 * list entry.
134 * @return Zend_Gdata_Spreadsheets_ListEntry Provides a fluent interface.
135 */
136 public function setCustom($custom)
137 {
138 $this->_custom = array();
139 foreach ($custom as $c) {
140 $this->addCustom($c);
141 }
142 return $this;
143 }
144
145 /**
146 * Add an individual custom row element to this list entry.
147 * @param Zend_Gdata_Spreadsheets_Extension_Custom $custom The custom
148 * element to be added.
149 * @return Zend_Gdata_Spreadsheets_ListEntry Provides a fluent interface.
150 */
151 public function addCustom($custom)
152 {
153 $this->_custom[] = $custom;
154 $this->_customByName[$custom->getColumnName()] = $custom;
155 return $this;
156 }
157
158 /**
159 * Remove an individual row element from this list entry by index. This
160 * will cause the array to be re-indexed.
161 * @param int $index The index of the custom element to be deleted.
162 * @return Zend_Gdata_Spreadsheets_ListEntry Provides a fluent interface.
163 * @throws Zend_Gdata_App_InvalidArgumentException
164 */
165 public function removeCustom($index)
166 {
167 if (array_key_exists($index, $this->_custom)) {
168 $element = $this->_custom[$index];
169 // Remove element
170 unset($this->_custom[$index]);
171 // Re-index the array
172 $this->_custom = array_values($this->_custom);
173 // Be sure to delete form both arrays!
174 $key = array_search($element, $this->_customByName);
175 unset($this->_customByName[$key]);
176 } else {
177 require_once 'Zend/Gdata/App/InvalidArgumentException.php';
178 throw new Zend_Gdata_App_InvalidArgumentException(
179 'Element does not exist.');
180 }
181 return $this;
182 }
183
184 /**
185 * Remove an individual row element from this list entry by name.
186 * @param string $name The name of the custom element to be deleted.
187 * @return Zend_Gdata_Spreadsheets_ListEntry Provides a fluent interface.
188 * @throws Zend_Gdata_App_InvalidArgumentException
189 */
190 public function removeCustomByName($name)
191 {
192 if (array_key_exists($name, $this->_customByName)) {
193 $element = $this->_customByName[$name];
194 // Remove element
195 unset($this->_customByName[$name]);
196 // Be sure to delete from both arrays!
197 $key = array_search($element, $this->_custom);
198 unset($this->_custom[$key]);
199 } else {
200 require_once 'Zend/Gdata/App/InvalidArgumentException.php';
201 throw new Zend_Gdata_App_InvalidArgumentException(
202 'Element does not exist.');
203 }
204 return $this;
205 }
206
207}
Note: See TracBrowser for help on using the repository browser.