| 1 |
<?PHP |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 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 |
?> |
|---|