ISSO is no longer a product regularly released so we'll remove the issoversion tag...
[isso.git] / PrinterRootElementTable.php
1 <?php
2 /*=====================================================================*
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright ©2002-[#]year[#] Blue Static
6 || #
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.
10 || #
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
14 || # more details.
15 || #
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 \*=====================================================================*/
21
22 /**
23 * Printer Root Element: Table (PrinterRootElementTable.php)
24 *
25 * @package ISSO
26 */
27
28 require_once('ISSO/PrinterRootElement.php');
29
30 /**
31 * Printer Root Element: Table
32 *
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.
35 *
36 * @author Blue Static
37 * @copyright Copyright (c)2002 - [#]year[#], Blue Static
38 * @version $Revision$
39 * @package ISSO
40 *
41 */
42 class BSPrinterRootElementTable extends BSPrinterRootElement
43 {
44 /**
45 * Maximum number of columns
46 * @var integer
47 */
48 private $colspan = 0;
49
50 /**
51 * Heading child elements
52 * @var array
53 */
54 private $headers = array();
55
56 /**
57 * Width of the table
58 * @var string
59 */
60 private $width = '90%';
61
62 // ###################################################################
63 /**
64 * Constructor
65 */
66 public function __construct()
67 {
68 $this->setCssClass('tborder');
69 }
70
71 // ###################################################################
72 /**
73 * Adds a table row into the child list
74 *
75 * @param BSPrinterTableElement Table element
76 */
77 public function addChild(BSPrinterElement $tr)
78 {
79 if (!$tr instanceof BSPrinterTableElement)
80 {
81 trigger_error('BSPrinterRootElementTable::addChild() only accepts BSPrinterTableElement objects as children');
82 }
83 $this->children[] = $tr;
84 }
85
86 // ###################################################################
87 /**
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
90 *
91 * @param BSPrinterTableElement Child element
92 */
93 public function addHeadingChild(BSPrinterTableElement $tr)
94 {
95 $this->headers[] = $tr;
96 }
97
98 // ###################################################################
99 /**
100 * Sets the width of the table
101 *
102 * @param string Width value
103 */
104 public function setWidth($width)
105 {
106 $this->width = $width;
107 }
108
109 // ###################################################################
110 /**
111 * Calculates the number of columns to display based on the colspan
112 * of children elements
113 */
114 private function _calculateColumnCount()
115 {
116 foreach ($this->children AS $child)
117 {
118 if ($child->numberOfColumns() > $this->colspan)
119 {
120 $this->colspan = $child->numberOfColumns();
121 }
122 }
123 }
124
125 // ###################################################################
126 /**
127 * Returns the HTML for all printed children elements
128 *
129 * @return string Printed HTML
130 */
131 protected function _paintChildren()
132 {
133 $builder = '';
134
135 $this->children = array_merge($this->headers, $this->children);
136 $this->headers = array();
137
138 $this->_calculateColumnCount();
139
140 foreach ($this->children AS $child)
141 {
142 $child->setColumnNumber($this->colspan);
143 $builder .= "\n" . $child->paint();
144 }
145
146 return $builder;
147 }
148
149 // ###################################################################
150 /**
151 * Paints the <table>
152 *
153 * @return string Table HTML code
154 */
155 public function paint()
156 {
157 return "<br />\n<table cellpadding=\"4\" cellspacing=\"1\" border=\"0\" align=\"center\" width=\"" . $this->width . "\"" . $this->_prepareStyle() . ">" . $this->_paintChildren() . "\n</table>";
158 }
159 }
160
161 /*=====================================================================*
162 || ###################################################################
163 || # $HeadURL$
164 || # $Id$
165 || ###################################################################
166 \*=====================================================================*/
167 ?>