📄 table.php
字号:
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | PHP version 4.0 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Adam Daniel <adaniel1@eesus.jnj.com> |
// | Bertrand Mansion <bmansion@mamasam.com> |
// +----------------------------------------------------------------------+
//
// $Id: Table.php,v 1.9 2001/08/06 21:14:39 adaniel Exp $
require_once "PEAR.php";
require_once "HTML/Common.php";
/**
* Builds an HTML table
*
* @author Adam Daniel <adaniel1@eesus.jnj.com>
* @author Bertrand Mansion <bmansion@mamasam.com>
* @version 1.5
* @since PHP 4.0.3pl1
*/
class HTML_Table extends HTML_Common {
/**
* Automatically adds a new row or column if a given row or column index does not exist
* @var bool
* @access private
*/
var $_autoGrow = true;
/**
* Value to insert into empty cells
* @var string
* @access private
*/
var $_autoFill = " ";
/**
* Array containing the table structure
* @var array
* @access private
*/
var $_structure = array();
/**
* Number of rows composing in the table
* @var int
* @access private
*/
var $_rows = 0;
/**
* Number of column composing the table
* @var int
* @access private
*/
var $_cols = 0;
/**
* Tracks the level of nested tables
* @var
* @since 1.5
* @access private
*/
var $_nestLevel = 0;
/**
* Class constructor
* @param array $attributes Associative array of table tag attributes
* @param int $tabOffset
* @access public
*/
function HTML_Table($attributes=null, $tabOffset=0)
{
$commonVersion = 1.3;
if (HTML_Common::apiVersion() < $commonVersion) {
return new PEAR_Error("HTML_Table version " . $this->apiVersion() . " requires " .
"HTML_Common version $commonVersion or greater.", 0, PEAR_ERROR_TRIGGER);
}
HTML_Common::HTML_Common($attributes, $tabOffset);
} // end constructor
/**
* Returns the API version
* @access public
* @returns double
*/
function apiVersion()
{
return 1.5;
} // end func apiVersion
/**
* Sets the table caption
* @param string $caption
* @param mixed $attributes Associative array or string of table row attributes
* @access public
*/
function setCaption($caption, $attributes=null)
{
$attributes = $this->_parseAttributes($attributes);
$this->_structure["caption"] = array("attr"=>$attributes, "contents"=>$caption);
} // end func setCaption
/**
* Sets the autoFill value
* @param mixed $fill
* @access public
*/
function setAutoFill($fill)
{
$this->_autoFill = $fill;
} // end func setAutoFill
/**
* Returns the autoFill value
* @access public
* @returns mixed
*/
function getAutoFill()
{
return $this->_autoFill;
} // end func getAutoFill
/**
* Sets the autoGrow value
* @param bool $fill
* @access public
*/
function setAutoGrow($grow)
{
$this->_autoGrow = $grow;
} // end func setAutoGrow
/**
* Returns the autoGrow value
* @access public
* @returns mixed
*/
function getAutoGrow()
{
return $this->_autoGrow;
} // end func getAutoGrow
/**
* Sets the number of rows in the table
* @param int $rows
* @access public
*/
function setRowCount($rows)
{
$this->_rows = $rows;
} // end func setRowCount
/**
* Sets the number of columns in the table
* @param int $cols
* @access public
*/
function setColCount($cols)
{
$this->_cols = $cols;
} // end func setColCount
/**
* Returns the number of rows in the table
* @access public
* @returns int
*/
function getRowCount()
{
return $this->_rows;
} // end func getRowCount
/**
* Sets the number of columns in the table
* @access public
* @returns int
*/
function getColCount()
{
return $this->_cols;
} // end func getColCount
/**
* Sets a rows type 'TH' or 'TD'
* @param int $row Row index
* @param string $type 'TH' or 'TD'
* @access public
*/
function setRowType($row, $type)
{
for ($counter=0; $counter < $this->_cols; $counter++) {
$this->_structure[$row][$counter]["type"] = $type;
}
} // end func setRowType
/**
* Sets a columns type 'TH' or 'TD'
* @param int $col Column index
* @param string $type 'TH' or 'TD'
* @access public
*/
function setColType($col, $type)
{
for ($counter=0; $counter < $this->_rows; $counter++) {
$this->_structure[$counter][$col]["type"] = $type;
}
} // end func setColType
/**
* Sets the cell attributes for an existing cell.
*
* If the given indices do not exist and autoGrow is true then the given
* row and/or col is automatically added. If autoGrow is false then an
* error is returned.
* @param int $row Row index
* @param int $col Column index
* @param mixed $attributes Associative array or string of table row attributes
* @access public
* @throws PEAR_Error
*/
function setCellAttributes($row, $col, $attributes)
{
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
/**
* Updates the cell attributes passed but leaves other existing attributes in tact
* @param int $row Row index
* @param int $col Column index
* @param mixed $attributes Associative array or string of table row attributes
* @access public
*/
function updateCellAttributes($row, $col, $attributes)
{
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
/**
* Sets the cell contents for an existing cell
*
* If the given indices do not exist and autoGrow is true then the given
* row and/or col is automatically added. If autoGrow is false then an
* error is returned.
* @param int $row Row index
* @param int $col Column index
* @param mixed $contents May contain html or any object with a toHTML method
* @param string $type (optional) Cell type either 'TH' or 'TD'
* @access public
* @throws PEAR_Error
*/
function setCellContents($row, $col, $contents, $type='TD')
{
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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -