123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295 |
- <?php
- class HTML_QuickForm_Renderer_ITDynamic extends HTML_QuickForm_Renderer
- {
-
-
- var $_tpl = null;
-
- var $_errors = array();
-
- var $_showRequired = false;
-
- var $_groupSeparator = null;
-
- var $_groupElementIdx = 0;
-
- var $_elementBlocks = array();
-
- var $_headerBlock = null;
-
-
- function HTML_QuickForm_Renderer_ITDynamic(&$tpl)
- {
- $this->HTML_QuickForm_Renderer();
- $this->_tpl =& $tpl;
- $this->_tpl->setCurrentBlock('qf_main_loop');
- }
- function finishForm(&$form)
- {
-
- if (!empty($this->_errors) && $this->_tpl->blockExists('qf_error_loop')) {
- foreach ($this->_errors as $error) {
- $this->_tpl->setVariable('qf_error', $error);
- $this->_tpl->parse('qf_error_loop');
- }
- }
-
- if ($this->_showRequired) {
- $this->_tpl->setVariable('qf_required_note', $form->getRequiredNote());
- }
-
- $this->_tpl->setVariable('qf_attributes', $form->getAttributes(true));
-
- $this->_tpl->setVariable('qf_javascript', $form->getValidationScript());
- }
- function renderHeader(&$header)
- {
- $blockName = $this->_matchBlock($header);
- if ('qf_header' == $blockName && isset($this->_headerBlock)) {
- $blockName = $this->_headerBlock;
- }
- $this->_tpl->setVariable('qf_header', $header->toHtml());
- $this->_tpl->parse($blockName);
- $this->_tpl->parse('qf_main_loop');
- }
- function renderElement(&$element, $required, $error)
- {
- $blockName = $this->_matchBlock($element);
-
- if ('qf_main_loop' != $this->_tpl->currentBlock) {
- if (0 != $this->_groupElementIdx && $this->_tpl->placeholderExists('qf_separator', $blockName)) {
- if (is_array($this->_groupSeparator)) {
- $this->_tpl->setVariable('qf_separator', $this->_groupSeparator[($this->_groupElementIdx - 1) % count($this->_groupSeparator)]);
- } else {
- $this->_tpl->setVariable('qf_separator', (string)$this->_groupSeparator);
- }
- }
- $this->_groupElementIdx++;
- } elseif(!empty($error)) {
-
- if ($this->_tpl->blockExists($blockName . '_error')) {
- $this->_tpl->setVariable('qf_error', $error);
- } else {
- $this->_errors[] = $error;
- }
- }
-
- if ($required) {
- $this->_showRequired = true;
- if ($this->_tpl->blockExists($blockName . '_required')) {
- $this->_tpl->touchBlock($blockName . '_required');
- }
- }
-
- $labels = $element->getLabel();
- if (is_array($labels)) {
- $mainLabel = array_shift($labels);
- } else {
- $mainLabel = $labels;
- }
-
- $this->_tpl->setVariable('qf_element', $element->toHtml());
- if ($this->_tpl->placeholderExists('qf_label', $blockName)) {
- $this->_tpl->setVariable('qf_label', $mainLabel);
- }
-
- if (is_array($labels)) {
- foreach($labels as $key => $label) {
- $key = is_int($key)? $key + 2: $key;
- if ($this->_tpl->blockExists($blockName . '_label_' . $key)) {
- $this->_tpl->setVariable('qf_label_' . $key, $label);
- }
- }
- }
- $this->_tpl->parse($blockName);
- $this->_tpl->parseCurrentBlock();
- }
- function renderHidden(&$element)
- {
- $this->_tpl->setVariable('qf_hidden', $element->toHtml());
- $this->_tpl->parse('qf_hidden_loop');
- }
- function startGroup(&$group, $required, $error)
- {
- $blockName = $this->_matchBlock($group);
- $this->_tpl->setCurrentBlock($blockName . '_loop');
- $this->_groupElementIdx = 0;
- $this->_groupSeparator = is_null($group->_separator)? ' ': $group->_separator;
-
- if ($required) {
- $this->_showRequired = true;
- if ($this->_tpl->blockExists($blockName . '_required')) {
- $this->_tpl->touchBlock($blockName . '_required');
- }
- }
-
- if (!empty($error)) {
- if ($this->_tpl->blockExists($blockName . '_error')) {
- $this->_tpl->setVariable('qf_error', $error);
- } else {
- $this->_errors[] = $error;
- }
- }
- $this->_tpl->setVariable('qf_group_label', $group->getLabel());
- }
- function finishGroup(&$group)
- {
- $this->_tpl->parse($this->_matchBlock($group));
- $this->_tpl->setCurrentBlock('qf_main_loop');
- $this->_tpl->parseCurrentBlock();
- }
-
- function _matchBlock(&$element)
- {
- $name = $element->getName();
- $type = $element->getType();
- if (isset($this->_elementBlocks[$name]) && $this->_tpl->blockExists($this->_elementBlocks[$name])) {
- if (('group' == $type) || ($this->_elementBlocks[$name] . '_loop' != $this->_tpl->currentBlock)) {
- return $this->_elementBlocks[$name];
- }
- }
- if ('group' != $type && 'qf_main_loop' != $this->_tpl->currentBlock) {
- $prefix = substr($this->_tpl->currentBlock, 0, -5);
- } else {
- $prefix = 'qf';
- }
- if ($this->_tpl->blockExists($prefix . '_' . $type)) {
- return $prefix . '_' . $type;
- } elseif ($this->_tpl->blockExists($prefix . '_' . $name)) {
- return $prefix . '_' . $name;
- } else {
- return $prefix . '_element';
- }
- }
-
- function setElementBlock($elementName, $blockName = null)
- {
- if (is_array($elementName)) {
- $this->_elementBlocks = array_merge($this->_elementBlocks, $elementName);
- } else {
- $this->_elementBlocks[$elementName] = $blockName;
- }
- }
-
- function setHeaderBlock($blockName)
- {
- $this->_headerBlock = $blockName;
- }
- }
- ?>
|