PageRenderTime 49ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/administrator/components/com_virtuemart/classes/PEAR/Table/Storage.php

https://bitbucket.org/dgough/annamaria-daneswood-25102012
PHP | 788 lines | 405 code | 52 blank | 331 comment | 108 complexity | d084e6fda90c5852e75f8ab26b8a958a MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3. /**
  4. * Storage class for HTML::Table data
  5. *
  6. * This class stores data for tables built with HTML_Table. When having
  7. * more than one instance, it can be used for grouping the table into the
  8. * parts <thead>...</thead>, <tfoot>...</tfoot> and <tbody>...</tbody>.
  9. *
  10. * PHP versions 4
  11. *
  12. * LICENSE: This source file is subject to version 3.0 of the PHP license
  13. * that is available through the world-wide-web at the following URI:
  14. * http://www.php.net/license/3_0.txt. If you did not receive a copy of
  15. * the PHP License and are unable to obtain it through the web, please
  16. * send a note to license@php.net so we can mail you a copy immediately.
  17. *
  18. * @category HTML
  19. * @package HTML_Table
  20. * @author Adam Daniel <adaniel1@eesus.jnj.com>
  21. * @author Bertrand Mansion <bmansion@mamasam.com>
  22. * @copyright 2005 The PHP Group
  23. * @license http://www.php.net/license/3_0.txt PHP License 3.0
  24. * @version CVS: $Id: Storage.php 617 2007-01-04 19:43:08Z soeren_nb $
  25. * @link http://pear.php.net/package/HTML_Table
  26. */
  27. /**
  28. * Storage class for HTML::Table data
  29. *
  30. * This class stores data for tables built with HTML_Table. When having
  31. * more than one instance, it can be used for grouping the table into the
  32. * parts <thead>...</thead>, <tfoot>...</tfoot> and <tbody>...</tbody>.
  33. *
  34. * @category HTML
  35. * @package HTML_Table
  36. * @author Adam Daniel <adaniel1@eesus.jnj.com>
  37. * @author Bertrand Mansion <bmansion@mamasam.com>
  38. * @author Mark Wiesemann <wiesemann@php.net>
  39. * @copyright 2005 The PHP Group
  40. * @license http://www.php.net/license/3_0.txt PHP License 3.0
  41. * @version Release: @package_version@
  42. * @link http://pear.php.net/package/HTML_Table
  43. */
  44. class HTML_Table_Storage extends HTML_Common {
  45. /**
  46. * Value to insert into empty cells
  47. * @var string
  48. * @access private
  49. */
  50. var $_autoFill = '&nbsp;';
  51. /**
  52. * Automatically adds a new row or column if a given row or column index does not exist
  53. * @var bool
  54. * @access private
  55. */
  56. var $_autoGrow = true;
  57. /**
  58. * Array containing the table structure
  59. * @var array
  60. * @access private
  61. */
  62. var $_structure = array();
  63. /**
  64. * Number of rows composing in the table
  65. * @var int
  66. * @access private
  67. */
  68. var $_rows = 0;
  69. /**
  70. * Number of column composing the table
  71. * @var int
  72. * @access private
  73. */
  74. var $_cols = 0;
  75. /**
  76. * Tracks the level of nested tables
  77. * @var int
  78. * @access private
  79. */
  80. var $_nestLevel = 0;
  81. /**
  82. * Whether to use <thead>, <tfoot> and <tbody> or not
  83. * @var bool
  84. * @access private
  85. */
  86. var $_useTGroups = false;
  87. /**
  88. * Class constructor
  89. * @param array $attributes Associative array of table tag attributes
  90. * @param int $tabOffset
  91. * @param bool $useTGroups Whether to use <thead>, <tfoot> and
  92. * <tbody> or not
  93. * @access public
  94. */
  95. function HTML_Table_Storage($attributes = null, $tabOffset = 0, $useTGroups = false)
  96. {
  97. HTML_Common::HTML_Common($attributes, (int)$tabOffset);
  98. $this->_useTGroups = (boolean)$useTGroups;
  99. }
  100. /**
  101. * Sets the useTGroups value
  102. * @param boolean $useTGroups
  103. * @access public
  104. */
  105. function setUseTGroups($useTGroups)
  106. {
  107. $this->_useTGroups = $useTGroups;
  108. }
  109. /**
  110. * Returns the useTGroups value
  111. * @access public
  112. * @return boolean
  113. */
  114. function getUseTGroups()
  115. {
  116. return $this->_useTGroups;
  117. }
  118. /**
  119. * Sets the autoFill value
  120. * @param mixed $fill
  121. * @access public
  122. */
  123. function setAutoFill($fill)
  124. {
  125. $this->_autoFill = $fill;
  126. }
  127. /**
  128. * Returns the autoFill value
  129. * @access public
  130. * @return mixed
  131. */
  132. function getAutoFill()
  133. {
  134. return $this->_autoFill;
  135. }
  136. /**
  137. * Sets the autoGrow value
  138. * @param bool $fill
  139. * @access public
  140. */
  141. function setAutoGrow($grow)
  142. {
  143. $this->_autoGrow = $grow;
  144. }
  145. /**
  146. * Returns the autoGrow value
  147. * @access public
  148. * @return mixed
  149. */
  150. function getAutoGrow()
  151. {
  152. return $this->_autoGrow;
  153. }
  154. /**
  155. * Sets the number of rows in the table
  156. * @param int $rows
  157. * @access public
  158. */
  159. function setRowCount($rows)
  160. {
  161. $this->_rows = $rows;
  162. }
  163. /**
  164. * Sets the number of columns in the table
  165. * @param int $cols
  166. * @access public
  167. */
  168. function setColCount($cols)
  169. {
  170. $this->_cols = $cols;
  171. }
  172. /**
  173. * Returns the number of rows in the table
  174. * @access public
  175. * @return int
  176. */
  177. function getRowCount()
  178. {
  179. return $this->_rows;
  180. }
  181. /**
  182. * Gets the number of columns in the table
  183. *
  184. * If a row index is specified, the count will not take
  185. * the spanned cells into account in the return value.
  186. *
  187. * @param int Row index to serve for cols count
  188. * @access public
  189. * @return int
  190. */
  191. function getColCount($row = null)
  192. {
  193. if (!is_null($row)) {
  194. $count = 0;
  195. foreach ($this->_structure[$row] as $cell) {
  196. if (is_array($cell)) {
  197. $count++;
  198. }
  199. }
  200. return $count;
  201. }
  202. return $this->_cols;
  203. }
  204. /**
  205. * Sets a rows type 'TH' or 'TD'
  206. * @param int $row Row index
  207. * @param string $type 'TH' or 'TD'
  208. * @access public
  209. */
  210. function setRowType($row, $type)
  211. {
  212. for ($counter = 0; $counter < $this->_cols; $counter++) {
  213. $this->_structure[$row][$counter]['type'] = $type;
  214. }
  215. }
  216. /**
  217. * Sets a columns type 'TH' or 'TD'
  218. * @param int $col Column index
  219. * @param string $type 'TH' or 'TD'
  220. * @access public
  221. */
  222. function setColType($col, $type)
  223. {
  224. for ($counter = 0; $counter < $this->_rows; $counter++) {
  225. $this->_structure[$counter][$col]['type'] = $type;
  226. }
  227. }
  228. /**
  229. * Sets the cell attributes for an existing cell.
  230. *
  231. * If the given indices do not exist and autoGrow is true then the given
  232. * row and/or col is automatically added. If autoGrow is false then an
  233. * error is returned.
  234. * @param int $row Row index
  235. * @param int $col Column index
  236. * @param mixed $attributes Associative array or string of table row attributes
  237. * @access public
  238. * @throws PEAR_Error
  239. */
  240. function setCellAttributes($row, $col, $attributes)
  241. {
  242. if (isset($this->_structure[$row][$col]) && $this->_structure[$row][$col] == '__SPANNED__') return;
  243. $attributes = $this->_parseAttributes($attributes);
  244. $err = $this->_adjustEnds($row, $col, 'setCellAttributes', $attributes);
  245. if (PEAR::isError($err)) {
  246. return $err;
  247. }
  248. $this->_structure[$row][$col]['attr'] = $attributes;
  249. $this->_updateSpanGrid($row, $col);
  250. }
  251. /**
  252. * Updates the cell attributes passed but leaves other existing attributes in tact
  253. * @param int $row Row index
  254. * @param int $col Column index
  255. * @param mixed $attributes Associative array or string of table row attributes
  256. * @access public
  257. */
  258. function updateCellAttributes($row, $col, $attributes)
  259. {
  260. if (isset($this->_structure[$row][$col]) && $this->_structure[$row][$col] == '__SPANNED__') return;
  261. $attributes = $this->_parseAttributes($attributes);
  262. $err = $this->_adjustEnds($row, $col, 'updateCellAttributes', $attributes);
  263. if (PEAR::isError($err)) {
  264. return $err;
  265. }
  266. $this->_updateAttrArray($this->_structure[$row][$col]['attr'], $attributes);
  267. $this->_updateSpanGrid($row, $col);
  268. }
  269. /**
  270. * Returns the attributes for a given cell
  271. * @param int $row Row index
  272. * @param int $col Column index
  273. * @return array
  274. * @access public
  275. */
  276. function getCellAttributes($row, $col)
  277. {
  278. if (isset($this->_structure[$row][$col]) && $this->_structure[$row][$col] != '__SPANNED__') {
  279. return $this->_structure[$row][$col]['attr'];
  280. } elseif (!isset($this->_structure[$row][$col])) {
  281. return PEAR::raiseError('Invalid table cell reference[' .
  282. $row . '][' . $col . '] in HTML_Table::getCellAttributes');
  283. }
  284. return;
  285. }
  286. /**
  287. * Sets the cell contents for an existing cell
  288. *
  289. * If the given indices do not exist and autoGrow is true then the given
  290. * row and/or col is automatically added. If autoGrow is false then an
  291. * error is returned.
  292. * @param int $row Row index
  293. * @param int $col Column index
  294. * @param mixed $contents May contain html or any object with a toHTML method;
  295. * if it is an array (with strings and/or objects), $col
  296. * will be used as start offset and the array elements
  297. * will be set to this and the following columns in $row
  298. * @param string $type (optional) Cell type either 'TH' or 'TD'
  299. * @access public
  300. * @throws PEAR_Error
  301. */
  302. function setCellContents($row, $col, $contents, $type = 'TD')
  303. {
  304. if (is_array($contents)) {
  305. foreach ($contents as $singleContent) {
  306. $ret = $this->_setSingleCellContents($row, $col, $singleContent, $type);
  307. if (PEAR::isError($ret)) {
  308. return $ret;
  309. }
  310. $col++;
  311. }
  312. } else {
  313. $ret = $this->_setSingleCellContents($row, $col, $contents, $type);
  314. if (PEAR::isError($ret)) {
  315. return $ret;
  316. }
  317. }
  318. }
  319. /**
  320. * Sets the cell contents for a single existing cell
  321. *
  322. * If the given indices do not exist and autoGrow is true then the given
  323. * row and/or col is automatically added. If autoGrow is false then an
  324. * error is returned.
  325. * @param int $row Row index
  326. * @param int $col Column index
  327. * @param mixed $contents May contain html or any object with a toHTML method;
  328. * if it is an array (with strings and/or objects), $col
  329. * will be used as start offset and the array elements
  330. * will be set to this and the following columns in $row
  331. * @param string $type (optional) Cell type either 'TH' or 'TD'
  332. * @access private
  333. * @throws PEAR_Error
  334. */
  335. function _setSingleCellContents($row, $col, $contents, $type = 'TD')
  336. {
  337. if (isset($this->_structure[$row][$col]) && $this->_structure[$row][$col] == '__SPANNED__') return;
  338. $err = $this->_adjustEnds($row, $col, 'setCellContents');
  339. if (PEAR::isError($err)) {
  340. return $err;
  341. }
  342. $this->_structure[$row][$col]['contents'] = $contents;
  343. $this->_structure[$row][$col]['type'] = $type;
  344. }
  345. /**
  346. * Returns the cell contents for an existing cell
  347. * @param int $row Row index
  348. * @param int $col Column index
  349. * @access public
  350. * @return mixed
  351. */
  352. function getCellContents($row, $col)
  353. {
  354. if (isset($this->_structure[$row][$col]) && $this->_structure[$row][$col] == '__SPANNED__') return;
  355. if (!isset($this->_structure[$row][$col])) {
  356. return PEAR::raiseError('Invalid table cell reference[' .
  357. $row . '][' . $col . '] in HTML_Table::getCellContents');
  358. }
  359. return $this->_structure[$row][$col]['contents'];
  360. }
  361. /**
  362. * Sets the contents of a header cell
  363. * @param int $row
  364. * @param int $col
  365. * @param mixed $contents
  366. * @param mixed $attributes Associative array or string of table row attributes
  367. * @access public
  368. */
  369. function setHeaderContents($row, $col, $contents, $attributes = null)
  370. {
  371. $this->setCellContents($row, $col, $contents, 'TH');
  372. if (!is_null($attributes)) {
  373. $this->updateCellAttributes($row, $col, $attributes);
  374. }
  375. }
  376. /**
  377. * Adds a table row and returns the row identifier
  378. * @param array $contents (optional) Must be a indexed array of valid cell contents
  379. * @param mixed $attributes (optional) Associative array or string of table row attributes
  380. * This can also be an array of attributes, in which case the attributes
  381. * will be repeated in a loop.
  382. * @param string $type (optional) Cell type either 'th' or 'td'
  383. * @param bool $inTR false if attributes are to be applied in TD tags
  384. * true if attributes are to be applied in TR tag
  385. * @return int
  386. * @access public
  387. */
  388. function addRow($contents = null, $attributes = null, $type = 'td', $inTR = false)
  389. {
  390. if (isset($contents) && !is_array($contents)) {
  391. return PEAR::raiseError('First parameter to HTML_Table::addRow must be an array');
  392. }
  393. if (is_null($contents)) {
  394. $contents = array();
  395. }
  396. $type = strtolower($type);
  397. $row = $this->_rows++;
  398. foreach ($contents as $col => $content) {
  399. if ($type == 'td') {
  400. $this->setCellContents($row, $col, $content);
  401. } elseif ($type == 'th') {
  402. $this->setHeaderContents($row, $col, $content);
  403. }
  404. }
  405. $this->setRowAttributes($row, $attributes, $inTR);
  406. return $row;
  407. }
  408. /**
  409. * Sets the row attributes for an existing row
  410. * @param int $row Row index
  411. * @param mixed $attributes Associative array or string of table row attributes
  412. * This can also be an array of attributes, in which case the attributes
  413. * will be repeated in a loop.
  414. * @param bool $inTR false if attributes are to be applied in TD tags
  415. * true if attributes are to be applied in TR tag
  416. * @access public
  417. * @throws PEAR_Error
  418. */
  419. function setRowAttributes($row, $attributes, $inTR = false)
  420. {
  421. if (!$inTR) {
  422. $multiAttr = $this->_isAttributesArray($attributes);
  423. for ($i = 0; $i < $this->_cols; $i++) {
  424. if ($multiAttr) {
  425. $this->setCellAttributes($row, $i,
  426. $attributes[$i - ((ceil(($i + 1) / count($attributes))) - 1) * count($attributes)]);
  427. } else {
  428. $this->setCellAttributes($row, $i, $attributes);
  429. }
  430. }
  431. } else {
  432. $attributes = $this->_parseAttributes($attributes);
  433. $err = $this->_adjustEnds($row, 0, 'setRowAttributes', $attributes);
  434. if (PEAR::isError($err)) {
  435. return $err;
  436. }
  437. $this->_structure[$row]['attr'] = $attributes;
  438. }
  439. }
  440. /**
  441. * Updates the row attributes for an existing row
  442. * @param int $row Row index
  443. * @param mixed $attributes Associative array or string of table row attributes
  444. * @param bool $inTR false if attributes are to be applied in TD tags
  445. * true if attributes are to be applied in TR tag
  446. * @access public
  447. * @throws PEAR_Error
  448. */
  449. function updateRowAttributes($row, $attributes = null, $inTR = false)
  450. {
  451. if (!$inTR) {
  452. $multiAttr = $this->_isAttributesArray($attributes);
  453. for ($i = 0; $i < $this->_cols; $i++) {
  454. if ($multiAttr) {
  455. $this->updateCellAttributes($row, $i,
  456. $attributes[$i - ((ceil(($i + 1) / count($attributes))) - 1) * count($attributes)]);
  457. } else {
  458. $this->updateCellAttributes($row, $i, $attributes);
  459. }
  460. }
  461. } else {
  462. $attributes = $this->_parseAttributes($attributes);
  463. $err = $this->_adjustEnds($row, 0, 'updateRowAttributes', $attributes);
  464. if (PEAR::isError($err)) {
  465. return $err;
  466. }
  467. $this->_updateAttrArray($this->_structure[$row]['attr'], $attributes);
  468. }
  469. }
  470. /**
  471. * Returns the attributes for a given row as contained in the TR tag
  472. * @param int $row Row index
  473. * @return array
  474. * @access public
  475. */
  476. function getRowAttributes($row)
  477. {
  478. if (isset($this->_structure[$row]['attr'])) {
  479. return $this->_structure[$row]['attr'];
  480. }
  481. return;
  482. }
  483. /**
  484. * Alternates the row attributes starting at $start
  485. * @param int $start Row index of row in which alternating begins
  486. * @param mixed $attributes1 Associative array or string of table row attributes
  487. * @param mixed $attributes2 Associative array or string of table row attributes
  488. * @param bool $inTR false if attributes are to be applied in TD tags
  489. * true if attributes are to be applied in TR tag
  490. * @access public
  491. */
  492. function altRowAttributes($start, $attributes1, $attributes2, $inTR = false)
  493. {
  494. for ($row = $start ; $row < $this->_rows ; $row++) {
  495. $attributes = ( ($row + $start) % 2 == 0 ) ? $attributes1 : $attributes2;
  496. $this->updateRowAttributes($row, $attributes, $inTR);
  497. }
  498. }
  499. /**
  500. * Adds a table column and returns the column identifier
  501. * @param array $contents (optional) Must be a indexed array of valid cell contents
  502. * @param mixed $attributes (optional) Associative array or string of table row attributes
  503. * @param string $type (optional) Cell type either 'th' or 'td'
  504. * @return int
  505. * @access public
  506. */
  507. function addCol($contents = null, $attributes = null, $type = 'td')
  508. {
  509. if (isset($contents) && !is_array($contents)) {
  510. return PEAR::raiseError('First parameter to HTML_Table::addCol must be an array');
  511. }
  512. if (is_null($contents)) {
  513. $contents = array();
  514. }
  515. $type = strtolower($type);
  516. $col = $this->_cols++;
  517. foreach ($contents as $row => $content) {
  518. if ($type == 'td') {
  519. $this->setCellContents($row, $col, $content);
  520. } elseif ($type == 'th') {
  521. $this->setHeaderContents($row, $col, $content);
  522. }
  523. }
  524. $this->setColAttributes($col, $attributes);
  525. return $col;
  526. }
  527. /**
  528. * Sets the column attributes for an existing column
  529. * @param int $col Column index
  530. * @param mixed $attributes (optional) Associative array or string of table row attributes
  531. * @access public
  532. */
  533. function setColAttributes($col, $attributes = null)
  534. {
  535. $multiAttr = $this->_isAttributesArray($attributes);
  536. for ($i = 0; $i < $this->_rows; $i++) {
  537. if ($multiAttr) {
  538. $this->setCellAttributes($i, $col,
  539. $attributes[$i - ((ceil(($i + 1) / count($attributes))) - 1) * count($attributes)]);
  540. } else {
  541. $this->setCellAttributes($i, $col, $attributes);
  542. }
  543. }
  544. }
  545. /**
  546. * Updates the column attributes for an existing column
  547. * @param int $col Column index
  548. * @param mixed $attributes (optional) Associative array or string of table row attributes
  549. * @access public
  550. */
  551. function updateColAttributes($col, $attributes = null)
  552. {
  553. $multiAttr = $this->_isAttributesArray($attributes);
  554. for ($i = 0; $i < $this->_rows; $i++) {
  555. if ($multiAttr) {
  556. $this->updateCellAttributes($i, $col,
  557. $attributes[$i - ((ceil(($i + 1) / count($attributes))) - 1) * count($attributes)]);
  558. } else {
  559. $this->updateCellAttributes($i, $col, $attributes);
  560. }
  561. }
  562. }
  563. /**
  564. * Sets the attributes for all cells
  565. * @param mixed $attributes (optional) Associative array or string of table row attributes
  566. * @access public
  567. */
  568. function setAllAttributes($attributes = null)
  569. {
  570. for ($i = 0; $i < $this->_rows; $i++) {
  571. $this->setRowAttributes($i, $attributes);
  572. }
  573. }
  574. /**
  575. * Updates the attributes for all cells
  576. * @param mixed $attributes (optional) Associative array or string of table row attributes
  577. * @access public
  578. */
  579. function updateAllAttributes($attributes = null)
  580. {
  581. for ($i = 0; $i < $this->_rows; $i++) {
  582. $this->updateRowAttributes($i, $attributes);
  583. }
  584. }
  585. /**
  586. * Returns the table rows as HTML
  587. * @access public
  588. * @return string
  589. */
  590. function toHtml($tabs = null, $tab = null)
  591. {
  592. $strHtml = '';
  593. if (is_null($tabs)) {
  594. $tabs = $this->_getTabs();
  595. }
  596. if (is_null($tab)) {
  597. $tab = $this->_getTab();
  598. }
  599. $lnEnd = $this->_getLineEnd();
  600. if ($this->_useTGroups) {
  601. $extraTab = $tab;
  602. } else {
  603. $extraTab = '';
  604. }
  605. for ($i = 0 ; $i < $this->_rows ; $i++) {
  606. $attr = '';
  607. if (isset($this->_structure[$i]['attr'])) {
  608. $attr = $this->_getAttrString($this->_structure[$i]['attr']);
  609. }
  610. $strHtml .= $tabs .$tab . $extraTab . '<tr'.$attr.'>' . $lnEnd;
  611. for ($j = 0 ; $j < $this->_cols ; $j++) {
  612. $attr = '';
  613. $contents = '';
  614. $type = 'td';
  615. if (isset($this->_structure[$i][$j]) && $this->_structure[$i][$j] == '__SPANNED__') {
  616. $strHtml .= $tabs . $tab . $tab . $extraTab . '<!-- span -->' . $lnEnd;
  617. continue;
  618. }
  619. if (isset($this->_structure[$i][$j]['type'])) {
  620. $type = (strtolower($this->_structure[$i][$j]['type']) == 'th' ? 'th' : 'td');
  621. }
  622. if (isset($this->_structure[$i][$j]['attr'])) {
  623. $attr = $this->_structure[$i][$j]['attr'];
  624. }
  625. if (isset($this->_structure[$i][$j]['contents'])) {
  626. $contents = $this->_structure[$i][$j]['contents'];
  627. }
  628. $strHtml .= $tabs . $tab . $tab . $extraTab . "<$type" . $this->_getAttrString($attr) . '>';
  629. if (is_object($contents)) {
  630. // changes indent and line end settings on nested tables
  631. if (is_subclass_of($contents, 'html_common')) {
  632. $contents->setTab($tab . $extraTab);
  633. $contents->setTabOffset($this->_tabOffset + 3);
  634. $contents->_nestLevel = $this->_nestLevel + 1;
  635. $contents->setLineEnd($this->_getLineEnd());
  636. }
  637. if (method_exists($contents, 'toHtml')) {
  638. $contents = $contents->toHtml();
  639. } elseif (method_exists($contents, 'toString')) {
  640. $contents = $contents->toString();
  641. }
  642. }
  643. if (is_array($contents)) {
  644. $contents = implode(', ', $contents);
  645. }
  646. if (isset($this->_autoFill) && $contents === '') {
  647. $contents = $this->_autoFill;
  648. }
  649. $strHtml .= $contents;
  650. $strHtml .= "</$type>" . $lnEnd;
  651. }
  652. $strHtml .= $tabs . $tab . $extraTab . '</tr>' . $lnEnd;
  653. }
  654. return $strHtml;
  655. }
  656. /**
  657. * Checks if rows or columns are spanned
  658. * @param int $row Row index
  659. * @param int $col Column index
  660. * @access private
  661. */
  662. function _updateSpanGrid($row, $col)
  663. {
  664. if (isset($this->_structure[$row][$col]['attr']['colspan'])) {
  665. $colspan = $this->_structure[$row][$col]['attr']['colspan'];
  666. }
  667. if (isset($this->_structure[$row][$col]['attr']['rowspan'])) {
  668. $rowspan = $this->_structure[$row][$col]['attr']['rowspan'];
  669. }
  670. if (isset($colspan)) {
  671. for ($j = $col + 1; (($j < $this->_cols) && ($j <= ($col + $colspan - 1))); $j++) {
  672. $this->_structure[$row][$j] = '__SPANNED__';
  673. }
  674. }
  675. if (isset($rowspan)) {
  676. for ($i = $row + 1; (($i < $this->_rows) && ($i <= ($row + $rowspan - 1))); $i++) {
  677. $this->_structure[$i][$col] = '__SPANNED__';
  678. }
  679. }
  680. if (isset($colspan) && isset($rowspan)) {
  681. for ($i = $row + 1; (($i < $this->_rows) && ($i <= ($row + $rowspan - 1))); $i++) {
  682. for ($j = $col + 1; (($j <= $this->_cols) && ($j <= ($col + $colspan - 1))); $j++) {
  683. $this->_structure[$i][$j] = '__SPANNED__';
  684. }
  685. }
  686. }
  687. }
  688. /**
  689. * Adjusts ends (total number of rows and columns)
  690. * @param int $row Row index
  691. * @param int $col Column index
  692. * @param string $method Method name of caller
  693. * Used to populate PEAR_Error if thrown.
  694. * @param array $attributes Assoc array of attributes
  695. * Default is an empty array.
  696. * @access private
  697. * @throws PEAR_Error
  698. */
  699. function _adjustEnds($row, $col, $method, $attributes = array())
  700. {
  701. $colspan = isset($attributes['colspan']) ? $attributes['colspan'] : 1;
  702. $rowspan = isset($attributes['rowspan']) ? $attributes['rowspan'] : 1;
  703. if (($row + $rowspan - 1) >= $this->_rows) {
  704. if ($this->_autoGrow) {
  705. $this->_rows = $row + $rowspan;
  706. } else {
  707. return PEAR::raiseError('Invalid table row reference[' .
  708. $row . '] in HTML_Table::' . $method);
  709. }
  710. }
  711. if (($col + $colspan - 1) >= $this->_cols) {
  712. if ($this->_autoGrow) {
  713. $this->_cols = $col + $colspan;
  714. } else {
  715. return PEAR::raiseError('Invalid table column reference[' .
  716. $col . '] in HTML_Table::' . $method);
  717. }
  718. }
  719. }
  720. /**
  721. * Tells if the parameter is an array of attribute arrays/strings
  722. * @param mixed $attributes Variable to test
  723. * @access private
  724. * @return bool
  725. */
  726. function _isAttributesArray($attributes)
  727. {
  728. if (is_array($attributes) && isset($attributes[0])) {
  729. if (is_array($attributes[0]) || (is_string($attributes[0]) && count($attributes) > 1)) {
  730. return true;
  731. }
  732. }
  733. return false;
  734. }
  735. }
  736. ?>