object. This can have a parent or not: if it does, * then it will be painted as a child, otherwise it will act as a root. * * @author Blue Static * @copyright Copyright (c)2005 - 2008, Blue Static * @package ISSO * */ class BSPrinterRootTable extends BSPrinterRootAbstract { /** * Maximum number of columns * @var integer */ private $colspan = 0; /** * Heading child elements * @var array */ private $headers = array(); /** * Width of the table * @var string */ private $width = '90%'; /** * Constructor */ public function __construct() { $this->setCssClass('tborder'); } /** * Makes a new instance of the object in a static fashion * * @return object */ public static function make() { $obj = new ReflectionClass(__CLASS__); $args = func_get_args(); return $obj->newInstanceArgs($args); } /** * Adds a table row into the child list * * @param BSPrinterElementTable Table element * * @return fluent interface */ public function addChild(BSPrinterAbstract $tr) { if (!$tr instanceof BSPrinterElementTable) { throw new Exception('BSPrinterRootTable::addChild() only accepts BSPrinterElementTable objects as children'); } $this->children[] = $tr; return $this; } /** * Adds a table element to be a heading of the table. This is still * considered a child, but it goes before all other child elemends * * @param BSPrinterElementTable Child element * * @return fluent interface */ public function addHeadingChild(BSPrinterElementTable $tr) { $this->headers[] = $tr; return $this; } /** * Sets the width of the table * * @param string Width value * * @return fluent interface */ public function setWidth($width) { $this->width = $width; return $this; } /** * Calculates the number of columns to display based on the colspan * of children elements */ private function _calculateColumnCount() { foreach ($this->children as $child) { if ($child->numberOfColumns() > $this->colspan) { $this->colspan = $child->numberOfColumns(); } } } /** * Returns the HTML for all printed children elements * * @return string Printed HTML */ protected function _paintChildren() { $builder = ''; $this->children = array_merge($this->headers, $this->children); $this->headers = array(); $this->_calculateColumnCount(); foreach ($this->children as $child) { $child->setColumnNumber($this->colspan); $builder .= "\n" . $child->paint(); } return $builder; } /** * Paints the * * @return string Table HTML code */ public function paint() { return "
\n
width . "\"" . $this->_prepareStyle() . ">" . $this->_paintChildren() . "\n
"; } } ?>