2 /*=====================================================================*
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright (c)2002-2007 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 (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 - 2007, Blue Static
41 class BSPrinterRootElementTable
extends BSPrinterRootElement
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');
70 // ###################################################################
72 * Adds a table row into the child list
74 * @param BSPrinterTableElement Table element
76 public function addChild(BSPrinterElement
$tr)
78 if (!$tr instanceof BSPrinterTableElement
)
80 throw new Exception('BSPrinterRootElementTable::addChild() only accepts BSPrinterTableElement objects as children');
82 $this->children
[] = $tr;
85 // ###################################################################
87 * Adds a table element to be a heading of the table. This is still
88 * considered a child, but it goes before all other child elemends
90 * @param BSPrinterTableElement Child element
92 public function addHeadingChild(BSPrinterTableElement
$tr)
94 $this->headers
[] = $tr;
97 // ###################################################################
99 * Sets the width of the table
101 * @param string Width value
103 public function setWidth($width)
105 $this->width
= $width;
108 // ###################################################################
110 * Calculates the number of columns to display based on the colspan
111 * of children elements
113 private function _calculateColumnCount()
115 foreach ($this->children
AS $child)
117 if ($child->numberOfColumns() > $this->colspan
)
119 $this->colspan
= $child->numberOfColumns();
124 // ###################################################################
126 * Returns the HTML for all printed children elements
128 * @return string Printed HTML
130 protected function _paintChildren()
134 $this->children
= array_merge($this->headers
, $this->children
);
135 $this->headers
= array();
137 $this->_calculateColumnCount();
139 foreach ($this->children
AS $child)
141 $child->setColumnNumber($this->colspan
);
142 $builder .= "\n" . $child->paint();
148 // ###################################################################
152 * @return string Table HTML code
154 public function paint()
156 return "<br />\n<table cellpadding=\"4\" cellspacing=\"1\" border=\"0\" align=\"center\" width=\"" . $this->width
. "\"" . $this->_prepareStyle() . ">" . $this->_paintChildren() . "\n</table>";