Row.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * Wrap an OpenDocument spreadsheet row
  4. *
  5. * Requires PHP 5.3
  6. *
  7. * @license CeCILL 2.0
  8. * @copyright 2005-2012 Ouest Systemes Informatiques
  9. */
  10. namespace OSInet\Open_Document\Calc;
  11. class Row {
  12. /**
  13. * @var DOMElement $row
  14. */
  15. protected $row;
  16. /**
  17. * Analyze a spreadsheet row and return the cells as an array of Calc_Cell
  18. *
  19. * @return array
  20. */
  21. function getCells () {
  22. $cellNodeList = $this->row->childNodes;
  23. $cells = array();
  24. $iCell = 0;
  25. for ($icol = 0 ; $icol < $cellNodeList->length ; $icol++) {
  26. $cellElement = $cellNodeList->item($icol);
  27. $count = NULL;
  28. if (is_object($cellElement)) {
  29. $count = $cellElement->getAttributeNS(Reader::NS_TABLE, 'number-columns-repeated');
  30. }
  31. if (empty($count)) {
  32. $count = 1;
  33. }
  34. for ($j = 0 ; $j < $count ; $j++) {
  35. $cells[$iCell++] = new Cell($cellElement);
  36. }
  37. }
  38. return $cells;
  39. }
  40. /**
  41. * Construct a Row from the DOMElement representing it.
  42. *
  43. * This DOMElement must bear a table:table-row tag
  44. *
  45. * @param \DOMNodeList $row
  46. * @return void
  47. */
  48. function __construct(\DOMElement $row) {
  49. if ((!($row instanceof \DOMElement)) || ($row->tagName != 'table:table-row')) {
  50. die('Row::__construct() needs a DOMElement parameter for a table-row element ');
  51. }
  52. $this->row = $row;
  53. }
  54. }