Xataface  2.0alpha2
Xataface Application Framework
 All Data Structures Namespaces Files Functions Variables Groups Pages
ArrayDataface.php
Go to the documentation of this file.
1 <?php
2 /* vim: set expandtab tabstop=4 shiftwidth=4: */
3 // +----------------------------------------------------------------------+
4 // | PHP version 4.0 |
5 // +----------------------------------------------------------------------+
6 // | Copyright (c) 1997-2003 The PHP Group |
7 // +----------------------------------------------------------------------+
8 // | This source file is subject to version 2.0 of the PHP license, |
9 // | that is bundled with this package in the file LICENSE, and is |
10 // | available at through the world-wide-web at |
11 // | http://www.php.net/license/2_02.txt. |
12 // | If you did not receive a copy of the PHP license and are unable to |
13 // | obtain it through the world-wide-web, please send a note to |
14 // | license@php.net so we can mail you a copy immediately. |
15 // +----------------------------------------------------------------------+
16 // | Authors: Alexey Borzov <borz_off@cs.msu.su> |
17 // | Adam Daniel <adaniel1@eesus.jnj.com> |
18 // | Bertrand Mansion <bmansion@mamasam.com> |
19 // | Thomas Schulz <ths@4bconsult.de> |
20 // +----------------------------------------------------------------------+
21 //
22 // $Id: Array.php,v 1.1.1.1 2005/11/29 19:21:56 sjhannah Exp $
23 
24 require_once 'HTML/QuickForm/Renderer/Array.php';
25 
98 class HTML_QuickForm_Renderer_ArrayDataface extends HTML_QuickForm_Renderer_Array
99 {
100 
108  function HTML_QuickForm_Renderer_ArrayDataface($collectHidden = false, $staticLabels = false, $assoc = true)
109  {
110  $this->HTML_QuickForm_Renderer_Array($collectHidden, $staticLabels, $assoc);
111 
112  } // end constructor
113 
114 
115  function startForm(&$form){
116 
117  parent::startForm($form);
118  foreach ( $form->_errors as $key=>$val){
119  if ( is_int($key) ){
120  $this->_ary['errors'][] = $val;
121  }
122  }
123  if ( method_exists($form, 'getSubmitLabel') ){
124  $this->_ary['submit_label'] = $form->getSubmitLabel();
125  }
126  }
127 
137  function _elementToArray(&$element, $required, $error)
138  {
139 
140  $ret = array(
141  'name' => $element->getName(),
142  'value' => $element->getValue(),
143  'type' => $element->getType(),
144  'frozen' => $element->isFrozen(),
145  'required' => $required,
146  'error' => $error,
147  'field' => $element->getFieldDef(),
148  'properties'=> $element->getProperties()
149  );
150  //if ( !$ret['name']) {var_dump($element);}
151  // render label(s)
152  $labels = $element->getLabel();
153  if (is_array($labels) && $this->_staticLabels) {
154  foreach($labels as $key => $label) {
155  $key = is_int($key)? $key + 1: $key;
156  if (1 === $key) {
157  $ret['label'] = $label;
158  } else {
159  $ret['label_' . $key] = $label;
160  }
161  }
162  } else {
163  $ret['label'] = $labels;
164  }
165 
166  // set the style for the element
167 
168  if (isset($this->_elementStyles[$ret['name']])) {
169  $ret['style'] = $this->_elementStyles[$ret['name']];
170  }
171  if ('group' == $ret['type']) {
172  $ret['separator'] = $element->_separator;
173  $ret['elements'] = array();
174  } else {
175  $ret['html'] = $element->toHtml();
176  }
177 
178  if (!empty($error)) {
179  $this->_ary['errors'][$ret['name']] = $error;
180  }
181  return $ret;
182  }
183 
184 
185  function renderHeader(&$header)
186  {
187  $this->_ary['sections'][$this->_sectionCount] = array(
188  'header' => $header->toHtml(),
189  'name' => $header->getName(),
190  'field' => $header->getFieldDef()
191  );
192  $this->_currentSection = $this->_sectionCount++;
193  } // end func renderHeader
194 
195 
196 
197 
198 }