Index: branches/RC/core/units/custom_fields/custom_fields_event_handler.php =================================================================== diff -u -N -r8929 -r10913 --- branches/RC/core/units/custom_fields/custom_fields_event_handler.php (.../custom_fields_event_handler.php) (revision 8929) +++ branches/RC/core/units/custom_fields/custom_fields_event_handler.php (.../custom_fields_event_handler.php) (revision 10913) @@ -83,7 +83,7 @@ $ml_helper =& $this->Application->recallObject('kMultiLanguageHelper'); /* @var $ml_helper kMultiLanguageHelper */ - + // call main item config to clone cdata table $this->Application->getUnitOption($main_prefix, 'TableName'); $ml_helper->deleteField($main_prefix.'-cdata', $event->getEventParam('id')); @@ -119,7 +119,7 @@ $ml_helper =& $this->Application->recallObject('kMultiLanguageHelper'); /* @var $ml_helper kMultiLanguageHelper */ - + // call main item config to clone cdata table $this->Application->getUnitOption($main_prefix, 'TableName'); $ml_helper->createFields($main_prefix.'-cdata'); @@ -145,5 +145,89 @@ $object =& $event->getObject(); $object->SetDBField('Type', $this->Application->GetVar('cf_type')); } + + /** + * Prepares ValueList field's value as xml for editing + * + * @param kEvent $event + */ + function OnAfterItemLoad(&$event) + { + parent::OnAfterItemLoad($event); + + $object =& $event->getObject(); + /* @var $object kDBItem */ + + if (!in_array($object->GetDBField('ElementType'), $this->_getMultiElementTypes())) { + return ; + } + + $custom_field_helper =& $this->Application->recallObject('InpCustomFieldsHelper'); + /* @var $custom_field_helper InpCustomFieldsHelper */ + + $options = $custom_field_helper->GetValuesHash( $object->GetDBField('ValueList') ); + + $records = Array (); + foreach ($options as $option_key => $option_title) { + if ($option_key > 0) { + $records[] = Array ('OptionKey' => $option_key, 'OptionTitle' => $option_title); + } + } + + $minput_helper =& $this->Application->recallObject('MInputHelper'); + /* @var $minput_helper MInputHelper */ + + $xml = $minput_helper->prepareMInputXML($records, Array ('OptionKey', 'OptionTitle')); + $object->SetDBField('Options', $xml); + } + + /** + * Returns custom field element types, that will use minput control + * + * @return unknown + */ + function _getMultiElementTypes() + { + return Array ('select', 'multiselect', 'radio'); + } + + /** + * Saves minput content to ValueList field + * + * @param kEvent $event + */ + function OnBeforeItemUpdate(&$event) + { + parent::OnBeforeItemUpdate($event); + + $object =& $event->getObject(); + /* @var $object kDBItem */ + + if (!in_array($object->GetDBField('ElementType'), $this->_getMultiElementTypes())) { + return ; + } + + $minput_helper =& $this->Application->recallObject('MInputHelper'); + /* @var $minput_helper MInputHelper */ + + $ret = $object->GetDBField('ElementType') == 'multiselect' ? Array () : Array ('' => '=+'); + $records = $minput_helper->parseMInputXML($object->GetDBField('Options')); + + if ($object->GetDBField('SortValues')) { + usort($records, Array (&$this, '_sortValues')); + ksort($records); + } + + foreach ($records as $record) { + $ret[] = $record['OptionKey'] . '=+' . $record['OptionTitle']; + } + + $object->SetDBField('ValueList', implode(VALUE_LIST_SEPARATOR, $ret)); + } + + function _sortValues($record_a, $record_b) + { + return strcasecmp($record_a['OptionTitle'], $record_b['OptionTitle']); + } } ?> \ No newline at end of file