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.
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
24
* @see Zend_Gdata_Entry
26
require_once 'Zend/Gdata/Entry.php';
29
* @see Zend_Gdata_Spreadsheets_Extension_Custom
31
require_once 'Zend/Gdata/Spreadsheets/Extension/Custom.php';
34
* Concrete class for working with List entries.
38
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
39
* @license http://framework.zend.com/license/new-bsd New BSD License
41
class Zend_Gdata_Spreadsheets_ListEntry extends Zend_Gdata_Entry
44
protected $_entryClassName = 'Zend_Gdata_Spreadsheets_ListEntry';
47
* List of custom row elements (Zend_Gdata_Spreadsheets_Extension_Custom),
48
* indexed by order added to this entry.
51
protected $_custom = array();
54
* List of custom row elements (Zend_Gdata_Spreadsheets_Extension_Custom),
55
* indexed by element name.
58
protected $_customByName = array();
61
* Constructs a new Zend_Gdata_Spreadsheets_ListEntry object.
62
* @param DOMElement $element An existing XML element on which to base this new object.
64
public function __construct($element = null)
66
foreach (Zend_Gdata_Spreadsheets::$namespaces as $nsPrefix => $nsUri) {
67
$this->registerNamespace($nsPrefix, $nsUri);
69
parent::__construct($element);
72
public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
74
$element = parent::getDOM($doc, $majorVersion, $minorVersion);
75
if (!empty($this->_custom)) {
76
foreach ($this->_custom as $custom) {
77
$element->appendChild($custom->getDOM($element->ownerDocument));
83
protected function takeChildFromDOM($child)
85
switch ($child->namespaceURI) {
86
case $this->lookupNamespace('gsx');
87
$custom = new Zend_Gdata_Spreadsheets_Extension_Custom($child->localName);
88
$custom->transferFromDOM($child);
89
$this->addCustom($custom);
92
parent::takeChildFromDOM($child);
98
* Gets the row elements contained by this list entry.
99
* @return array The custom row elements in this list entry
101
public function getCustom()
103
return $this->_custom;
107
* Gets a single row element contained by this list entry using its name.
108
* @param string $name The name of a custom element to return. If null
109
* or not defined, an array containing all custom elements
110
* indexed by name will be returned.
111
* @return mixed If a name is specified, the
112
* Zend_Gdata_Spreadsheets_Extension_Custom element requested,
113
* is returned or null if not found. Otherwise, an array of all
114
* Zend_Gdata_Spreadsheets_Extension_Custom elements is returned
117
public function getCustomByName($name = null)
119
if ($name === null) {
120
return $this->_customByName;
122
if (array_key_exists($name, $this->customByName)) {
123
return $this->_customByName[$name];
131
* Sets the row elements contained by this list entry. If any
132
* custom row elements were previously stored, they will be overwritten.
133
* @param array $custom The custom row elements to be contained in this
135
* @return Zend_Gdata_Spreadsheets_ListEntry Provides a fluent interface.
137
public function setCustom($custom)
139
$this->_custom = array();
140
foreach ($custom as $c) {
141
$this->addCustom($c);
147
* Add an individual custom row element to this list entry.
148
* @param Zend_Gdata_Spreadsheets_Extension_Custom $custom The custom
149
* element to be added.
150
* @return Zend_Gdata_Spreadsheets_ListEntry Provides a fluent interface.
152
public function addCustom($custom)
154
$this->_custom[] = $custom;
155
$this->_customByName[$custom->getColumnName()] = $custom;
160
* Remove an individual row element from this list entry by index. This
161
* will cause the array to be re-indexed.
162
* @param int $index The index of the custom element to be deleted.
163
* @return Zend_Gdata_Spreadsheets_ListEntry Provides a fluent interface.
164
* @throws Zend_Gdata_App_InvalidArgumentException
166
public function removeCustom($index)
168
if (array_key_exists($index, $this->_custom)) {
169
$element = $this->_custom[$index];
171
unset($this->_custom[$index]);
172
// Re-index the array
173
$this->_custom = array_values($this->_custom);
174
// Be sure to delete form both arrays!
175
$key = array_search($element, $this->_customByName);
176
unset($this->_customByName[$key]);
178
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
179
throw new Zend_Gdata_App_InvalidArgumentException(
180
'Element does not exist.');
186
* Remove an individual row element from this list entry by name.
187
* @param string $name The name of the custom element to be deleted.
188
* @return Zend_Gdata_Spreadsheets_ListEntry Provides a fluent interface.
189
* @throws Zend_Gdata_App_InvalidArgumentException
191
public function removeCustomByName($name)
193
if (array_key_exists($name, $this->_customByName)) {
194
$element = $this->_customByName[$name];
196
unset($this->_customByName[$name]);
197
// Be sure to delete from both arrays!
198
$key = array_search($element, $this->_custom);
199
unset($this->_custom[$key]);
201
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
202
throw new Zend_Gdata_App_InvalidArgumentException(
203
'Element does not exist.');