Changeset View
Changeset View
Standalone View
Standalone View
branches/5.2.x/core/units/helpers/recursive_helper.php
Show All 32 Lines | |||||
} | } | ||||
$ci_table = $this->Application->getUnitOption('ci', 'TableName'); | $ci_table = $this->Application->getUnitOption('ci', 'TableName'); | ||||
// 1. remove category items from this category if it is supplemental (non-primary) category to them | // 1. remove category items from this category if it is supplemental (non-primary) category to them | ||||
$sql = 'DELETE FROM '.$ci_table.' | $sql = 'DELETE FROM '.$ci_table.' | ||||
WHERE ('.$id_field.' = '.$category_id.') AND (PrimaryCat = 0)'; | WHERE ('.$id_field.' = '.$category_id.') AND (PrimaryCat = 0)'; | ||||
$this->Conn->Query($sql); | $this->Conn->Query($sql); | ||||
/** @var kTempTablesHandler $temp_handler */ | |||||
$temp_handler = $this->Application->recallObject($prefix.'_TempHandler', 'kTempTablesHandler'); | $temp_handler = $this->Application->recallObject($prefix.'_TempHandler', 'kTempTablesHandler'); | ||||
/* @var $temp_handler kTempTablesHandler */ | |||||
// 2. delete items this have this category as primary | // 2. delete items this have this category as primary | ||||
$delete_ids = $this->getCategoryItems($category_id, true); | $delete_ids = $this->getCategoryItems($category_id, true); | ||||
foreach ($delete_ids as $item_prefix => $resource_ids) { | foreach ($delete_ids as $item_prefix => $resource_ids) { | ||||
if (!$item_prefix) { | if (!$item_prefix) { | ||||
// not ItemPrefix filled -> old categoryitem linking | // not ItemPrefix filled -> old categoryitem linking | ||||
continue; | continue; | ||||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Line(s) | |||||
$dst_parent_path = $this->_getParentPath($backup_category_id); | $dst_parent_path = $this->_getParentPath($backup_category_id); | ||||
if ( substr($dst_parent_path, 0, strlen($src_parent_path)) == $src_parent_path ) { | if ( substr($dst_parent_path, 0, strlen($src_parent_path)) == $src_parent_path ) { | ||||
// target path contains source path -> recursion | // target path contains source path -> recursion | ||||
return; | return; | ||||
} | } | ||||
// 1. clone category | // 1. clone category | ||||
/** @var kTempTablesHandler $temp_handler */ | |||||
$temp_handler = $this->Application->recallObject($prefix . '_TempHandler', 'kTempTablesHandler'); | $temp_handler = $this->Application->recallObject($prefix . '_TempHandler', 'kTempTablesHandler'); | ||||
/* @var $temp_handler kTempTablesHandler*/ | |||||
$temp_handler->BuildTables($prefix, Array ($category_id)); | $temp_handler->BuildTables($prefix, Array ($category_id)); | ||||
$new_category_id = array_pop($temp_handler->CloneItems($prefix, '', Array ($category_id))); | $new_category_id = array_pop($temp_handler->CloneItems($prefix, '', Array ($category_id))); | ||||
$this->Application->SetVar('m_cat_id', $new_category_id); | $this->Application->SetVar('m_cat_id', $new_category_id); | ||||
$id_field = $this->Application->getUnitOption($prefix, 'IDField'); | $id_field = $this->Application->getUnitOption($prefix, 'IDField'); | ||||
$table_name = $this->Application->getUnitOption($prefix, 'TableName'); | $table_name = $this->Application->getUnitOption($prefix, 'TableName'); | ||||
// 2. assign supplemental items to current category to new category | // 2. assign supplemental items to current category to new category | ||||
$paste_ids = $this->getCategoryItems($category_id, false); | $paste_ids = $this->getCategoryItems($category_id, false); | ||||
foreach ($paste_ids as $item_prefix => $resource_ids) { | foreach ($paste_ids as $item_prefix => $resource_ids) { | ||||
if ( !$item_prefix ) { | if ( !$item_prefix ) { | ||||
// not ItemPrefix filled -> old categoryitem linking | // not ItemPrefix filled -> old categoryitem linking | ||||
continue; | continue; | ||||
} | } | ||||
/** @var kCatDBItem $item_object */ | |||||
$item_object = $this->Application->recallObject($item_prefix . '.-item', null, Array ('skip_autoload' => true)); | $item_object = $this->Application->recallObject($item_prefix . '.-item', null, Array ('skip_autoload' => true)); | ||||
/* @var $item_object kCatDBItem */ | |||||
foreach ($resource_ids as $item_resource_id) { | foreach ($resource_ids as $item_resource_id) { | ||||
$item_object->Load($item_resource_id, 'ResourceId'); | $item_object->Load($item_resource_id, 'ResourceId'); | ||||
$item_object->assignToCategory($new_category_id, false); | $item_object->assignToCategory($new_category_id, false); | ||||
} | } | ||||
} | } | ||||
// 3. clone items that have current category as primary | // 3. clone items that have current category as primary | ||||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Line(s) | |||||
FROM ' . TABLE_PREFIX . 'Categories | FROM ' . TABLE_PREFIX . 'Categories | ||||
WHERE CategoryId = ' . $category_id; | WHERE CategoryId = ' . $category_id; | ||||
$cache[$category_id] = $this->Conn->GetOne($sql); | $cache[$category_id] = $this->Conn->GetOne($sql); | ||||
} | } | ||||
return $cache[$category_id]; | return $cache[$category_id]; | ||||
} | } | ||||
} | } | ||||
No newline at end of file | No newline at end of file |