2 /*=====================================================================*
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright (c)2005-2008 Blue Static
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version 2 of the License.
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
23 * Printer Root Element: Table (PrinterRootTable.php)
28 require_once(ISSO
. '/PrinterRootAbstract.php');
31 * Printer Root Element: Table
33 * Represents a <table> object. This can have a parent or not: if it does,
34 * then it will be painted as a child, otherwise it will act as a root.
37 * @copyright Copyright (c)2005 - 2008, Blue Static
41 class BSPrinterRootTable
extends BSPrinterRootAbstract
44 * Maximum number of columns
50 * Heading child elements
53 private $headers = array();
59 private $width = '90%';
61 // ###################################################################
65 public function __construct()
67 $this->setCssClass('tborder');
71 * Makes a new instance of the object in a static fashion
75 public static function make()
77 $obj = new ReflectionClass(__CLASS__
);
78 $args = func_get_args();
79 return $obj->newInstanceArgs($args);
82 // ###################################################################
84 * Adds a table row into the child list
86 * @param BSPrinterElementTable Table element
88 * @return fluent interface
90 public function addChild(BSPrinterAbstract
$tr)
92 if (!$tr instanceof BSPrinterElementTable
)
94 throw new Exception('BSPrinterRootTable::addChild() only accepts BSPrinterElementTable objects as children');
96 $this->children
[] = $tr;
100 // ###################################################################
102 * Adds a table element to be a heading of the table. This is still
103 * considered a child, but it goes before all other child elemends
105 * @param BSPrinterElementTable Child element
107 * @return fluent interface
109 public function addHeadingChild(BSPrinterElementTable
$tr)
111 $this->headers
[] = $tr;
115 // ###################################################################
117 * Sets the width of the table
119 * @param string Width value
121 * @return fluent interface
123 public function setWidth($width)
125 $this->width
= $width;
129 // ###################################################################
131 * Calculates the number of columns to display based on the colspan
132 * of children elements
134 private function _calculateColumnCount()
136 foreach ($this->children
as $child)
138 if ($child->numberOfColumns() > $this->colspan
)
140 $this->colspan
= $child->numberOfColumns();
145 // ###################################################################
147 * Returns the HTML for all printed children elements
149 * @return string Printed HTML
151 protected function _paintChildren()
155 $this->children
= array_merge($this->headers
, $this->children
);
156 $this->headers
= array();
158 $this->_calculateColumnCount();
160 foreach ($this->children
as $child)
162 $child->setColumnNumber($this->colspan
);
163 $builder .= "\n" . $child->paint();
169 // ###################################################################
173 * @return string Table HTML code
175 public function paint()
177 return "<br />\n<table cellpadding=\"4\" cellspacing=\"1\" border=\"0\" align=\"center\" width=\"" . $this->width
. "\"" . $this->_prepareStyle() . ">" . $this->_paintChildren() . "\n</table>";