Xataface  2.0alpha2
Xataface Application Framework
 All Data Structures Namespaces Files Functions Variables Groups Pages
advmultiselect.php
Go to the documentation of this file.
1 <?php
2 $GLOBALS['HTML_QUICKFORM_ELEMENT_TYPES']['advmultiselect'] = array('HTML/QuickForm/advmultiselect.php', 'HTML_QuickForm_advmultiselect');
3 
8  function &buildWidget(&$record, &$field, &$form, $formFieldName, $new=false){
9  $table =& $record->_table;
10 
11  $widget =& $field['widget'];
12  if ( !@$widget['repeat'] ) $widget['repeat'] = 1;
13  $factory =& Dataface_FormTool::factory();
14  $attributes = array('class'=>$widget['class'], 'id'=>$field['name']);
15  if ( $field['repeat'] ){
16  $attributes['multiple'] = true;
17  $attributes['size'] = 5;
18  }
19  $options =& Dataface_FormTool::getVocabulary($record, $field);
20 
21  if ( !isset( $options) ) $options = array();
22 
23  if ( $record and $record->val($field['name']) ){
24  $vals = $record->val($field['name']);
25  if ( is_array($vals) ){
26  foreach ( $vals as $thisval){
27  if ( !isset($options[$thisval]) ){
28  $options[$thisval] = $thisval;
29  }
30  }
31  }
32 
33  }
34  $el =& $factory->addElement('advmultiselect', $formFieldName, $widget['label'], $options, $attributes );
35  //$el->setFieldDef($field);
36  //return $el;
37 
38  $el->setButtonAttributes('moveup' , 'class=inputCommand');
39  $el->setButtonAttributes('movedown', 'class=inputCommand');
40  return $el;
41  }
42 
43  function pushValue(&$record, &$field, &$form, &$element, &$metaValues){
44  // quickform stores select fields as arrays, and the table schema will only accept
45  // array values if the 'repeat' flag is set.
46  $table =& $record->_table;
47  $formTool =& Dataface_FormTool::getInstance();
48  $formFieldName =& $element->getName();
49 
50  if ( !$field['repeat'] ){
51  $val = $element->getValue();
52  if ( count($val)>0 ){
53  return $val[0];
54 
55  } else {
56  return null;
57 
58  }
59  } else {
60  return $element->getValue();
61  }
62 
63 
64 
65  }
66 
67 
68 }