]> src.bluestatic.org Git - isso.git/blob - PrinterRootForm.php
Add a way to quick-set API fields via an array
[isso.git] / PrinterRootForm.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 (PrinterRootForm.php)
24 *
25 * @package ISSO
26 */
27
28 require_once(ISSO . '/PrinterRootAbstract.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 BSPrinterRootForm extends BSPrinterRootAbstract
42 {
43 /**
44 * The form's action
45 * @var string
46 */
47 private $action;
48
49 /**
50 * "Do" parameter
51 * @var string
52 */
53 private $do;
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 * Constructor
69 */
70 public function __construct($action, $do, $name = 'issoform')
71 {
72 $this->action = $action;
73 $this->do = $do;
74 $this->name = $name;
75 }
76
77 /**
78 * Makes a new instance of the object in a static fashion
79 *
80 * @return object
81 */
82 public static function make()
83 {
84 $obj = new ReflectionClass(__CLASS__);
85 $args = func_get_args();
86 return $obj->newInstanceArgs($args);
87 }
88
89 /**
90 * Should this form be used for upload?
91 *
92 * @param bool Upload?
93 *
94 * @return fluent interface
95 */
96 public function setUpload($upload)
97 {
98 $this->upload = $upload;
99 return $this;
100 }
101
102 /**
103 * Adds a table row into the child list
104 *
105 * @param BSPrinterAbstract Table element
106 *
107 * @return fluent interface
108 */
109 public function addChild(BSPrinterAbstract $tr)
110 {
111 $this->children[] = $tr;
112 return $this;
113 }
114
115 /**
116 * Returns the HTML for all printed children elements
117 *
118 * @return string Printed HTML
119 */
120 protected function _paintChildren()
121 {
122 $builder = '';
123
124 foreach ($this->children as $child)
125 {
126 $builder .= "\n" . $child->paint();
127 }
128
129 return $builder;
130 }
131
132 /**
133 * Paints the <table>
134 *
135 * @return string Table HTML code
136 */
137 public function paint()
138 {
139 array_push($this->children, new BSPrinterElement('hidden', 'do', $this->do));
140
141 return "\n<form name=\"" . $this->name . "\" action=\"" . $this->action . "\" method=\"post\"" . ($this->upload ? ' enctype="mime/multi-part"' : '') . ">\n" . $this->_paintChildren() . "\n</form>";
142 }
143 }
144
145 ?>