<?php
require_once 'HTML/Table.php';
/**
* @author Laurent Laville
*/
class HTML_Table_ColGroup extends HTML_Table {
/**
* Array containing the table column group specifications
*
* @var array
* @access private
*/
var $_colgroup = array();
/**
* Class constructor (ZE1)
*/
function HTML_Table_ColGroup($attributes = null, $tabOffset = 0, $useTGroups = false)
{
$this->HTML_Table($attributes, $tabOffset, $useTGroups);
}
/**
* Sets the table columns group specifications, or removes existing ones.
*
* @param mixed $colgroup (optional) Columns attributes
* @param mixed $attributes (optional) Associative array or string of table row attributes
* @access public
*/
function setColGroup($colgroup = null, $attributes = null)
{
if (isset($colgroup)) {
$attributes = $this->_parseAttributes($attributes);
$this->_colgroup[] = array('attr' => $attributes, 'contents' => $colgroup);
} else {
$this->_colgroup = array();
}
}
/**
* Returns the table structure as HTML
* !!! Code are copied from HTML_Table except for paragraph between lines 70 to 86 !!!
*
* @access public
* @return string
*/
function toHtml()
{
$strHtml = '';
$tabs = $this->_getTabs();
$tab = $this->_getTab();
$lnEnd = $this->_getLineEnd();
if ($this->_comment) {
$strHtml .= $tabs . "<!-- $this->_comment -->" . $lnEnd;
}
$strHtml .=
$tabs . '<table' . $this->_getAttrString($this->_attributes) . '>' . $lnEnd;
if (!empty($this->_caption)) {
$attr = $this->_caption['attr'];
$contents = $this->_caption['contents'];
$strHtml .= $tabs . $tab . '<caption' . $this->_getAttrString($attr) . '>';
if (is_array($contents)) {
$contents = implode(', ', $contents);
}
$strHtml .= $contents;
$strHtml .= '</caption>' . $lnEnd;
}
if (!empty($this->_colgroup)) {
foreach($this->_colgroup as $g => $col) {
$attr = $this->_colgroup[$g]['attr'];
$contents = $this->_colgroup[$g]['contents'];
$strHtml .= $tabs . $tab . '<colgroup' . $this->_getAttrString($attr) . '>';
if (!empty($contents)) {
$strHtml .= $lnEnd;
if (!is_array($contents)) {
$contents = array($contents);
}
foreach($contents as $a => $colAttr) {
$attr = $this->_parseAttributes($colAttr);
$strHtml .= $tabs . $tab . $tab . '<col' . $this->_getAttrString($attr) . '>' . $lnEnd;
}
$strHtml .= $tabs . $tab;
}
$strHtml .= '</colgroup>' . $lnEnd;
}
}
if ($this->_useTGroups) {
$tHeadColCount = 0;
if ($this->_thead !== null) {
$tHeadColCount = $this->_thead->getColCount();
}
$tFootColCount = 0;
if ($this->_tfoot !== null) {
$tFootColCount = $this->_tfoot->getColCount();
}
$tBodyColCount = 0;
if ($this->_tbody !== null) {
$tBodyColCount = $this->_tbody->getColCount();
}
$maxColCount = max($tHeadColCount, $tFootColCount, $tBodyColCount);
if ($this->_thead !== null) {
$this->_thead->setColCount($maxColCount);
if ($this->_thead->getRowCount() > 0) {
$strHtml .= $tabs . $tab . '<thead>' . $lnEnd;
$strHtml .= $this->_thead->toHtml();
$strHtml .= $tabs . $tab . '</thead>' . $lnEnd;
}
}
if ($this->_tfoot !== null) {
$this->_tfoot->setColCount($maxColCount);
if ($this->_tfoot->getRowCount() > 0) {
$strHtml .= $tabs . $tab . '<tfoot>' . $lnEnd;
$strHtml .= $this->_tfoot->toHtml();
$strHtml .= $tabs . $tab . '</tfoot>' . $lnEnd;
}
}
if ($this->_tbody !== null) {
$this->_tbody->setColCount($maxColCount);
if ($this->_tbody->getRowCount() > 0) {
$strHtml .= $tabs . $tab . '<tbody>' . $lnEnd;
$strHtml .= $this->_tbody->toHtml();
$strHtml .= $tabs . $tab . '</tbody>' . $lnEnd;
}
}
} else {
$strHtml .= $this->_tbody->toHtml();
}
$strHtml .= $tabs . '</table>' . $lnEnd;
return $strHtml;
}
}
?>