root/trunk/patForms/Parser/patTemplateRenderer.php

Revision 320, 3.4 kB (checked in by schst, 3 years ago)

Parser now uses the element's id for the placeholder. Parser_patTemplateRenderer and Parser_SimpleRenderer now use the matching renderers as delegates (fixes bug #184 and #185). This commit may break some scripts, but the parser was labelled alpha before.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 <?PHP
2 /**
3  * Renderer based on patForms_Parser and patTemplate
4  *
5  * $Id$
6  *
7  * @author        Stephan Schmidt <s.schmidt@metrix.de>
8  * @package        patForms
9  * @subpackage    Parser
10  * @license        LGPL
11  * @copyright    PHP Application Tools <http://www.php-tools.net>
12  */
13  
14 /**
15  * Renderer based on patForms_Parser and patTemplate
16  *
17  * Use this parser, if you want to use the forms together
18  * with patTemplate
19  *
20  * Possible arguements to renderForm():
21  * - template : name of the template (_not_ filename) in which the elements will be added
22  * - errorTemplate : name of the template to which the error messages will be added (will be repeated, if more than one error occured)
23  * - errorTemplateContainer : name of the template which contains the errorTemplate. If errors occured, its visibility will be set to visible
24  *
25  * @author        Stephan Schmidt <s.schmidt@metrix.de>
26  * @package        patForms
27  * @subpackage    Parser
28  * @license        LGPL
29  * @copyright    PHP Application Tools <http://www.php-tools.net>
30  * @version        1.0
31  */
32 class patForms_Parser_patTemplateRenderer extends patForms_Parser
33 {
34    /**
35     * patTemplate object
36     * @access    private
37     */
38     var $_tmpl    =    null;
39     
40    /**
41     * checks whether errors have been rendered or not
42     * @access    private
43     */
44     var $errorsRendered = array();
45     
46    /**
47     * set the reference to the patTemplate object
48     *
49     * @access    public
50     * @param    object    patTemplate object
51     */
52     function setTemplate(&$tmpl)
53     {
54         $this->_tmpl = &$tmpl;
55     }
56
57    /**
58     * gathers serialized data from all elements and replaces them in the outputFile.
59     *
60     * @access    public
61     * @param    object    &$patForms            Reference to the patForms object
62     * @param    mixed    $args                optional arguments
63     * @return    string    $html                HTML code
64     */
65     function render(&$patForms, $args = null)
66     {
67         if ($this->_tmpl == null) {
68             $this->_tmpl = &patForms_Parser::getStaticProperty('tmpl');
69         }
70
71         $renderer = &patForms::createRenderer('patTemplate');
72         $renderer = &new patForms_Renderer_patTemplate();
73         $renderer->setTemplate($this->_tmpl);
74         
75         $renderer->setPlaceholder($this->_placeholder);
76         $renderer->setFormPlaceholders($this->_placeholder_form_start, $this->_placeholder_form_end);
77         
78         // check, whether the file has been loaded
79         if (!$this->_tmpl->exists($args['template'])) {
80             $this->_tmpl->readTemplatesFromFile($this->_outputFile);
81         }
82
83         return $renderer->render($patForms, $args);
84     }
85
86    /**
87     * get the placeholder for an element
88     *
89     * @access    protected
90     * @param    string        element name
91     * @param    string        name of the placeholder template
92     * @return    string        placeholder
93     */
94     function _getPlaceholderForElement( $element, $template = 'placeholder' )
95     {
96         // adjust the case
97         switch( $this->_placeholder_case )
98         {
99             case 'upper':
100                 $element    =    strtoupper( $element );
101                 break;
102             case 'lower':
103                 $element    =    strtolower( $element );
104                 break;
105             default:
106                 break;
107         }
108         
109         return    sprintf( '{'.$this->{'_'.$template}.'}', $element );
110     }
111
112    /**
113     * get the placeholder for a form tag
114     *
115     * @access    protected
116     * @param    string        name of the form
117     * @param    string        type (start|end)
118     * @return    string        placeholder
119     */
120     function _getPlaceholderForForm( $form, $type )
121     {
122         // adjust the case
123         switch( $this->_placeholder_case )
124         {
125             case 'upper':
126                 $form    =    strtoupper( $form );
127                 break;
128             case 'lower':
129                 $form    =    strtolower( $form );
130                 break;
131             default:
132                 break;
133         }
134
135         $template    =    '_placeholder_form_'.$type;
136         return    sprintf( '{'.$this->$template.'}', $form );
137     }
138 }
139 ?>
Note: See TracBrowser for help on using the browser.