Subversion Repositories Applications.papyrus

Rev

Rev 320 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 320 Rev 443
Line 14... Line 14...
14
// | license@php.net so we can mail you a copy immediately.               |
14
// | license@php.net so we can mail you a copy immediately.               |
15
// +----------------------------------------------------------------------+
15
// +----------------------------------------------------------------------+
16
// | Author: Ron McClain <ron@humaniq.com>                                |
16
// | Author: Ron McClain <ron@humaniq.com>                                |
17
// +----------------------------------------------------------------------+
17
// +----------------------------------------------------------------------+
18
//
18
//
19
// $Id: Object.php,v 1.1 2005-03-30 08:50:33 jpm Exp $
19
// $Id: Object.php,v 1.2 2005-09-20 17:01:22 ddelon Exp $
Line 20... Line 20...
20
 
20
 
Line 21... Line 21...
21
require_once('HTML/QuickForm/Renderer.php');
21
require_once('HTML/QuickForm/Renderer.php');
22
 
22
 
23
/**
23
/**
24
 * A concrete renderer for HTML_QuickForm, makes an object from form contents
24
 * A concrete renderer for HTML_QuickForm, makes an object from form contents
25
 *
25
 *
26
 * Based on HTML_Quickform_Renderer_Array code
26
 * Based on HTML_Quickform_Renderer_Array code
27
 *
27
 *
28
 * @public
28
 * @access public
-
 
29
 */
29
 */
30
class HTML_QuickForm_Renderer_Object extends HTML_QuickForm_Renderer
30
class HTML_QuickForm_Renderer_Object extends HTML_QuickForm_Renderer {
31
{
31
    /**
32
    /**
32
     * The object being generated
33
     * The object being generated
33
     * @var object $_obj
34
     * @var object $_obj
Line 73... Line 74...
73
 
74
 
74
    /**
75
    /**
75
     * Constructor
76
     * Constructor
76
     *
77
     *
77
     * @param collecthidden bool    true: collect all hidden elements
78
     * @param collecthidden bool    true: collect all hidden elements
78
     * @public
79
     * @access public
79
     */
80
     */
80
    function HTML_QuickForm_Renderer_Object($collecthidden = false) 
81
    function HTML_QuickForm_Renderer_Object($collecthidden = false) 
81
    {
82
    {
82
        $this->HTML_QuickForm_Renderer();
83
        $this->HTML_QuickForm_Renderer();
83
        $this->_collectHidden = $collecthidden;
84
        $this->_collectHidden = $collecthidden;
84
        $this->_obj = new QuickformForm;
85
        $this->_obj = new QuickformForm;
Line 85... Line 86...
85
    }
86
    }
86
 
87
 
87
    /**
88
    /**
88
     * Return the rendered Object
89
     * Return the rendered Object
89
     * @public
90
     * @access public
90
     */
91
     */
91
    function toObject() 
92
    function toObject() 
92
    {
93
    {
Line 93... Line 94...
93
        return $this->_obj;
94
        return $this->_obj;
94
    }
95
    }
95
 
96
 
96
    /**
97
    /**
97
     * Set the class of the form elements.  Defaults to StdClass.
98
     * Set the class of the form elements.  Defaults to QuickformElement.
98
     * @param type string   Name of element class
99
     * @param type string   Name of element class
-
 
100
     * @access public
99
     * @public
101
     */
100
     */
102
    function setElementType($type)
Line 101... Line 103...
101
    function setElementType($type) {
103
    {
102
        $this->_elementType = $type;
104
        $this->_elementType = $type;
Line 123... Line 125...
123
        $hobj = new StdClass;
125
        $hobj = new StdClass;
124
        $hobj->header = $header->toHtml();
126
        $hobj->header = $header->toHtml();
125
        $this->_obj->sections[$this->_sectionCount] = $hobj;
127
        $this->_obj->sections[$this->_sectionCount] = $hobj;
126
        $this->_currentSection = $this->_sectionCount++;
128
        $this->_currentSection = $this->_sectionCount++;
127
    }
129
    }
-
 
130
 
128
    function renderElement(&$element, $required, $error) 
131
    function renderElement(&$element, $required, $error) 
129
    {
132
    {
130
        $elObj = $this->_elementToObject($element, $required, $error);
133
        $elObj = $this->_elementToObject($element, $required, $error);
131
        if(!empty($error)) {
134
        if(!empty($error)) {
132
            $name = $elObj->name;
135
            $name = $elObj->name;
133
            $this->_obj->errors->$name = $error;
136
            $this->_obj->errors->$name = $error;
134
        }
137
        }
135
        $this->_storeObject($elObj);
138
        $this->_storeObject($elObj);
136
    } // end func renderElement
139
    } // end func renderElement
Line 137... Line 140...
137
 
140
 
-
 
141
    function renderHidden(&$element)
138
    function renderHidden(&$element) {
142
    {
139
        if($this->_collectHidden) {
143
        if($this->_collectHidden) {
140
            $this->_obj->hidden .= $element->toHtml() . "\n";
144
            $this->_obj->hidden .= $element->toHtml() . "\n";
141
        } else {
145
        } else {
142
            $this->renderElement($element, false, null);
146
            $this->renderElement($element, false, null);
Line 146... Line 150...
146
    function startGroup(&$group, $required, $error) 
150
    function startGroup(&$group, $required, $error) 
147
    {
151
    {
148
        $this->_currentGroup = $this->_elementToObject($group, $required, $error);
152
        $this->_currentGroup = $this->_elementToObject($group, $required, $error);
149
        if(!empty($error)) {
153
        if(!empty($error)) {
150
            $name = $this->_currentGroup->name;
154
            $name = $this->_currentGroup->name;
151
            $this->_view->errors->$name = $error;
155
            $this->_obj->errors->$name = $error;
152
        }
156
        }
153
    } // end func startGroup
157
    } // end func startGroup
Line 154... Line 158...
154
 
158
 
155
    function finishGroup(&$group) 
159
    function finishGroup(&$group) 
Line 159... Line 163...
159
    } // end func finishGroup
163
    } // end func finishGroup
Line 160... Line 164...
160
 
164
 
161
    /**
165
    /**
162
     * Creates an object representing an element
166
     * Creates an object representing an element
163
     *
167
     *
164
     * @private
168
     * @access private
165
     * @param element object    An HTML_QuickForm_element object
169
     * @param element object    An HTML_QuickForm_element object
166
     * @param required bool         Whether an element is required
170
     * @param required bool         Whether an element is required
167
     * @param error string    Error associated with the element
171
     * @param error string    Error associated with the element
168
     * @return object
172
     * @return object
Line 203... Line 207...
203
    }
207
    }
Line 204... Line 208...
204
 
208
 
205
    /** 
209
    /** 
206
     * Stores an object representation of an element in the form array
210
     * Stores an object representation of an element in the form array
207
     *
211
     *
208
     * @private
212
     * @access private
209
     * @param elObj object     Object representation of an element
213
     * @param elObj object     Object representation of an element
210
     * @return void
214
     * @return void
211
     */
215
     */
212
    function _storeObject($elObj) 
216
    function _storeObject($elObj) 
Line 233... Line 237...
233
} // end class HTML_QuickForm_Renderer_Object
237
} // end class HTML_QuickForm_Renderer_Object
Line 234... Line 238...
234
 
238
 
235
 
-
 
236
 
239
 
237
/**
240
 
238
 * @abstract Long Description
241
/**
239
 * This class represents the object passed to outputObject()
242
 * Convenience class for the form object passed to outputObject()
240
 * 
243
 * 
241
 * Eg.  
244
 * Eg.  
242
 * {form.outputJavaScript():h}
245
 * {form.outputJavaScript():h}
243
 * {form.outputHeader():h}
246
 * {form.outputHeader():h}
244
 *   <table>
247
 *   <table>
245
 *     <tr>
248
 *     <tr>
246
 *       <td>{form.name.label:h}</td><td>{form.name.html:h}</td>
249
 *       <td>{form.name.label:h}</td><td>{form.name.html:h}</td>
247
 *     </tr>
-
 
248
 *   </table>
-
 
249
 * </form>
250
 *     </tr>
250
 * 
251
 *   </table>
-
 
252
 * </form>
251
 * @public
253
 */
252
 */
254
class QuickformForm
253
class QuickformForm {
255
{
254
    /**
256
   /**
255
     * Whether the form has been frozen
257
    * Whether the form has been frozen
256
     * @var boolean $frozen
258
    * @var boolean $frozen
257
     */
259
    */
258
    var $frozen;        
260
    var $frozen;
259
    
261
 
260
    /**
262
   /**
261
     * Javascript for client-side validation
263
    * Javascript for client-side validation
-
 
264
    * @var string $javascript
-
 
265
    */
-
 
266
    var $javascript;
-
 
267
 
-
 
268
   /**
-
 
269
    * Attributes for form tag
-
 
270
    * @var string $attributes
-
 
271
    */
-
 
272
    var $attributes;
-
 
273
 
-
 
274
   /**
-
 
275
    * Note about required elements
-
 
276
    * @var string $requirednote
-
 
277
    */
-
 
278
    var $requirednote;
-
 
279
 
-
 
280
   /**
-
 
281
    * Collected html of all hidden variables
-
 
282
    * @var string $hidden
-
 
283
    */
-
 
284
    var $hidden;
-
 
285
 
-
 
286
   /**
-
 
287
    * Set if there were validation errors.  
-
 
288
    * StdClass object with element names for keys and their
-
 
289
    * error messages as values
Line 262... Line 290...
262
     * @var string $javascript
290
    * @var object $errors
263
     */
-
 
264
     var $javascript;
-
 
265
 
-
 
266
     /**
-
 
267
      * Attributes for form tag
-
 
268
      * @var string $attributes
-
 
269
      */
-
 
270
     var $attributes;
-
 
271
 
-
 
272
     /**
-
 
273
      * Note about required elements
-
 
274
      * @var string $requirednote
-
 
275
      */
-
 
276
     var $requirednote;
-
 
277
 
-
 
278
     /**
-
 
279
      * Collected html of all hidden variables
-
 
280
      * @var string $hidden
-
 
281
      */
-
 
282
     var $hidden;
-
 
283
 
-
 
284
     /**
-
 
285
      * Set if there were validation errors.  
-
 
286
      * StdClass object with element names for keys and their
-
 
287
      * error messages as values
-
 
288
      * @var object $errors
-
 
289
      */
291
    */
290
     var $errors;
292
    var $errors;
291
 
293
 
292
     /**
294
   /**
293
      * Array of QuickformElementObject elements.  If there are headers in the form
295
    * Array of QuickformElementObject elements.  If there are headers in the form
294
      * this will be empty and the elements will be in the 
296
    * this will be empty and the elements will be in the 
295
      * separate sections
297
    * separate sections
296
      * @var array $elements
298
    * @var array $elements
297
      */
299
    */
298
     var $elements;
300
    var $elements;
299
 
301
 
300
     /**
302
   /**
301
      * Array of sections contained in the document
303
    * Array of sections contained in the document
302
      * @var array $sections
304
    * @var array $sections
303
      */
305
    */
304
     var $sections;
306
    var $sections;
305
 
307
 
306
     /**
308
   /**
307
      * Output &lt;form&gt; header
309
    * Output &lt;form&gt; header
-
 
310
    * {form.outputHeader():h} 
308
      * {form.outputHeader():h} 
311
    * @return string    &lt;form attributes&gt;
309
      * @return string    &lt;form attributes&gt;
-
 
310
      */
312
    */
-
 
313
    function outputHeader()
311
     function outputHeader() {
314
    {
312
        $hdr = "<form " . $this->attributes . ">\n";
315
        return "<form " . $this->attributes . ">\n";
313
        return $hdr;
316
    }
314
       }
317
 
315
     /**
318
   /**
316
      * Output form javascript
319
    * Output form javascript
-
 
320
    * {form.outputJavaScript():h}
317
      * {form.outputJavaScript():h}
321
    * @return string    Javascript
318
      * @return string    Javascript
322
    */
319
      */
323
    function outputJavaScript()
Line 320... Line 324...
320
     function outputJavaScript() {
324
    {
321
        return $this->javascript;
325
        return $this->javascript;
322
     }
326
    }
323
} // end class QuickformForm
327
} // end class QuickformForm
324
 
328
 
325
 
329
 
326
/**
330
/**
327
 * Convenience class describing a form element.
331
 * Convenience class describing a form element.
328
 * The properties defined here will be available from 
332
 * The properties defined here will be available from 
329
 * your flexy templates by referencing
333
 * your flexy templates by referencing
330
 * {form.zip.label:h}, {form.zip.html:h}, etc.
334
 * {form.zip.label:h}, {form.zip.html:h}, etc.
331
 */
335
 */
332
class QuickformElement {
336
class QuickformElement
Line 397... Line 401...
397
     */
401
     */
398
    var $elements;
402
    var $elements;
Line 399... Line 403...
399
 
403
 
400
    function isType($type)
404
    function isType($type)
401
    {
405
    {
402
        if($this->type == $type) {
-
 
403
            return true;
-
 
404
        } else {
-
 
405
            return false;
-
 
406
        }
406
        return ($this->type == $type);
407
    }
407
    }
408
    
408
 
409
    function notFrozen()
409
    function notFrozen()
410
    {
410
    {
411
        if(!$this->frozen) {
-
 
412
            return true;
-
 
413
        } else {
-
 
414
            return false;
-
 
415
        }
411
        return !$this->frozen;
Line 416... Line 412...
416
    }
412
    }
417
 
413
 
418
    function isButton()
414
    function isButton()
419
    {
-
 
420
        if($this->type == "submit" || $this->type == "reset") {
-
 
421
            return true;
-
 
422
        } else {
-
 
423
            return false;
415
    {
Line -... Line 416...
-
 
416
        return ($this->type == "submit" || $this->type == "reset");
-
 
417
    }
-
 
418
 
-
 
419
 
424
        }
420
   /**
425
    }
421
    * XXX: why does it use Flexy when all other stuff here does not depend on it?
426
 
-
 
427
    function outputStyle()
422
    */
428
    {
423
    function outputStyle()
429
        $filename = "styles/".$this->style.".html";
424
    {
430
        ob_start();
425
        ob_start();
431
        HTML_Template_Flexy::staticQuickTemplate($filename, $this);
426
        HTML_Template_Flexy::staticQuickTemplate('styles/' . $this->style . '.html', $this);
432
        $ret = ob_get_contents();
427
        $ret = ob_get_contents();
433
        ob_end_clean();
-
 
434
        return $ret;
428
        ob_end_clean();
435
    }
-
 
436
 
429
        return $ret;
-
 
430
    }