WorksheetEntry.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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-2008 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /**
  22. * @see Zend_Gdata_Entry
  23. */
  24. require_once 'Zend/Gdata/Entry.php';
  25. /**
  26. * @see Zend_Gdata_Spreadsheets_Extension_RowCount
  27. */
  28. require_once 'Zend/Gdata/Spreadsheets/Extension/RowCount.php';
  29. /**
  30. * @see Zend_Gdata_Spreadsheets_Extension_ColCount
  31. */
  32. require_once 'Zend/Gdata/Spreadsheets/Extension/ColCount.php';
  33. /**
  34. * Concrete class for working with Worksheet entries.
  35. *
  36. * @category Zend
  37. * @package Zend_Gdata
  38. * @subpackage Spreadsheets
  39. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  40. * @license http://framework.zend.com/license/new-bsd New BSD License
  41. */
  42. class Zend_Gdata_Spreadsheets_WorksheetEntry extends Zend_Gdata_Entry
  43. {
  44. protected $_entryClassName = 'Zend_Gdata_Spreadsheets_WorksheetEntry';
  45. protected $_rowCount = null;
  46. protected $_colCount = null;
  47. /**
  48. * Constructs a new Zend_Gdata_Spreadsheets_WorksheetEntry object.
  49. *
  50. * @param DOMElement $element (optional) The DOMElement on which to base this object.
  51. */
  52. public function __construct($element = null)
  53. {
  54. $this->registerAllNamespaces(Zend_Gdata_Spreadsheets::$namespaces);
  55. parent::__construct($element);
  56. }
  57. /**
  58. * Retrieves a DOMElement which corresponds to this element and all
  59. * child properties. This is used to build an entry back into a DOM
  60. * and eventually XML text for sending to the server upon updates, or
  61. * for application storage/persistence.
  62. *
  63. * @param DOMDocument $doc The DOMDocument used to construct DOMElements
  64. * @return DOMElement The DOMElement representing this element and all
  65. * child properties.
  66. */
  67. public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
  68. {
  69. $element = parent::getDOM($doc, $majorVersion, $minorVersion);
  70. if ($this->_rowCount != null) {
  71. $element->appendChild($this->_rowCount->getDOM($element->ownerDocument));
  72. }
  73. if ($this->_colCount != null) {
  74. $element->appendChild($this->_colCount->getDOM($element->ownerDocument));
  75. }
  76. return $element;
  77. }
  78. /**
  79. * Creates individual Entry objects of the appropriate type and
  80. * stores them in the $_entry array based upon DOM data.
  81. *
  82. * @param DOMNode $child The DOMNode to process
  83. */
  84. protected function takeChildFromDOM($child)
  85. {
  86. $absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
  87. switch ($absoluteNodeName) {
  88. case $this->lookupNamespace('gs') . ':' . 'rowCount';
  89. $rowCount = new Zend_Gdata_Spreadsheets_Extension_RowCount();
  90. $rowCount->transferFromDOM($child);
  91. $this->_rowCount = $rowCount;
  92. break;
  93. case $this->lookupNamespace('gs') . ':' . 'colCount';
  94. $colCount = new Zend_Gdata_Spreadsheets_Extension_ColCount();
  95. $colCount->transferFromDOM($child);
  96. $this->_colCount = $colCount;
  97. break;
  98. default:
  99. parent::takeChildFromDOM($child);
  100. break;
  101. }
  102. }
  103. /**
  104. * Gets the row count for this entry.
  105. *
  106. * @return string The row count for the entry.
  107. */
  108. public function getRowCount()
  109. {
  110. return $this->_rowCount;
  111. }
  112. /**
  113. * Gets the column count for this entry.
  114. *
  115. * @return string The column count for the entry.
  116. */
  117. public function getColumnCount()
  118. {
  119. return $this->_colCount;
  120. }
  121. /**
  122. * Sets the row count for this entry.
  123. *
  124. * @param string $rowCount The new row count for the entry.
  125. */
  126. public function setRowCount($rowCount)
  127. {
  128. $this->_rowCount = $rowCount;
  129. return $this;
  130. }
  131. /**
  132. * Sets the column count for this entry.
  133. *
  134. * @param string $colCount The new column count for the entry.
  135. */
  136. public function setColumnCount($colCount)
  137. {
  138. $this->_colCount = $colCount;
  139. return $this;
  140. }
  141. /**
  142. * Returns the content of all rows as an associative array
  143. *
  144. * @return array An array of rows. Each element of the array is an associative array of data
  145. */
  146. public function getContentsAsRows()
  147. {
  148. $service = new Zend_Gdata_Spreadsheets($this->getHttpClient());
  149. return $service->getSpreadsheetListFeedContents($this);
  150. }
  151. /**
  152. * Returns the content of all cells as an associative array, indexed
  153. * off the cell location (ie 'A1', 'D4', etc). Each element of
  154. * the array is an associative array with a 'value' and a 'function'.
  155. * Only non-empty cells are returned by default. 'range' is the
  156. * value of the 'range' query parameter specified at:
  157. * http://code.google.com/apis/spreadsheets/reference.html#cells_Parameters
  158. *
  159. * @param string $range The range of cells to retrieve
  160. * @param boolean $empty Whether to retrieve empty cells
  161. * @return array An associative array of cells
  162. */
  163. public function getContentsAsCells($range = null, $empty = false)
  164. {
  165. $service = new Zend_Gdata_Spreadsheets($this->getHttpClient());
  166. return $service->getSpreadsheetCellFeedContents($this, $range, $empty);
  167. }
  168. }