Application->getUnitOption('c', 'IDField'); $table_name = $this->Application->getUnitOption('c', 'TableName'); $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->DeleteCategory($sub_category_id); } } $ci_table = $this->Application->getUnitOption('ci', 'TableName'); // 1. remove category items from this category if it is supplemental (non-primary) category to them $sql = 'DELETE FROM '.$ci_table.' WHERE ('.$id_field.' = '.$category_id.') AND (PrimaryCat = 0)'; $this->Conn->Query($sql); $temp_handler =& $this->Application->recallObject('c_TempHandler', 'kTempTablesHandler'); // 2. delete items this have this category as primary $sql = 'SELECT ItemPrefix, ItemResourceId FROM '.$ci_table.' WHERE ('.$id_field.' = '.$category_id.') AND (PrimaryCat = 1)'; $category_items = $this->Conn->GetCol($sql, 'ItemResourceId'); $delete_ids = Array(); foreach ($category_items as $resource_id => $item_prefix) { $delete_ids[$item_prefix][] = $resource_id; } foreach ($delete_ids as $item_prefix => $resource_ids) { if (!$item_prefix) { // not ItemPrefix filled -> old categoryitem linking continue; } $item_ids = $this->GetItemIDs($item_prefix, $resource_ids); $temp_handler->BuildTables($item_prefix, $item_ids); $temp_handler->DeleteItems($item_prefix, '', $item_ids); } // 3. delete this category $temp_handler->BuildTables('c', Array($category_id)); $temp_handler->DeleteItems('c', '', Array($category_id)); } /** * Converts resource ids list to id field list for given prefix * * @param string $prefix * @param Array $resource_ids * @return Array */ function GetItemIDs($prefix, $resource_ids) { if (!$resource_ids) { return Array(); } $id_field = $this->Application->getUnitOption($prefix, 'IDField'); $table_name = $this->Application->getUnitOption($prefix, 'TableName'); $sql = 'SELECT '.$id_field.' FROM '.$table_name.' WHERE ResourceId IN ('.implode(',', $resource_ids).')'; return $this->Conn->GetCol($sql); } // moves selected categories to destination category function MoveCategories($category_ids, $dest_category_id) { if (!$category_ids) return ; $id_field = $this->Application->getUnitOption('c', 'IDField'); $table_name = $this->Application->getUnitOption('c', 'TableName'); $sql = 'UPDATE '.$table_name.' SET ParentId = '.$dest_category_id.' WHERE '.$id_field.' IN ('.$category_ids.')'; $this->Conn->Query($sql); $this->Application->StoreVar('PermCache_UpdateRequired', 1); } function PasteCategory($category_id) { // mode == copy - complete recusive clone with subitems for all items in clipboard // $temp =& $this->Application->recallObject($event->getPrefixSpecial().'_TempHandler', 'kTempTablesHandler'); // $temp->CloneItems($event->Prefix, $event->Special, $ids_arr); } } ?>