Index: branches/5.3.x/core/units/custom_data/custom_data_event_handler.php =================================================================== diff -u -N -r15483 -r15698 --- branches/5.3.x/core/units/custom_data/custom_data_event_handler.php (.../custom_data_event_handler.php) (revision 15483) +++ branches/5.3.x/core/units/custom_data/custom_data_event_handler.php (.../custom_data_event_handler.php) (revision 15698) @@ -1,6 +1,6 @@ Application->getUnitOption('cdata', 'Clones'); + // 1. clone custom data table + $this->Application->getUnitConfig('cdata')->addClones(Array ( + $event->MasterEvent->Prefix . '-cdata' => Array ( + 'ParentPrefix' => $event->MasterEvent->Prefix, + 'TableName' => $this->_getDataTable($event->MasterEvent), + ) + )); - $data_table = $this->Application->getUnitOption($event->MasterEvent->Prefix, 'CustomDataTableName'); - - if ( !$data_table ) { - $data_table = $this->Application->getUnitOption($event->MasterEvent->Prefix, 'TableName') . 'CustomData'; - } - - $clones[$event->MasterEvent->Prefix.'-cdata'] = Array ( - 'ParentPrefix' => $event->MasterEvent->Prefix, - 'TableName' => $data_table, - ); - $this->Application->setUnitOption('cdata', 'Clones', $clones); - // 2. add custom field information to main item $this->createCustomFields($event->MasterEvent->Prefix); } /** + * Returns custom data table name for given event + * + * @param kEvent $event + * @return string + * @access protected + */ + protected function _getDataTable(kEvent $event) + { + $config = $event->getUnitConfig(); + $ret = $config->getCustomDataTableName(); + + return $ret ? $ret : $config->getTableName() . 'CustomData'; + } + + /** * Returns list of custom fields for a given $prefix * * @param $prefix @@ -55,34 +63,34 @@ { static $custom_fields = Array (); - if (defined('IS_INSTALL') && IS_INSTALL && !$this->Application->TableFound('CustomFields', true)) { + if ( defined('IS_INSTALL') && IS_INSTALL && !$this->Application->TableFound('CustomFields', true) ) { return false; } - if (!$prefix) { + if ( !$prefix ) { // prefix not specified return false; } - $item_type = $this->Application->getUnitOption($prefix, 'ItemType'); - if (!$item_type) { + $item_type = $this->Application->getUnitConfig($prefix)->getItemType(); + if ( !$item_type ) { // no main config of such type return false; } $no_caching = (defined('IS_INSTALL') && IS_INSTALL) || (defined('CUSTOM_FIELD_ADDED') && CUSTOM_FIELD_ADDED); - if (!$custom_fields || $no_caching) { + if ( !$custom_fields || $no_caching ) { // query all custom fields at once -> saves 4 sqls queries - if ($no_caching) { + if ( $no_caching ) { $all_custom_fields = $this->getCustomFields(); } else { $cache_key = 'all_custom_fields[%CfSerial%][%ModSerial%]'; $all_custom_fields = $this->Application->getCache($cache_key, false); - if ($all_custom_fields === false) { + if ( $all_custom_fields === false ) { $this->Conn->nextQueryCachable = true; $all_custom_fields = $this->getCustomFields(); $this->Application->setCache($cache_key, $all_custom_fields); @@ -91,7 +99,7 @@ foreach ($all_custom_fields as $custom_field_id => $custom_field_data) { $cf_type = $custom_field_data['Type']; - if (!array_key_exists($cf_type, $custom_fields)) { + if ( !array_key_exists($cf_type, $custom_fields) ) { $custom_fields[$cf_type] = Array (); } @@ -129,29 +137,36 @@ { parent::OnAfterConfigRead($event); - $main_prefix = $this->Application->getUnitOption($event->Prefix, 'ParentPrefix'); + $config = $event->getUnitConfig(); + $main_prefix = $config->getParentPrefix(); + if ( !$main_prefix ) { - return ; + return; } $custom_fields = $this->scanCustomFields($main_prefix); + if ( !$custom_fields ) { - return ; + return; } - // 2. create fields (for customdata item) - $fields = $this->Application->getUnitOption($event->Prefix, 'Fields', Array ()); - $field_options = Array ('type' => 'string', 'formatter' => 'kMultiLanguage', 'db_type' => 'text', 'default' => ''); + // 2. create fields (for custom data item) + $field_options = Array ( + 'type' => 'string', + 'formatter' => 'kMultiLanguage', 'db_type' => 'text', + 'default' => '' + ); foreach ($custom_fields as $custom_id => $custom_params) { - if ( isset($fields['cust_' . $custom_id]) ) { + $field_name = 'cust_' . $custom_id; + + if ( $config->getFieldByName($field_name) ) { continue; } - $fields['cust_' . $custom_id] = $field_options; - $fields['cust_' . $custom_id]['force_primary'] = !$custom_params['MultiLingual']; - } - $this->Application->setUnitOption($event->Prefix, 'Fields', $fields); + $field_options['force_primary'] = !$custom_params['MultiLingual']; + $config->addFields($field_options, $field_name); + } } /** @@ -169,7 +184,7 @@ } $calculated_fields = Array (); - $virtual_fields = $this->Application->getUnitOption($prefix, 'VirtualFields', Array ()); + $config = $this->Application->getUnitConfig($prefix); $cf_helper = $this->Application->recallObject('InpCustomFieldsHelper'); /* @var $cf_helper InpCustomFieldsHelper */ @@ -219,24 +234,24 @@ break; } - if ( !isset($virtual_fields['cust_' . $custom_name]) ) { - $virtual_fields['cust_' . $custom_name] = Array (); - } - $virtual_fields['cust_' . $custom_name] = kUtil::array_merge_recursive($field_options, $virtual_fields['cust_' . $custom_name]); + $field_name = 'cust_' . $custom_name; + $old_field_options = $config->getVirtualFieldByName($field_name, Array ()); + + $config->addVirtualFields(Array ( + $field_name => kUtil::array_merge_recursive($field_options, $old_field_options) + )); + $custom_fields[$custom_id] = $custom_name; } - $config_calculated_fields = $this->Application->getUnitOption($prefix, 'CalculatedFields', Array ()); - foreach ($config_calculated_fields as $special => $special_fields) { + foreach ($config->getCalculatedFieldSpecials() as $special) { if ( $special == '-virtual' ) { continue; } - $config_calculated_fields[$special] = array_merge($config_calculated_fields[$special], $calculated_fields); + $config->addCalculatedFieldsBySpecial($special, $calculated_fields); } - $this->Application->setUnitOption($prefix, 'CalculatedFields', $config_calculated_fields); - $this->Application->setUnitOption($prefix, 'CustomFields', $custom_fields); - $this->Application->setUnitOption($prefix, 'VirtualFields', $virtual_fields); + $config->setCustomFields($custom_fields); } } \ No newline at end of file