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-2010 Zend Technologies USA Inc. (http://www.zend.com)
20 * @license http://framework.zend.com/license/new-bsd New BSD License
25 * @see Zend_Gdata_Entry
27 require_once 'Zend/Gdata/Entry.php';
30 * @see Zend_Gdata_Spreadsheets_Extension_Custom
32 require_once 'Zend/Gdata/Spreadsheets/Extension/Custom.php';
35 * Concrete class for working with List entries.
39 * @subpackage Spreadsheets
40 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
41 * @license http://framework.zend.com/license/new-bsd New BSD License
43 class Zend_Gdata_Spreadsheets_ListEntry extends Zend_Gdata_Entry
46 protected $_entryClassName = 'Zend_Gdata_Spreadsheets_ListEntry';
49 * List of custom row elements (Zend_Gdata_Spreadsheets_Extension_Custom),
50 * indexed by order added to this entry.
53 protected $_custom = array();
56 * List of custom row elements (Zend_Gdata_Spreadsheets_Extension_Custom),
57 * indexed by element name.
60 protected $_customByName = array();
63 * Constructs a new Zend_Gdata_Spreadsheets_ListEntry object.
64 * @param DOMElement $element An existing XML element on which to base this new object.
66 public function __construct($element = null)
68 $this->registerAllNamespaces(Zend_Gdata_Spreadsheets::$namespaces);
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.');