Start providing a fluent interface for the printer stuff. All printer elemnets now...
[isso.git] / PrinterRootElementForm.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: Form (PrinterRootElementForm.php)
24 *
25 * @package ISSO
26 */
27
28 require_once(ISSO . '/PrinterRootElement.php');
29
30 /**
31 * Printer Root Element: Form
32 *
33 * Represents a <form> 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 BSPrinterRootElementForm extends BSPrinterRootElement
42 {
43 /**
44 * The form's action (or the controller to respond to)
45 * @var string
46 */
47 private $controller;
48
49 /**
50 * Method to use
51 * @var string
52 */
53 private $action;
54
55 /**
56 * The form's name
57 * @var string
58 */
59 private $name;
60
61 /**
62 * This form is upload-ready
63 * @var bool
64 */
65 private $upload;
66
67 // ###################################################################
68 /**
69 * Constructor
70 */
71 public function __construct($controller, $action, $name = 'issoform')
72 {
73 $this->controller = $controller;
74 $this->action = $action;
75 $this->name = $name;
76 }
77
78 /**
79 * Makes a new instance of the object in a static fashion
80 *
81 * @return object
82 */
83 public static function make()
84 {
85 $obj = new ReflectionClass(__CLASS__);
86 $args = func_get_args();
87 return $obj->newInstanceArgs($args);
88 }
89
90 // ###################################################################
91 /**
92 * Should this form be used for upload?
93 *
94 * @param bool Upload?
95 */
96 public function setUpload($upload)
97 {
98 $this->upload = $upload;
99 }
100
101 // ###################################################################
102 /**
103 * Adds a table row into the child list
104 *
105 * @param BSPrinterElement Table element
106 */
107 public function addChild(BSPrinterElement $tr)
108 {
109 $this->children[] = $tr;
110 }
111
112 // ###################################################################
113 /**
114 * Returns the HTML for all printed children elements
115 *
116 * @return string Printed HTML
117 */
118 protected function _paintChildren()
119 {
120 $builder = '';
121
122 foreach ($this->children AS $child)
123 {
124 $builder .= "\n" . $child->paint();
125 }
126
127 return $builder;
128 }
129
130 // ###################################################################
131 /**
132 * Paints the <table>
133 *
134 * @return string Table HTML code
135 */
136 public function paint()
137 {
138 array_push($this->children, new BSPrinterBaseElement('hidden', 'action', $this->action));
139
140 return "\n<form name=\"" . $this->name . "\" action=\"" . $this->controller . "\" method=\"post\"" . ($this->upload ? ' enctype="mime/multi-part"' : '') . ">\n" . $this->_paintChildren() . "\n</form>";
141 }
142 }
143
144 ?>