Index: trunk/kernel/include/custommetadata.php =================================================================== diff -u -N -r5431 -r7635 --- trunk/kernel/include/custommetadata.php (.../custommetadata.php) (revision 5431) +++ trunk/kernel/include/custommetadata.php (.../custommetadata.php) (revision 7635) @@ -1,6 +1,6 @@ classname = 'clsCustomMetaData'; } - + function LoadResource($ResourceId) { // TO REMOVE } - + function DeleteResource($ResourceId, $main_prefix) { if (!$ResourceId) return false; - + $custom_table = $this->Application->getUnitOption($main_prefix.'-cdata', 'TableName'); $sql = 'DELETE FROM '.$custom_table.' WHERE ResourceId = '.$ResourceId; $this->adodbConnection->Execute($sql); } - + function CopyResource($OldId,$NewId, $main_prefix) { $custom_data =& $this->Application->recallObject($main_prefix.'-cdata.-item', null, Array('skip_autoload' => true)); $custom_data->Load($OldId, 'ResourceId'); - + if ($custom_data->isLoaded()) { $custom_data->SetDBField('ResourceId', $NewId); $custom_data->Create(); } } - + function &SetFieldValue($FieldId,$ResourceId,$Value) { // so strange construction used, because in normal // way it doesn't work at all (gets item copy not // pointer) $index = $this->GetDataItem($FieldId, true); - + if($index !== false) { $d =& $this->Items[$index]; @@ -70,7 +70,7 @@ { $d = null; } - + if(is_object($d)) { $d->Set('Value', $Value); @@ -83,7 +83,7 @@ $this->Items[$x]->Set("CustomFieldId",0); break; } - } + } $d->Delete(true); } } @@ -108,49 +108,58 @@ { $d =& $this->GetItemRefByIndex($i); if($d->Get("CustomFieldId")==$id) - { + { $found=TRUE; break; - } + } } return $found ? ($return_index ? $i : $d) : false; } - function SaveData($main_prefix, $resource_id) - { - // to call OnAfterConfigRead event - $item_table = $this->Application->getUnitOption($main_prefix, 'TableName'); - - $ml_formatter =& $this->Application->recallObject('kMultiLanguage'); - $custom_data =& $this->Application->recallObject($main_prefix.'-cdata', null, Array('skip_autoload' => true)); - $custom_data->Load($resource_id, 'ResourceId'); - - foreach($this->Items as $f) { - $custom_id = $f->Get('CustomFieldId'); - $value = isset($GLOBALS['_CopyFromEditTable']) ? $f->Get('Value') : stripslashes($f->Get('Value')); - - $custom_name = $ml_formatter->LangFieldName('cust_'.$custom_id); - $custom_data->SetDBField($custom_name, $value); - } - - $custom_data->SetDBField('ResourceId', $resource_id); - return $custom_data->isLoaded() ? $custom_data->Update() : $custom_data->Create(); - } + function SaveData($main_prefix, $resource_id) + { + // to call OnAfterConfigRead event + $item_table = $this->Application->getUnitOption($main_prefix, 'TableName'); + $ml_formatter =& $this->Application->recallObject('kMultiLanguage'); + $custom_data =& $this->Application->recallObject($main_prefix.'-cdata', null, Array('skip_autoload' => true)); + $custom_data->Load($resource_id, 'ResourceId'); + + foreach($this->Items as $f) { + $custom_id = $f->Get('CustomFieldId'); + $value = isset($GLOBALS['_CopyFromEditTable']) ? $f->Get('Value') : stripslashes($f->Get('Value')); + + $custom_name = $ml_formatter->LangFieldName('cust_'.$custom_id); + $custom_data->SetDBField($custom_name, $value); + } + + $custom_data->SetDBField('ResourceId', $resource_id); + return $custom_data->isLoaded() ? $custom_data->Update() : $custom_data->Create(); + } + function &getTempHandler($prefix) { if (strlen($prefix) > 2 || strlen($prefix) == 0) { // not e.g. bb, c, u, but CustomFieldId :) or empty at all $this->Application->reportError(get_class($this), 'CopyToEditTable'); } - + $temp_handler =& $this->Application->recallObject($prefix.'-cdata_TempHandler', 'kTempTablesHandler'); return $temp_handler; } - + function CopyToEditTable($main_prefix, $idlist) { $temp_handler =& $this->getTempHandler($main_prefix); + $tables = $temp_handler->Tables; + $parent_prefix = $this->Application->getUnitOption($main_prefix.'-cdata', 'ParentPrefix'); + if ($parent_prefix) { + $tables['ForeignKey'] = $this->Application->getUnitOption($main_prefix.'-cdata', 'ForeignKey'); + $tables['ParentPrefix'] = $parent_prefix; + $tables['ParentTableKey'] = $this->Application->getUnitOption($main_prefix.'-cdata', 'ParentTableKey'); + } + $temp_handler->Tables = $tables; + $temp_handler->DoCopyLiveToTemp($temp_handler->Tables, $idlist); } @@ -165,9 +174,9 @@ $temp_handler =& $this->getTempHandler($main_prefix); $temp_handler->CancelEdit(); } - + function CreateEmptyEditTable($main_prefix) - { + { $temp_handler =& $this->getTempHandler($main_prefix); $temp_handler->DoCopyLiveToTemp($temp_handler->Tables, Array(0)); }