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