File indexing completed on 2024-12-22 05:36:46
0001 <?php 0002 0003 /** 0004 * Zend Framework 0005 * 0006 * LICENSE 0007 * 0008 * This source file is subject to the new BSD license that is bundled 0009 * with this package in the file LICENSE.txt. 0010 * It is also available through the world-wide-web at this URL: 0011 * http://framework.zend.com/license/new-bsd 0012 * If you did not receive a copy of the license and are unable to 0013 * obtain it through the world-wide-web, please send an email 0014 * to license@zend.com so we can send you a copy immediately. 0015 * 0016 * @category Zend 0017 * @package Zend_Gdata 0018 * @subpackage Spreadsheets 0019 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0020 * @license http://framework.zend.com/license/new-bsd New BSD License 0021 * @version $Id$ 0022 */ 0023 0024 /** 0025 * @see Zend_Gdata_Entry 0026 */ 0027 // require_once 'Zend/Gdata/Entry.php'; 0028 0029 /** 0030 * @see Zend_Gdata_Spreadsheets_Extension_Custom 0031 */ 0032 // require_once 'Zend/Gdata/Spreadsheets/Extension/Custom.php'; 0033 0034 /** 0035 * Concrete class for working with List entries. 0036 * 0037 * @category Zend 0038 * @package Zend_Gdata 0039 * @subpackage Spreadsheets 0040 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0041 * @license http://framework.zend.com/license/new-bsd New BSD License 0042 */ 0043 class Zend_Gdata_Spreadsheets_ListEntry extends Zend_Gdata_Entry 0044 { 0045 0046 protected $_entryClassName = 'Zend_Gdata_Spreadsheets_ListEntry'; 0047 0048 /** 0049 * List of custom row elements (Zend_Gdata_Spreadsheets_Extension_Custom), 0050 * indexed by order added to this entry. 0051 * @var array 0052 */ 0053 protected $_custom = array(); 0054 0055 /** 0056 * List of custom row elements (Zend_Gdata_Spreadsheets_Extension_Custom), 0057 * indexed by element name. 0058 * @var array 0059 */ 0060 protected $_customByName = array(); 0061 0062 /** 0063 * Constructs a new Zend_Gdata_Spreadsheets_ListEntry object. 0064 * @param DOMElement $element An existing XML element on which to base this new object. 0065 */ 0066 public function __construct($element = null) 0067 { 0068 $this->registerAllNamespaces(Zend_Gdata_Spreadsheets::$namespaces); 0069 parent::__construct($element); 0070 } 0071 0072 public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null) 0073 { 0074 $element = parent::getDOM($doc, $majorVersion, $minorVersion); 0075 if (!empty($this->_custom)) { 0076 foreach ($this->_custom as $custom) { 0077 $element->appendChild($custom->getDOM($element->ownerDocument)); 0078 } 0079 } 0080 return $element; 0081 } 0082 0083 protected function takeChildFromDOM($child) 0084 { 0085 switch ($child->namespaceURI) { 0086 case $this->lookupNamespace('gsx'); 0087 $custom = new Zend_Gdata_Spreadsheets_Extension_Custom($child->localName); 0088 $custom->transferFromDOM($child); 0089 $this->addCustom($custom); 0090 break; 0091 default: 0092 parent::takeChildFromDOM($child); 0093 break; 0094 } 0095 } 0096 0097 /** 0098 * Gets the row elements contained by this list entry. 0099 * @return array The custom row elements in this list entry 0100 */ 0101 public function getCustom() 0102 { 0103 return $this->_custom; 0104 } 0105 0106 /** 0107 * Gets a single row element contained by this list entry using its name. 0108 * @param string $name The name of a custom element to return. If null 0109 * or not defined, an array containing all custom elements 0110 * indexed by name will be returned. 0111 * @return mixed If a name is specified, the 0112 * Zend_Gdata_Spreadsheets_Extension_Custom element requested, 0113 * is returned or null if not found. Otherwise, an array of all 0114 * Zend_Gdata_Spreadsheets_Extension_Custom elements is returned 0115 * indexed by name. 0116 */ 0117 public function getCustomByName($name = null) 0118 { 0119 if ($name === null) { 0120 return $this->_customByName; 0121 } else { 0122 if (array_key_exists($name, $this->customByName)) { 0123 return $this->_customByName[$name]; 0124 } else { 0125 return null; 0126 } 0127 } 0128 } 0129 0130 /** 0131 * Sets the row elements contained by this list entry. If any 0132 * custom row elements were previously stored, they will be overwritten. 0133 * @param array $custom The custom row elements to be contained in this 0134 * list entry. 0135 * @return Zend_Gdata_Spreadsheets_ListEntry Provides a fluent interface. 0136 */ 0137 public function setCustom($custom) 0138 { 0139 $this->_custom = array(); 0140 foreach ($custom as $c) { 0141 $this->addCustom($c); 0142 } 0143 return $this; 0144 } 0145 0146 /** 0147 * Add an individual custom row element to this list entry. 0148 * @param Zend_Gdata_Spreadsheets_Extension_Custom $custom The custom 0149 * element to be added. 0150 * @return Zend_Gdata_Spreadsheets_ListEntry Provides a fluent interface. 0151 */ 0152 public function addCustom($custom) 0153 { 0154 $this->_custom[] = $custom; 0155 $this->_customByName[$custom->getColumnName()] = $custom; 0156 return $this; 0157 } 0158 0159 /** 0160 * Remove an individual row element from this list entry by index. This 0161 * will cause the array to be re-indexed. 0162 * @param int $index The index of the custom element to be deleted. 0163 * @return Zend_Gdata_Spreadsheets_ListEntry Provides a fluent interface. 0164 * @throws Zend_Gdata_App_InvalidArgumentException 0165 */ 0166 public function removeCustom($index) 0167 { 0168 if (array_key_exists($index, $this->_custom)) { 0169 $element = $this->_custom[$index]; 0170 // Remove element 0171 unset($this->_custom[$index]); 0172 // Re-index the array 0173 $this->_custom = array_values($this->_custom); 0174 // Be sure to delete form both arrays! 0175 $key = array_search($element, $this->_customByName); 0176 unset($this->_customByName[$key]); 0177 } else { 0178 // require_once 'Zend/Gdata/App/InvalidArgumentException.php'; 0179 throw new Zend_Gdata_App_InvalidArgumentException( 0180 'Element does not exist.'); 0181 } 0182 return $this; 0183 } 0184 0185 /** 0186 * Remove an individual row element from this list entry by name. 0187 * @param string $name The name of the custom element to be deleted. 0188 * @return Zend_Gdata_Spreadsheets_ListEntry Provides a fluent interface. 0189 * @throws Zend_Gdata_App_InvalidArgumentException 0190 */ 0191 public function removeCustomByName($name) 0192 { 0193 if (array_key_exists($name, $this->_customByName)) { 0194 $element = $this->_customByName[$name]; 0195 // Remove element 0196 unset($this->_customByName[$name]); 0197 // Be sure to delete from both arrays! 0198 $key = array_search($element, $this->_custom); 0199 unset($this->_custom[$key]); 0200 } else { 0201 // require_once 'Zend/Gdata/App/InvalidArgumentException.php'; 0202 throw new Zend_Gdata_App_InvalidArgumentException( 0203 'Element does not exist.'); 0204 } 0205 return $this; 0206 } 0207 0208 }