Page MenuHomeIn-Portal Phabricator

categories_item.php
No OneTemporary

File Metadata

Created
Thu, Jul 3, 3:32 PM

categories_item.php

<?php
class CategoriesItem extends kDBItem
{
function Create()
{
if (!$this->Validate()) return false;
$this->SetDBField('ResourceId', $this->Application->NextResourceId());
$this->SetDBField('CreatedById', $this->Application->GetVar('u_id') );
$this->SetDBField('CreatedOn_date', adodb_mktime() );
$this->SetDBField('CreatedOn_time', adodb_mktime() );
$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().'|';
}
}
?>

Event Timeline