2 /*=====================================================================*
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright ©2002-[#]year[#] 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 [#]gpl[#] 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 (PrinterRootElementTable.php)
28 require_once('ISSO/PrinterRootElement.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)2002 - [#]year[#], Blue Static
42 class BSPrinterRootElementTable
extends BSPrinterRootElement
45 * Maximum number of columns
51 * Heading child elements
54 private $headers = array();
60 private $width = '90%';
62 // ###################################################################
66 public function __construct()
68 $this->setCssClass('tborder');
71 // ###################################################################
73 * Adds a table row into the child list
75 * @param BSPrinterTableElement Table element
77 public function addChild(BSPrinterElement
$tr)
79 if (!$tr instanceof BSPrinterTableElement
)
81 throw new Exception('BSPrinterRootElementTable::addChild() only accepts BSPrinterTableElement objects as children');
83 $this->children
[] = $tr;
86 // ###################################################################
88 * Adds a table element to be a heading of the table. This is still
89 * considered a child, but it goes before all other child elemends
91 * @param BSPrinterTableElement Child element
93 public function addHeadingChild(BSPrinterTableElement
$tr)
95 $this->headers
[] = $tr;
98 // ###################################################################
100 * Sets the width of the table
102 * @param string Width value
104 public function setWidth($width)
106 $this->width
= $width;
109 // ###################################################################
111 * Calculates the number of columns to display based on the colspan
112 * of children elements
114 private function _calculateColumnCount()
116 foreach ($this->children
AS $child)
118 if ($child->numberOfColumns() > $this->colspan
)
120 $this->colspan
= $child->numberOfColumns();
125 // ###################################################################
127 * Returns the HTML for all printed children elements
129 * @return string Printed HTML
131 protected function _paintChildren()
135 $this->children
= array_merge($this->headers
, $this->children
);
136 $this->headers
= array();
138 $this->_calculateColumnCount();
140 foreach ($this->children
AS $child)
142 $child->setColumnNumber($this->colspan
);
143 $builder .= "\n" . $child->paint();
149 // ###################################################################
153 * @return string Table HTML code
155 public function paint()
157 return "<br />\n<table cellpadding=\"4\" cellspacing=\"1\" border=\"0\" align=\"center\" width=\"" . $this->width
. "\"" . $this->_prepareStyle() . ">" . $this->_paintChildren() . "\n</table>";
161 /*=====================================================================*
162 || ###################################################################
165 || ###################################################################
166 \*=====================================================================*/