PageRenderTime 24ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/library/Zend/Gdata/Spreadsheets/ListEntry.php

https://bitbucket.org/openfisma-ondemand/openfisma
PHP | 208 lines | 92 code | 17 blank | 99 comment | 10 complexity | 7bb4d2e4f11f0ea3d55953846ff25251 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-2.1, GPL-3.0, Apache-2.0, EPL-1.0
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Gdata
  17. * @subpackage Spreadsheets
  18. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_Gdata_Entry
  24. */
  25. // require_once 'Zend/Gdata/Entry.php';
  26. /**
  27. * @see Zend_Gdata_Spreadsheets_Extension_Custom
  28. */
  29. // require_once 'Zend/Gdata/Spreadsheets/Extension/Custom.php';
  30. /**
  31. * Concrete class for working with List entries.
  32. *
  33. * @category Zend
  34. * @package Zend_Gdata
  35. * @subpackage Spreadsheets
  36. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  37. * @license http://framework.zend.com/license/new-bsd New BSD License
  38. */
  39. class Zend_Gdata_Spreadsheets_ListEntry extends Zend_Gdata_Entry
  40. {
  41. protected $_entryClassName = 'Zend_Gdata_Spreadsheets_ListEntry';
  42. /**
  43. * List of custom row elements (Zend_Gdata_Spreadsheets_Extension_Custom),
  44. * indexed by order added to this entry.
  45. * @var array
  46. */
  47. protected $_custom = array();
  48. /**
  49. * List of custom row elements (Zend_Gdata_Spreadsheets_Extension_Custom),
  50. * indexed by element name.
  51. * @var array
  52. */
  53. protected $_customByName = array();
  54. /**
  55. * Constructs a new Zend_Gdata_Spreadsheets_ListEntry object.
  56. * @param DOMElement $element An existing XML element on which to base this new object.
  57. */
  58. public function __construct($element = null)
  59. {
  60. $this->registerAllNamespaces(Zend_Gdata_Spreadsheets::$namespaces);
  61. parent::__construct($element);
  62. }
  63. public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
  64. {
  65. $element = parent::getDOM($doc, $majorVersion, $minorVersion);
  66. if (!empty($this->_custom)) {
  67. foreach ($this->_custom as $custom) {
  68. $element->appendChild($custom->getDOM($element->ownerDocument));
  69. }
  70. }
  71. return $element;
  72. }
  73. protected function takeChildFromDOM($child)
  74. {
  75. switch ($child->namespaceURI) {
  76. case $this->lookupNamespace('gsx');
  77. $custom = new Zend_Gdata_Spreadsheets_Extension_Custom($child->localName);
  78. $custom->transferFromDOM($child);
  79. $this->addCustom($custom);
  80. break;
  81. default:
  82. parent::takeChildFromDOM($child);
  83. break;
  84. }
  85. }
  86. /**
  87. * Gets the row elements contained by this list entry.
  88. * @return array The custom row elements in this list entry
  89. */
  90. public function getCustom()
  91. {
  92. return $this->_custom;
  93. }
  94. /**
  95. * Gets a single row element contained by this list entry using its name.
  96. * @param string $name The name of a custom element to return. If null
  97. * or not defined, an array containing all custom elements
  98. * indexed by name will be returned.
  99. * @return mixed If a name is specified, the
  100. * Zend_Gdata_Spreadsheets_Extension_Custom element requested,
  101. * is returned or null if not found. Otherwise, an array of all
  102. * Zend_Gdata_Spreadsheets_Extension_Custom elements is returned
  103. * indexed by name.
  104. */
  105. public function getCustomByName($name = null)
  106. {
  107. if ($name === null) {
  108. return $this->_customByName;
  109. } else {
  110. if (array_key_exists($name, $this->customByName)) {
  111. return $this->_customByName[$name];
  112. } else {
  113. return null;
  114. }
  115. }
  116. }
  117. /**
  118. * Sets the row elements contained by this list entry. If any
  119. * custom row elements were previously stored, they will be overwritten.
  120. * @param array $custom The custom row elements to be contained in this
  121. * list entry.
  122. * @return Zend_Gdata_Spreadsheets_ListEntry Provides a fluent interface.
  123. */
  124. public function setCustom($custom)
  125. {
  126. $this->_custom = array();
  127. foreach ($custom as $c) {
  128. $this->addCustom($c);
  129. }
  130. return $this;
  131. }
  132. /**
  133. * Add an individual custom row element to this list entry.
  134. * @param Zend_Gdata_Spreadsheets_Extension_Custom $custom The custom
  135. * element to be added.
  136. * @return Zend_Gdata_Spreadsheets_ListEntry Provides a fluent interface.
  137. */
  138. public function addCustom($custom)
  139. {
  140. $this->_custom[] = $custom;
  141. $this->_customByName[$custom->getColumnName()] = $custom;
  142. return $this;
  143. }
  144. /**
  145. * Remove an individual row element from this list entry by index. This
  146. * will cause the array to be re-indexed.
  147. * @param int $index The index of the custom element to be deleted.
  148. * @return Zend_Gdata_Spreadsheets_ListEntry Provides a fluent interface.
  149. * @throws Zend_Gdata_App_InvalidArgumentException
  150. */
  151. public function removeCustom($index)
  152. {
  153. if (array_key_exists($index, $this->_custom)) {
  154. $element = $this->_custom[$index];
  155. // Remove element
  156. unset($this->_custom[$index]);
  157. // Re-index the array
  158. $this->_custom = array_values($this->_custom);
  159. // Be sure to delete form both arrays!
  160. $key = array_search($element, $this->_customByName);
  161. unset($this->_customByName[$key]);
  162. } else {
  163. // require_once 'Zend/Gdata/App/InvalidArgumentException.php';
  164. throw new Zend_Gdata_App_InvalidArgumentException(
  165. 'Element does not exist.');
  166. }
  167. return $this;
  168. }
  169. /**
  170. * Remove an individual row element from this list entry by name.
  171. * @param string $name The name of the custom element to be deleted.
  172. * @return Zend_Gdata_Spreadsheets_ListEntry Provides a fluent interface.
  173. * @throws Zend_Gdata_App_InvalidArgumentException
  174. */
  175. public function removeCustomByName($name)
  176. {
  177. if (array_key_exists($name, $this->_customByName)) {
  178. $element = $this->_customByName[$name];
  179. // Remove element
  180. unset($this->_customByName[$name]);
  181. // Be sure to delete from both arrays!
  182. $key = array_search($element, $this->_custom);
  183. unset($this->_custom[$key]);
  184. } else {
  185. // require_once 'Zend/Gdata/App/InvalidArgumentException.php';
  186. throw new Zend_Gdata_App_InvalidArgumentException(
  187. 'Element does not exist.');
  188. }
  189. return $this;
  190. }
  191. }