Okay this finally looks good
[isso.git] / PrinterTableElement.php
1 <?php
2 /*=====================================================================*
3 || ###################################################################
4 || # Blue Static ISSO Framework [#]issoversion[#]
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 Table Element (PrinterTableElement.php)
24 *
25 * @package ISSO
26 */
27
28 require_once('ISSO/PrinterRootElementTable.php');
29 require_once('ISSO/PrinterBaseElement.php');
30
31 /**
32 * Printer Table Element
33 *
34 * This represents a table row that holds elements.
35 *
36 * @author Blue Static
37 * @copyright Copyright (c)2002 - [#]year[#], Blue Static
38 * @version $Revision$
39 * @package ISSO
40 *
41 */
42 class BSPrinterTableElement extends BSPrinterElement
43 {
44 /**
45 * CSS class to use
46 * @var string
47 */
48 private $cssClass = ':swap:';
49
50 /**
51 * Array of child nodes
52 * @var array
53 */
54 private $children = array();
55
56 // ###################################################################
57 /**
58 * Returns a new instance of this class
59 */
60 public static function Init()
61 {
62 return new BSPrinterTableElement();
63 }
64
65 // ###################################################################
66 /**
67 * Factory method that creates a checkbox row
68 *
69 * @param string Label
70 * @param string Element name
71 * @param mixed Value
72 * @param boolean Checked?
73 *
74 * @return BSPrinterTableElement A proper table element
75 */
76 public static function RowCheckbox($label, $name, $value, $checked = false)
77 {
78 $tr = new BSPrinterTableElement();
79
80 $tr->addChild(new BSPrinterLabelElement($label));
81
82 $elm = new BSPrinterBaseElement('checkbox', $name, $value);
83 $elm->setActive($checked);
84
85 $tr->addChild($elm);
86
87 return $tr;
88 }
89
90 // ###################################################################
91 /**
92 * Sets the CSS class to use. Use ":swap:" to alternate
93 *
94 * @param string CSS class
95 */
96 public function setCssClass($class)
97 {
98 $this->cssClass = $class;
99 }
100
101 // ###################################################################
102 /**
103 * Returns the number of columns in this element
104 *
105 * @return integer Column count
106 */
107 public function numberOfColumns()
108 {
109 return sizeof($this->children);
110 }
111
112 // ###################################################################
113 /**
114 * Adds a child node to the element
115 *
116 * @param BSPrinterElement A child element
117 *
118 * @return BSPrinterTableElement Returns the current object
119 */
120 public function addChild(BSPrinterElement $child)
121 {
122 $this->children[] = $child;
123 return $this;
124 }
125
126 // ###################################################################
127 /**
128 * Returns the HTML for all printed children elements
129 *
130 * @return string Printed HTML
131 */
132 protected function _paintChildren()
133 {
134 $builder = '';
135
136 foreach ($this->children AS $child)
137 {
138 $builder .= "\n<td>" . $child->paint() . "</td>\n";
139 }
140
141 return $builder;
142 }
143
144 // ###################################################################
145 /**
146 * Paints the entire table row
147 *
148 * @return string Table row HTML
149 */
150 public function paint()
151 {
152 return "<tr>" . $this->_paintChildren() . "</tr>";
153 }
154 }
155
156 /*=====================================================================*
157 || ###################################################################
158 || # $HeadURL$
159 || # $Id$
160 || ###################################################################
161 \*=====================================================================*/
162 ?>