cvs: php4 /pear/HTML Table.php
| From: | Adam Daniel | Date: | Mon, 06 Aug 2001 21:14:39 +0000 |
| Subject: | cvs: php4 /pear/HTML Table.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-428@lists.php.net to get a copy of this message | ||
adaniel Mon Aug 6 17:14:39 2001 EDT
Modified files:
/php4/pear/HTML Table.php
Log:
fixed problem with spanning cells
Index: php4/pear/HTML/Table.php
diff -u php4/pear/HTML/Table.php:1.8 php4/pear/HTML/Table.php:1.9
--- php4/pear/HTML/Table.php:1.8 Mon Aug 6 17:02:02 2001
+++ php4/pear/HTML/Table.php Mon Aug 6 17:14:39 2001
@@ -17,7 +17,7 @@
// | Bertrand Mansion <bmansion@mamasam.com> |
// +----------------------------------------------------------------------+
//
-// $Id: Table.php,v 1.8 2001/08/06 21:02:02 adaniel Exp $
+// $Id: Table.php,v 1.9 2001/08/06 21:14:39 adaniel Exp $
require_once "PEAR.php";
require_once "HTML/Common.php";
@@ -234,22 +234,12 @@
*/
function setCellAttributes($row, $col, $attributes)
{
- if (isset($this->_structure[$row][$col]) && $this->_structure[$row][$col] ==
"SPANNED") return;
- if ($row >= $this->_rows) {
- if ($this->_autoGrow) {
- $this->_rows = $row+1;
- } else {
- return new PEAR_Error("Invalid table row reference[$row] in
HTML_Table::setCellAttributes");
- }
- }
- if ($col >= $this->_cols) {
- if ($this->_autoGrow) {
- $this->_cols = $col+1;
- } else {
- return new PEAR_Error("Invalid table column reference[$col] in
HTML_Table::setCellAttributes");
- }
- }
+ if (isset($this->_structure[$row][$col]) && $this->_structure[$row][$col] ==
"__SPANNED__") return;
$attributes = $this->_parseAttributes($attributes);
+ $err = $this->_adjustEnds($row, $col, 'setCellAttributes', $attributes);
+ if (PEAR::isError($err)) {
+ return $err;
+ }
$this->_structure[$row][$col]["attr"] = $attributes;
$this->_updateSpanGrid($row, $col);
} // end func setCellAttributes
@@ -263,8 +253,12 @@
*/
function updateCellAttributes($row, $col, $attributes)
{
- if (isset($this->_structure[$row][$col]) && $this->_structure[$row][$col] ==
"SPANNED") return;
+ if (isset($this->_structure[$row][$col]) && $this->_structure[$row][$col] ==
"__SPANNED__") return;
$attributes = $this->_parseAttributes($attributes);
+ $err = $this->_adjustEnds($row, $col, 'updateCellAttributes', $attributes);
+ if (PEAR::isError($err)) {
+ return $err;
+ }
$this->_updateAttrArray($this->_structure[$row][$col]["attr"],
$attributes);
$this->_updateSpanGrid($row, $col);
} // end func updateCellAttributes
@@ -284,20 +278,10 @@
*/
function setCellContents($row, $col, $contents, $type='TD')
{
- if(isset($this->_structure[$row][$col]) && $this->_structure[$row][$col] ==
"SPANNED") return;
- if ($row >= $this->_rows) {
- if ($this->_autoGrow) {
- $this->_rows = $row+1;
- } else {
- return new PEAR_Error("Invalid table row reference[$row] in
HTML_Table::setCellContents");
- }
- }
- if ($col >= $this->_cols) {
- if ($this->_autoGrow) {
- $this->_cols = $col+1;
- } else {
- return new PEAR_Error("Invalid table column reference[$col] in
HTML_Table::setCellContents");
- }
+ if(isset($this->_structure[$row][$col]) && $this->_structure[$row][$col] ==
"__SPANNED__") return;
+ $err = $this->_adjustEnds($row, $col, 'setCellContents');
+ if (PEAR::isError($err)) {
+ return $err;
}
$this->_structure[$row][$col]["contents"] = $contents;
$this->_structure[$row][$col]["type"] = $type;
@@ -312,7 +296,7 @@
*/
function getCellContents($row, $col)
{
- if (isset($this->_structure[$row][$col]) && $this->_structure[$row][$col] ==
"SPANNED") return;
+ if (isset($this->_structure[$row][$col]) && $this->_structure[$row][$col] ==
"__SPANNED__") return;
return $this->_structure[$row][$col]["contents"];
} // end func getCellContents
@@ -467,7 +451,7 @@
for ($i = 0 ; $i < $this->_rows ; $i++) {
$strHtml .= $tabs ."\t<TR>\n";
for ($j = 0 ; $j < $this->_cols ; $j++) {
- if (isset($this -> _structure[$i][$j]) && $this->_structure[$i][$j]
== "SPANNED") {
+ if (isset($this -> _structure[$i][$j]) && $this->_structure[$i][$j]
== "__SPANNED__") {
$strHtml .= $tabs ."\t\t<!-- span -->\n";
continue;
}
@@ -533,22 +517,55 @@
}
if (isset($colspan)) {
for ($j = $col+1; (($j < $this->_cols) && ($j <= ($col + $colspan -
1))); $j++) {
- $this->_structure[$row][$j] = "SPANNED";
+ $this->_structure[$row][$j] = "__SPANNED__";
}
}
if (isset($rowspan)) {
for ($i = $row+1; (($i < $this->_rows) && ($i <= ($row + $rowspan -
1))); $i++) {
- $this->_structure[$i][$col] = "SPANNED";
+ $this->_structure[$i][$col] = "__SPANNED__";
}
}
if (isset($colspan) && isset($rowspan)) {
for ($i = $row+1; (($i < $this->_rows) && ($i <= ($row + $rowspan -
1))); $i++) {
for ($j = $col+1; (($j <= $this->_cols) && ($j <= ($col + $colspan
- 1))); $j++) {
- $this->_structure[$i][$j] = "SPANNED";
+ $this->_structure[$i][$j] = "__SPANNED__";
}
}
}
} // end func _updateSpanGrid
+ /**
+ * Adjusts ends (total number of rows and columns)
+ * @param int $row Row index
+ * @param int $col Column index
+ * @param string $method Method name of caller
+ * Used to populate PEAR_Error if thrown.
+ * @param array $attributes Assoc array of attributes
+ * Default is an empty array.
+ * @access private
+ * @throws PEAR_Error
+ */
+ function _adjustEnds($row, $col, $method, $attributes = array())
+ {
+ $colspan = isset($attributes['colspan']) ? $attributes['colspan'] : 1;
+ $rowspan = isset($attributes['rowspan']) ? $attributes['rowspan'] : 1;
+ if (($row + $rowspan - 1) >= $this->_rows) {
+ if ($this->_autoGrow) {
+ $this->_rows = $row + $rowspan;
+ } else {
+ return new PEAR_Error('Invalid table row reference[' .
+ $row . '] in HTML_Table::' . $method);
+ }
+ }
+ if (($col + $colspan - 1) >= $this->_cols) {
+ if ($this->_autoGrow) {
+ $this->_cols = $col + $colspan;
+ } else {
+ return new PEAR_Error('Invalid table column reference[' .
+ $col . '] in HTML_Table::' . $method);
+ }
+ }
+ }
+
} // end class HTML_Table
-?>
+?>