]> src.bluestatic.org Git - isso.git/blob - PrinterRootTable.php
Update version number
[isso.git] / PrinterRootTable.php
1 <?php
2 /*=====================================================================*
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright (c)2005-2008 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 2 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 (PrinterRootTable.php)
24 *
25 * @package ISSO
26 */
27
28 require_once(ISSO . '/PrinterRootAbstract.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)2005 - 2008, Blue Static
38 * @package ISSO
39 *
40 */
41 class BSPrinterRootTable extends BSPrinterRootAbstract
42 {
43 /**
44 * Maximum number of columns
45 * @var integer
46 */
47 private $colspan = 0;
48
49 /**
50 * Heading child elements
51 * @var array
52 */
53 private $headers = array();
54
55 /**
56 * Width of the table
57 * @var string
58 */
59 private $width = '90%';
60
61 /**
62 * Constructor
63 */
64 public function __construct()
65 {
66 $this->setCssClass('tborder');
67 }
68
69 /**
70 * Makes a new instance of the object in a static fashion
71 *
72 * @return object
73 */
74 public static function make()
75 {
76 $obj = new ReflectionClass(__CLASS__);
77 $args = func_get_args();
78 return $obj->newInstanceArgs($args);
79 }
80
81 /**
82 * Adds a table row into the child list
83 *
84 * @param BSPrinterElementTable Table element
85 *
86 * @return fluent interface
87 */
88 public function addChild(BSPrinterAbstract $tr)
89 {
90 if (!$tr instanceof BSPrinterElementTable)
91 {
92 throw new Exception('BSPrinterRootTable::addChild() only accepts BSPrinterElementTable objects as children');
93 }
94 $this->children[] = $tr;
95 return $this;
96 }
97
98 /**
99 * Adds a table element to be a heading of the table. This is still
100 * considered a child, but it goes before all other child elemends
101 *
102 * @param BSPrinterElementTable Child element
103 *
104 * @return fluent interface
105 */
106 public function addHeadingChild(BSPrinterElementTable $tr)
107 {
108 $this->headers[] = $tr;
109 return $this;
110 }
111
112 /**
113 * Sets the width of the table
114 *
115 * @param string Width value
116 *
117 * @return fluent interface
118 */
119 public function setWidth($width)
120 {
121 $this->width = $width;
122 return $this;
123 }
124
125 /**
126 * Calculates the number of columns to display based on the colspan
127 * of children elements
128 */
129 private function _calculateColumnCount()
130 {
131 foreach ($this->children as $child)
132 {
133 if ($child->numberOfColumns() > $this->colspan)
134 {
135 $this->colspan = $child->numberOfColumns();
136 }
137 }
138 }
139
140 /**
141 * Returns the HTML for all printed children elements
142 *
143 * @return string Printed HTML
144 */
145 protected function _paintChildren()
146 {
147 $builder = '';
148
149 $this->children = array_merge($this->headers, $this->children);
150 $this->headers = array();
151
152 $this->_calculateColumnCount();
153
154 foreach ($this->children as $child)
155 {
156 $child->setColumnNumber($this->colspan);
157 $builder .= "\n" . $child->paint();
158 }
159
160 return $builder;
161 }
162
163 /**
164 * Paints the <table>
165 *
166 * @return string Table HTML code
167 */
168 public function paint()
169 {
170 return "<br />\n<table cellpadding=\"4\" cellspacing=\"1\" border=\"0\" align=\"center\" width=\"" . $this->width . "\"" . $this->_prepareStyle() . ">" . $this->_paintChildren() . "\n</table>";
171 }
172 }
173
174 ?>