Xataface 2.0
Xataface Application Framework
Dataface/FormTool/advmultiselect.php
Go to the documentation of this file.
00001 <?php
00002 $GLOBALS['HTML_QUICKFORM_ELEMENT_TYPES']['advmultiselect'] = array('HTML/QuickForm/advmultiselect.php', 'HTML_QuickForm_advmultiselect');
00003 
00007 class Dataface_FormTool_advmultiselect {
00008         function &buildWidget(&$record, &$field, &$form, $formFieldName, $new=false){
00009                 $table =& $record->_table;
00010                 
00011                 $widget =& $field['widget'];
00012                 if ( !@$widget['repeat'] ) $widget['repeat'] = 1;
00013                 $factory =& Dataface_FormTool::factory();
00014                 $attributes = array('class'=>$widget['class'], 'id'=>$field['name']);
00015                 if ( $field['repeat'] ){
00016                         $attributes['multiple'] = true;
00017                         $attributes['size'] = 5;
00018                 }
00019                 $options =& Dataface_FormTool::getVocabulary($record, $field);
00020                 
00021                 if ( !isset( $options) ) $options = array();
00022                 
00023                 if ( $record and $record->val($field['name']) ){
00024                         $vals = $record->val($field['name']);
00025                         if ( is_array($vals) ){
00026                                 foreach ( $vals as $thisval){
00027                                         if ( !isset($options[$thisval]) ){
00028                                                 $options[$thisval] = $thisval;
00029                                         }
00030                                 }
00031                         }
00032                 
00033                 }
00034                 $el =&  $factory->addElement('advmultiselect', $formFieldName, $widget['label'], $options, $attributes  );
00035                 //$el->setFieldDef($field);
00036                 //return $el;
00037                 
00038                 $el->setButtonAttributes('moveup'  , 'class=inputCommand');
00039                 $el->setButtonAttributes('movedown', 'class=inputCommand');
00040                 return $el;
00041         }
00042         
00043         function pushValue(&$record, &$field, &$form, &$element, &$metaValues){
00044                 // quickform stores select fields as arrays, and the table schema will only accept 
00045                 // array values if the 'repeat' flag is set.
00046                 $table =& $record->_table;
00047                 $formTool =& Dataface_FormTool::getInstance();
00048                 $formFieldName =& $element->getName();
00049                 
00050                 if ( !$field['repeat'] ){
00051                         $val = $element->getValue();
00052                         if ( count($val)>0 ){
00053                                 return $val[0];
00054                                 
00055                         } else {
00056                                 return null;
00057                                 
00058                         }
00059                 } else {
00060                         return $element->getValue();
00061                 }
00062                         
00063                 
00064                 
00065         }
00066         
00067         
00068 }
 All Data Structures Namespaces Files Functions Variables Enumerations