Row.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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\OpenDocument\Calc;
  11. class Row {
  12. /**
  13. * @var \DOMElement $row
  14. */
  15. protected $row;
  16. /**
  17. * Construct a Row from the DOMElement representing it.
  18. *
  19. * This DOMElement must bear a table:table-row tag
  20. *
  21. * @param \DOMElement $row
  22. *
  23. * @return void
  24. */
  25. function __construct(\DOMElement $row) {
  26. if ((!($row instanceof \DOMElement)) || ($row->tagName != 'table:table-row')) {
  27. die('Row::__construct() needs a DOMElement parameter for a table-row element ');
  28. }
  29. $this->row = $row;
  30. }
  31. /**
  32. * Analyze a spreadsheet row and return the cells as an array of Calc_Cell
  33. *
  34. * @return array<\Osinet\OpenDocument\Calc\Cell>
  35. */
  36. function getCells(): array {
  37. $cellNodeList = $this->row->childNodes;
  38. $cells = [];
  39. $iCell = 0;
  40. for ($icol = 0; $icol < $cellNodeList->length; $icol++) {
  41. $cellNode = $cellNodeList->item($icol);
  42. $count = NULL;
  43. if ($cellNode instanceof \DOMElement) {
  44. $count = $cellNode->getAttributeNS(Reader::NS_TABLE, 'number-columns-repeated');
  45. }
  46. if (empty($count)) {
  47. $count = 1;
  48. }
  49. for ($j = 0; $j < $count; $j++) {
  50. $cells[$iCell++] = new Cell($cellNode);
  51. }
  52. }
  53. return $cells;
  54. }
  55. }