Index: trunk/core/kernel/application.php =================================================================== diff -u -r2581 -r2591 --- trunk/core/kernel/application.php (.../application.php) (revision 2581) +++ trunk/core/kernel/application.php (.../application.php) (revision 2591) @@ -243,6 +243,8 @@ { //$this->registerClass('Utilites',KERNEL_PATH.'/utility/utilities.php'); $this->registerClass('HTTPQuery',KERNEL_PATH.'/utility/http_query.php'); + $this->Factory->registerDependency('HTTPQuery', 'Params'); + $this->registerClass('Session',KERNEL_PATH.'/session/session.php'); $this->registerClass('SessionStorage',KERNEL_PATH.'/session/session.php'); $this->registerClass('LoginEventHandler',KERNEL_PATH.'/session/login_event_handler.php','login_EventHandler'); 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 Index: trunk/core/units/categories/categories_item.php =================================================================== diff -u -r2067 -r2591 --- trunk/core/units/categories/categories_item.php (.../categories_item.php) (revision 2067) +++ trunk/core/units/categories/categories_item.php (.../categories_item.php) (revision 2591) @@ -7,9 +7,36 @@ if (!$this->Validate()) return false; $this->SetDBField('ResourceId', $this->Application->NextResourceId()); - return parent::Create(); + $this->SetDBField('CreatedById', $this->Application->GetVar('u_id') ); + $this->SetDBField('CreatedOn_date', time() ); + $this->SetDBField('CreatedOn_time', time() ); + + $this->SetDBField('ParentId', $this->Application->GetVar('m_cat_id') ); + $ret = parent::Create(); + if($ret) + { + $sql = 'UPDATE %s SET ParentPath = %s WHERE CategoryId = %s'; + $parent_path = $this->buildParentPath(); + $this->Conn->Query( sprintf($sql, $this->TableName, $this->Conn->qstr($parent_path), $this->GetID() ) ); + + $this->SetDBField('ParentPath', $parent_path); + } + return $ret; + } + function buildParentPath() + { + $parent_id = $this->GetDBField('ParentId'); + + $cat_table = $this->Application->getUnitOption($this->Prefix, 'TableName'); + + $sql = 'SELECT ParentPath FROM '.$cat_table.' WHERE CategoryId = %s'; + $parent_path = $this->Conn->GetOne( sprintf($sql, $parent_id) ); + if(!$parent_path) $parent_path = '|'.$parent_id.'|'; + + return $parent_path.$this->GetID().'|'; + } } ?> \ No newline at end of file Index: trunk/kernel/units/general/cat_dbitem.php =================================================================== diff -u -r2337 -r2591 --- trunk/kernel/units/general/cat_dbitem.php (.../cat_dbitem.php) (revision 2337) +++ trunk/kernel/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 Index: trunk/kernel/units/categories/categories_item.php =================================================================== diff -u -r2067 -r2591 --- trunk/kernel/units/categories/categories_item.php (.../categories_item.php) (revision 2067) +++ trunk/kernel/units/categories/categories_item.php (.../categories_item.php) (revision 2591) @@ -7,9 +7,36 @@ if (!$this->Validate()) return false; $this->SetDBField('ResourceId', $this->Application->NextResourceId()); - return parent::Create(); + $this->SetDBField('CreatedById', $this->Application->GetVar('u_id') ); + $this->SetDBField('CreatedOn_date', time() ); + $this->SetDBField('CreatedOn_time', time() ); + + $this->SetDBField('ParentId', $this->Application->GetVar('m_cat_id') ); + $ret = parent::Create(); + if($ret) + { + $sql = 'UPDATE %s SET ParentPath = %s WHERE CategoryId = %s'; + $parent_path = $this->buildParentPath(); + $this->Conn->Query( sprintf($sql, $this->TableName, $this->Conn->qstr($parent_path), $this->GetID() ) ); + + $this->SetDBField('ParentPath', $parent_path); + } + return $ret; + } + function buildParentPath() + { + $parent_id = $this->GetDBField('ParentId'); + + $cat_table = $this->Application->getUnitOption($this->Prefix, 'TableName'); + + $sql = 'SELECT ParentPath FROM '.$cat_table.' WHERE CategoryId = %s'; + $parent_path = $this->Conn->GetOne( sprintf($sql, $parent_id) ); + if(!$parent_path) $parent_path = '|'.$parent_id.'|'; + + return $parent_path.$this->GetID().'|'; + } } ?> \ No newline at end of file