Calc_Row.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * Wrap an OpenDocument spreadsheet row
  4. *
  5. * Requires PHP 5.2
  6. *
  7. * @version $Id: Calc_Row.php,v 1.4 2007-09-09 19:49:24 marand Exp $
  8. * @license CeCILL 2.0
  9. * @copyright 2005-2006 Ouest Systemes Informatiques
  10. */
  11. $erCalc_Row = error_reporting(E_ALL | E_STRICT);
  12. class Calc_Row
  13. {
  14. /**
  15. * @var DOMElement $row
  16. */
  17. protected $row;
  18. /**
  19. * Analyze a spreadsheet row and return the cells as an array of Calc_Cell
  20. *
  21. * @return array
  22. */
  23. function getCells ()
  24. {
  25. $cellNodeList = $this->row->childNodes;
  26. $cells = array();
  27. $iCell = 0;
  28. for ($icol = 0 ; $icol < $cellNodeList->length ; $icol++)
  29. {
  30. $cellElement = $cellNodeList->item($icol);
  31. $count = NULL;
  32. if (is_object($cellElement))
  33. {
  34. $count = $cellElement->getAttributeNS(Calc_Reader::NS_TABLE, 'number-columns-repeated');
  35. }
  36. if (empty($count))
  37. {
  38. $count = 1;
  39. }
  40. for ($j = 0 ; $j < $count ; $j++)
  41. {
  42. $cells[$iCell++] = new Calc_Cell($cellElement);
  43. }
  44. }
  45. return $cells;
  46. }
  47. /**
  48. * Construct a Calc_Row from the DOMElement representing it.
  49. *
  50. * This DOMElement must bear a table:table-row tag
  51. *
  52. * @param DOMNodeList $row
  53. * @return void
  54. */
  55. function __construct(DOMElement $row)
  56. {
  57. if ((!($row instanceof DOMElement)) || ($row->tagName != 'table:table-row'))
  58. {
  59. die('Calc_Row::__construct() needs a DOMElement parameter for a table-row element ');
  60. }
  61. $this->row = $row;
  62. }
  63. }
  64. error_reporting($erCalc_Row);
  65. unset($erCalc_Row);