⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 storage.php

📁 完美的在线教育系统
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: *//** * Storage class for HTML::Table data * * This class stores data for tables built with HTML_Table. When having * more than one instance, it can be used for grouping the table into the * parts <thead>...</thead>, <tfoot>...</tfoot> and <tbody>...</tbody>. * * PHP versions 4 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt.  If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category   HTML * @package    HTML_Table * @author     Adam Daniel <adaniel1@eesus.jnj.com> * @author     Bertrand Mansion <bmansion@mamasam.com> * @copyright  2005 The PHP Group * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 * @version    CVS: $Id: Storage.php,v 1.9 2006/09/18 20:06:45 wiesemann Exp $ * @link       http://pear.php.net/package/HTML_Table *//** * Storage class for HTML::Table data * * This class stores data for tables built with HTML_Table. When having * more than one instance, it can be used for grouping the table into the * parts <thead>...</thead>, <tfoot>...</tfoot> and <tbody>...</tbody>. * * @category   HTML * @package    HTML_Table * @author     Adam Daniel <adaniel1@eesus.jnj.com> * @author     Bertrand Mansion <bmansion@mamasam.com> * @author     Mark Wiesemann <wiesemann@php.net> * @copyright  2005 The PHP Group * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 * @version    Release: @package_version@ * @link       http://pear.php.net/package/HTML_Table */class HTML_Table_Storage extends HTML_Common {    /**     * Value to insert into empty cells     * @var    string     * @access private     */    var $_autoFill = '&nbsp;';    /**     * Automatically adds a new row or column if a given row or column index does not exist     * @var    bool     * @access private     */    var $_autoGrow = true;    /**     * 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    int     * @access private     */    var $_nestLevel = 0;    /**     * Whether to use <thead>, <tfoot> and <tbody> or not     * @var    bool     * @access private     */    var $_useTGroups = false;    /**     * Class constructor     * @param    array    $attributes        Associative array of table tag attributes     * @param    int      $tabOffset     * @param    bool     $useTGroups        Whether to use <thead>, <tfoot> and     *                                       <tbody> or not     * @access   public     */    function HTML_Table_Storage($attributes = null, $tabOffset = 0, $useTGroups = false)    {        HTML_Common::HTML_Common($attributes, (int)$tabOffset);        $this->_useTGroups = (boolean)$useTGroups;    }    /**     * Sets the useTGroups value     * @param   boolean   $useTGroups     * @access  public     */    function setUseTGroups($useTGroups)    {        $this->_useTGroups = $useTGroups;    }    /**     * Returns the useTGroups value     * @access   public     * @return   boolean     */    function getUseTGroups()    {        return $this->_useTGroups;    }    /**     * Sets the autoFill value     * @param   mixed   $fill     * @access  public     */    function setAutoFill($fill)    {        $this->_autoFill = $fill;    }    /**     * Returns the autoFill value     * @access   public     * @return   mixed     */    function getAutoFill()    {        return $this->_autoFill;    }    /**     * Sets the autoGrow value     * @param    bool   $fill     * @access   public     */    function setAutoGrow($grow)    {        $this->_autoGrow = $grow;    }    /**     * Returns the autoGrow value     * @access   public     * @return   mixed     */    function getAutoGrow()    {        return $this->_autoGrow;    }    /**     * Sets the number of rows in the table     * @param    int     $rows     * @access   public     */    function setRowCount($rows)    {        $this->_rows = $rows;    }    /**     * Sets the number of columns in the table     * @param    int     $cols     * @access   public     */    function setColCount($cols)    {        $this->_cols = $cols;    }    /**     * Returns the number of rows in the table     * @access   public     * @return   int     */    function getRowCount()    {        return $this->_rows;    }    /**     * Gets the number of columns in the table     *     * If a row index is specified, the count will not take     * the spanned cells into account in the return value.     *     * @param    int    Row index to serve for cols count     * @access   public     * @return   int     */    function getColCount($row = null)    {        if (!is_null($row)) {            $count = 0;            foreach ($this->_structure[$row] as $cell) {                if (is_array($cell)) {                    $count++;                }            }            return $count;        }        return $this->_cols;    }    /**     * 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;        }    }    /**     * 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;        }    }    /**     * 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);    }    /**     * 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);    }    /**     * Returns the attributes for a given cell     * @param    int     $row         Row index     * @param    int     $col         Column index     * @return   array     * @access   public     */    function getCellAttributes($row, $col)    {        if (isset($this->_structure[$row][$col]) && $this->_structure[$row][$col] != '__SPANNED__') {            return $this->_structure[$row][$col]['attr'];        } elseif (!isset($this->_structure[$row][$col])) {            return PEAR::raiseError('Invalid table cell reference[' .                $row . '][' . $col . '] in HTML_Table::getCellAttributes');        }        return;    }    /**     * 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;     *                                if it is an array (with strings and/or objects), $col     *                                will be used as start offset and the array elements     *                                will be set to this and the following columns in $row     * @param    string   $type       (optional) Cell type either 'TH' or 'TD'     * @access   public     * @throws   PEAR_Error     */    function setCellContents($row, $col, $contents, $type = 'TD')    {        if (is_array($contents)) {            foreach ($contents as $singleContent) {                $ret = $this->_setSingleCellContents($row, $col, $singleContent, $type);                if (PEAR::isError($ret)) {                    return $ret;                }                $col++;            }        } else {            $ret = $this->_setSingleCellContents($row, $col, $contents, $type);            if (PEAR::isError($ret)) {                return $ret;            }        }    }    /**     * Sets the cell contents for a single 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;     *                                if it is an array (with strings and/or objects), $col     *                                will be used as start offset and the array elements     *                                will be set to this and the following columns in $row     * @param    string   $type       (optional) Cell type either 'TH' or 'TD'     * @access   private     * @throws   PEAR_Error     */    function _setSingleCellContents($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;        $this->_structure[$row][$col]['type'] = $type;    }    /**     * Returns the cell contents for an existing cell     * @param    int        $row    Row index     * @param    int        $col    Column index     * @access   public     * @return   mixed     */    function getCellContents($row, $col)    {        if (isset($this->_structure[$row][$col]) && $this->_structure[$row][$col] == '__SPANNED__') return;        if (!isset($this->_structure[$row][$col])) {            return PEAR::raiseError('Invalid table cell reference[' .                $row . '][' . $col . '] in HTML_Table::getCellContents');        }        return $this->_structure[$row][$col]['contents'];    }    /**     * Sets the contents of a header cell     * @param    int     $row     * @param    int     $col

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -