Index: trunk/core/units/general/cat_dbitem.php =================================================================== diff -u -r2337 -r2591 --- trunk/core/units/general/cat_dbitem.php (.../cat_dbitem.php) (revision 2337) +++ trunk/core/units/general/cat_dbitem.php (.../cat_dbitem.php) (revision 2591) @@ -2,6 +2,17 @@ class kCatDBItem extends kDBItem { + var $CustomFields = Array(); + + function Init($prefix, $special, $event_params = null) + { + parent::Init($prefix, $special, $event_params); + + $item_type = $this->Application->getUnitOption($this->Prefix, 'ItemType'); + $sql = 'SELECT CustomFieldId, FieldName FROM '.TABLE_PREFIX.'CustomField WHERE Type = %s'; + $this->CustomFields = $this->Conn->GetCol( sprintf($sql, $item_type), 'FieldName' ); + } + function Create() { if (!$this->Validate()) return false; @@ -150,6 +161,23 @@ } } } + + function SetCustomField($field, $value) + { + $cf_id = getArrayValue($this->CustomFields, $field); + if(!$cf_id) return false; + + $data_table = TABLE_PREFIX.'CustomMetaData'; + + $sql = 'SELECT CustomDataId FROM '.$data_table.' WHERE CustomFieldId = %s AND ResourceId = %s'; + $data_id = (int)$this->Conn->GetOne( sprintf($sql, $cf_id, $this->GetDBField('ResourceId') ) ); + + $lang_id = $this->Application->GetVar('lang.current_id'); + + $sql = 'REPLACE INTO '.$data_table.'(CustomDataId,ResourceId,CustomFieldId,Value,l'.$lang_id.'_Value) VALUES (%1$s,%2$s,%3$s,%4$s,%4$s)'; + + $this->Conn->Query( sprintf($sql, $data_id, $this->GetDBField('ResourceId'), $cf_id, $this->Conn->qstr($value) ) ); + } } ?> \ No newline at end of file