|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00027 require_once 'Zend/Gdata/Entry.php'; 00028 00032 require_once 'Zend/Gdata/Spreadsheets/Extension/Custom.php'; 00033 00043 class Zend_Gdata_Spreadsheets_ListEntry extends Zend_Gdata_Entry 00044 { 00045 00046 protected $_entryClassName = 'Zend_Gdata_Spreadsheets_ListEntry'; 00047 00053 protected $_custom = array(); 00054 00060 protected $_customByName = array(); 00061 00066 public function __construct($element = null) 00067 { 00068 $this->registerAllNamespaces(Zend_Gdata_Spreadsheets::$namespaces); 00069 parent::__construct($element); 00070 } 00071 00072 public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null) 00073 { 00074 $element = parent::getDOM($doc, $majorVersion, $minorVersion); 00075 if (!empty($this->_custom)) { 00076 foreach ($this->_custom as $custom) { 00077 $element->appendChild($custom->getDOM($element->ownerDocument)); 00078 } 00079 } 00080 return $element; 00081 } 00082 00083 protected function takeChildFromDOM($child) 00084 { 00085 switch ($child->namespaceURI) { 00086 case $this->lookupNamespace('gsx'); 00087 $custom = new Zend_Gdata_Spreadsheets_Extension_Custom($child->localName); 00088 $custom->transferFromDOM($child); 00089 $this->addCustom($custom); 00090 break; 00091 default: 00092 parent::takeChildFromDOM($child); 00093 break; 00094 } 00095 } 00096 00101 public function getCustom() 00102 { 00103 return $this->_custom; 00104 } 00105 00117 public function getCustomByName($name = null) 00118 { 00119 if ($name === null) { 00120 return $this->_customByName; 00121 } else { 00122 if (array_key_exists($name, $this->customByName)) { 00123 return $this->_customByName[$name]; 00124 } else { 00125 return null; 00126 } 00127 } 00128 } 00129 00137 public function setCustom($custom) 00138 { 00139 $this->_custom = array(); 00140 foreach ($custom as $c) { 00141 $this->addCustom($c); 00142 } 00143 return $this; 00144 } 00145 00152 public function addCustom($custom) 00153 { 00154 $this->_custom[] = $custom; 00155 $this->_customByName[$custom->getColumnName()] = $custom; 00156 return $this; 00157 } 00158 00166 public function removeCustom($index) 00167 { 00168 if (array_key_exists($index, $this->_custom)) { 00169 $element = $this->_custom[$index]; 00170 // Remove element 00171 unset($this->_custom[$index]); 00172 // Re-index the array 00173 $this->_custom = array_values($this->_custom); 00174 // Be sure to delete form both arrays! 00175 $key = array_search($element, $this->_customByName); 00176 unset($this->_customByName[$key]); 00177 } else { 00178 require_once 'Zend/Gdata/App/InvalidArgumentException.php'; 00179 throw new Zend_Gdata_App_InvalidArgumentException( 00180 'Element does not exist.'); 00181 } 00182 return $this; 00183 } 00184 00191 public function removeCustomByName($name) 00192 { 00193 if (array_key_exists($name, $this->_customByName)) { 00194 $element = $this->_customByName[$name]; 00195 // Remove element 00196 unset($this->_customByName[$name]); 00197 // Be sure to delete from both arrays! 00198 $key = array_search($element, $this->_custom); 00199 unset($this->_custom[$key]); 00200 } else { 00201 require_once 'Zend/Gdata/App/InvalidArgumentException.php'; 00202 throw new Zend_Gdata_App_InvalidArgumentException( 00203 'Element does not exist.'); 00204 } 00205 return $this; 00206 } 00207 00208 }