Xataface  2.0alpha2
Xataface Application Framework
 All Data Structures Namespaces Files Functions Variables Groups Pages
Dataface.php
Go to the documentation of this file.
1 <?php
13 require_once 'Dataface/SkinTool.php';
14 //require_once 'Dataface/Table.php';
15 //require_once 'Dataface/TableTool.php';
16 //require_once 'Dataface/Record.php';
17 require_once 'HTML/QuickForm/Renderer/Default.php';
18 
19 define('DATAFACE_RENDERER_FIELD_NOT_FOUND',2005);
20 
21 class HTML_QuickForm_Renderer_Dataface extends HTML_QuickForm_Renderer_Default {
23  var $elementTemplate = "Dataface_QuickForm_element.html";
24  var $groupElementTemplate = "Dataface_Quickform_groupelement.html";
25 
29  var $_fieldMap = array();
30 
31 
33  $this->_skinTool =& Dataface_SkinTool::getInstance();
34  parent::HTML_QuickForm_Renderer_Default();
35  $this->setRequiredNoteTemplate('');
36  }
37 
38  function addField($elementname, $fieldname){
39  $this->_fieldMap[$elementname] = $fieldname;
40  }
41 
42  function renderElement(&$element, $required, $error)
43  {
44  $context = array( "field"=>$element->getFieldDef(), "element"=>$element->toHtml(), "required"=>$required, "error"=>$error, "frozen"=>$element->isFrozen());
45  $context['properties'] =& $element->getProperties();
46 
47 
48 
49 
50 
51 
52  if ( !$this->_inGroup ){
53  ob_start();
54  $this->_skinTool->display($context, $this->elementTemplate);
55  $html = ob_get_contents();
56  ob_end_clean();
57  $this->_html .= $html;
58  } else {
59 
60  ob_start();
61  $this->_skinTool->display($context, $this->groupElementTemplate);
62  $html = ob_get_contents();
63  ob_end_clean();
64  $this->_groupElements[] =& $html;
65  }
66  } // end func renderElement
67 
68  function startGroup(&$group, $required, $error)
69  {
70  $name = $group->getName();
71  if ( isset( $this->_groupWraps[$name] ) )
72  $this->_groupTemplate = $this->_groupWraps[$name] ; // $this->_prepareTemplate($name, $group->getLabel(), $required, $error);
73  else
74  $this->_groupTemplate = '';
75  $this->_groupElementTemplate = empty($this->_groupTemplates[$name])? '': $this->_groupTemplates[$name];
76  $this->_groupWrap = empty($this->_groupWraps[$name])? '': $this->_groupWraps[$name];
77  $this->_groupElements = array();
78  $this->_inGroup = true;
79 
80  } // end func startGroup
81 
82  function finishGroup(&$group)
83  {
84  $separator = $group->_separator;
85  if (is_array($separator)) {
86  $count = count($separator);
87  $html = '';
88  for ($i = 0; $i < count($this->_groupElements); $i++) {
89  $html .= (0 == $i? '': $separator[($i - 1) % $count]) . $this->_groupElements[$i];
90  }
91  } else {
92  if (is_null($separator)) {
93  //$separator = '&nbsp;';
94  $separator='';
95  }
96 
97  $html = implode((string)$separator, $this->_groupElements);
98  }
99  if (!empty($this->_groupWrap)) {
100  $html = str_replace('{content}', $html, $this->_groupWrap);
101  }
102  //echo "<h1>html</h1>".$html;
103  $this->_html .= $html; //str_replace('{element}', $html, $this->_groupTemplate);
104  $this->_inGroup = false;
105  } // end func finishGroup
106 
107 }
108 
109