Index: branches/5.2.x/core/units/helpers/category_helper.php =================================================================== diff -u -N -r13840 -r14092 --- branches/5.2.x/core/units/helpers/category_helper.php (.../category_helper.php) (revision 13840) +++ branches/5.2.x/core/units/helpers/category_helper.php (.../category_helper.php) (revision 14092) @@ -1,6 +1,6 @@ Application->findModule('Name', 'Core', 'RootCat'); // 0; + $block_params['cat_id'] = $this->Application->getBaseCategory(); $block_params['no_editing'] = 1; $block_params['current'] = $current_category == $block_params['cat_id'] ? 1 : 0; $block_params['separator'] = $params['separator']; @@ -305,7 +305,7 @@ $category_data = $this->Conn->GetRow($sql); $cached_path = Array (); - $skip_category = $this->Application->findModule('Name', 'Core', 'RootCat'); + $skip_category = $this->Application->getBaseCategory(); if ($category_data) { $category_names = explode('&|&', $category_data[$navbar_field]); @@ -387,31 +387,43 @@ */ function _getChildren($parent_category_id, $language_count) { - $id_field = $this->Application->getUnitOption('c', 'IDField'); + static $items_by_parent = null, $parent_mapping = null; - // get category children + parent category - $sql = 'SELECT * - FROM '.$this->Application->getUnitOption('c', 'TableName').' - WHERE ParentId = '.$parent_category_id.' OR '.$id_field.' = '.$parent_category_id.' - ORDER BY Priority DESC'; - $categories = $this->Conn->Query($sql, $id_field); + if ( !isset($items_by_parent) ) { + $fields = $items_by_parent = Array (); - $parent_data = $categories[$parent_category_id]; - unset($categories[$parent_category_id]); + for ($i = 1; $i <= $language_count; $i++) { + $fields[] = 'l' . $i . '_Name'; + } - // no children for this category - $data = Array ('id' => $parent_data[$id_field], 'children' => false, 'ThemeId' => $parent_data['ThemeId']); - for ($i = 1; $i <= $language_count; $i++) { - $data['l'.$i.'_Name'] = $parent_data['l'.$i.'_Name']; - } + $sql = 'SELECT CategoryId AS id, ' . implode(', ', $fields) . ', ParentId, ThemeId + FROM ' . $this->Application->getUnitOption('c', 'TableName') . ' + ORDER BY Priority DESC'; + $items = $this->Conn->Query($sql, 'id'); - if (!$categories) { - // no children - return $data; + foreach ($items as $item_id => $item_data) { + $item_parent_id = $item_data['ParentId']; + unset($item_data['ParentId']); + + if ( !array_key_exists($item_parent_id, $items_by_parent) ) { + $items_by_parent[$item_parent_id] = Array (); + } + + $item_data['children'] = false; + $parent_mapping[$item_id] = $item_parent_id; + $items_by_parent[$item_parent_id][$item_id] = $item_data; + } } - // category has children + $data = $items_by_parent[ $parent_mapping[$parent_category_id] ][$parent_category_id]; + $categories = array_key_exists($parent_category_id, $items_by_parent) ? $items_by_parent[$parent_category_id] : Array (); + foreach ($categories as $category_id => $category_data) { + if ($category_id == $parent_category_id) { + // don't process myself - prevents recursion + continue; + } + $data['children'][$category_id] = $this->_getChildren($category_id, $language_count); } @@ -445,7 +457,7 @@ $language_count = $ml_helper->getLanguageCount(); - $root_category = $this->Application->findModule('Name', 'Core', 'RootCat'); + $root_category = $this->Application->getBaseCategory(); $data = $this->_getChildren($root_category, $language_count); if ($this->Application->isCachingType(CACHING_TYPE_MEMORY)) { @@ -472,7 +484,7 @@ } $sql = 'SELECT - IF(c.IsSystem, CONCAT(c.Template, ":", c.ThemeId), CONCAT("id:", c.CategoryId)) AS SrcTemplate, + IF(c.`Type` = ' . PAGE_TYPE_TEMPLATE . ', CONCAT(c.Template, ":", c.ThemeId), CONCAT("id:", c.CategoryId)) AS SrcTemplate, LOWER( IF( c.SymLinkCategoryId IS NOT NULL, @@ -540,7 +552,7 @@ $data = $this->_getStructureTree(); $theme_id = (int)$themes_helper->getCurrentThemeId(); - $root_category = $this->Application->findModule('Name', 'Core', 'RootCat'); + $root_category = $this->Application->getBaseCategory(); $this->_primaryLanguageId = $this->Application->GetDefaultLanguageId(); $this->_structureTree = $this->_printChildren($data, $root_category, $this->Application->GetVar('m_lang'), $theme_id);