Index: branches/unlabeled/unlabeled-1.2.2/core/units/general/helpers/recursive_helper.php =================================================================== diff -u -r5625 -r5626 --- branches/unlabeled/unlabeled-1.2.2/core/units/general/helpers/recursive_helper.php (.../recursive_helper.php) (revision 5625) +++ branches/unlabeled/unlabeled-1.2.2/core/units/general/helpers/recursive_helper.php (.../recursive_helper.php) (revision 5626) @@ -90,12 +90,56 @@ $this->Application->StoreVar('PermCache_UpdateRequired', 1); } + /** + * Complete cloning or category with subcategories and subitems + * + * @param int $category_id + */ function PasteCategory($category_id) { - // mode == copy - complete recusive clone with subitems for all items in clipboard + $id_field = $this->Application->getUnitOption('c', 'IDField'); + $table_name = $this->Application->getUnitOption('c', 'TableName'); -// $temp =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler'); -// $temp->CloneItems($event->Prefix, $event->Special, $ids_arr); + $sql = 'SELECT '.$id_field.' + FROM '.$table_name.' + WHERE ParentId = '.$category_id; + + $sub_categories = $this->Conn->GetCol($sql); + if ($sub_categories) { + foreach ($sub_categories as $sub_category_id) { + $this->PasteCategory($sub_category_id); + } + } + + $ci_table = $this->Application->getUnitOption('ci', 'TableName'); + $temp_handler =& $this->Application->recallObject('c_TempHandler', 'kTempTablesHandler'); + + // 1. select all items from this category + $sql = 'SELECT ItemPrefix, ItemResourceId + FROM '.$ci_table.' + WHERE ('.$id_field.' = '.$category_id.')'; + $category_items = $this->Conn->GetCol($sql, 'ItemResourceId'); + + $paste_ids = Array(); + foreach ($category_items as $resource_id => $item_prefix) { + $paste_ids[$item_prefix][] = $resource_id; + } + + foreach ($paste_ids as $item_prefix => $resource_ids) { + if (!$item_prefix) { + // not ItemPrefix filled -> old categoryitem linking + continue; + } + + // 2. clone items from current category (for each prefix separately) + $item_ids = $this->GetItemIDs($item_prefix, $resource_ids); + $temp_handler->BuildTables($item_prefix, $item_ids); + $temp_handler->CloneItems($item_prefix, '', $item_ids); + } + + // 3. clone this category + $temp_handler->BuildTables('c', Array($category_id)); + $temp_handler->CloneItems('c', '', Array($category_id)); } }