Index: branches/5.2.x/core/units/helpers/menu_helper.php =================================================================== diff -u -N -r13840 -r14092 --- branches/5.2.x/core/units/helpers/menu_helper.php (.../menu_helper.php) (revision 13840) +++ branches/5.2.x/core/units/helpers/menu_helper.php (.../menu_helper.php) (revision 14092) @@ -114,7 +114,7 @@ static $root_path = null; if (!$root_cat) { - $root_cat = $this->Application->ModuleInfo['Core']['RootCat']; + $root_cat = $this->Application->getBaseCategory(); $cache_key = 'parent_paths[%CIDSerial:' . $root_cat . '%]'; $root_path = $this->Application->getCache($cache_key); @@ -148,7 +148,8 @@ $this->Application->setCache('master:cms_menu', serialize($menu)); } else { - $this->Application->setDBCache('cms_menu', serialize($menu)); + $to_cache = serialize($menu); // setDBCache's 2nd parameter passed by reference! + $this->Application->setDBCache('cms_menu', $to_cache); } } @@ -175,7 +176,7 @@ $cat = $this_category->GetDBField('ParentId'); } elseif ($cat == 0) { - $cat = $this->Application->ModuleInfo['Core']['RootCat']; + $cat = $this->Application->getBaseCategory(); } return $cat; @@ -235,7 +236,7 @@ 'cat_id' => $page['CategoryId'], 'item_type' => $page['ItemType'], 'page_id' => $page['ItemId'], - 'use_section' => (int)$page['IsSystem'] && ($page['ItemPath'] != 'index'), + 'use_section' => ($page['Type'] == PAGE_TYPE_TEMPLATE) && ($page['ItemPath'] != 'index'), 'has_sub_menu' => isset($page['sub_items']) && count($page['sub_items']) > 0, 'external_url' => $page['UseExternalUrl'] ? $page['ExternalUrl'] : false, // for backward compatibility 'menu_icon' => $page['UseMenuIconUrl'] ? $page['MenuIconUrl'] : false, @@ -286,24 +287,9 @@ } } - $items = Array (); - // Sub-categories from current category - $sql = 'SELECT - c.CategoryId AS CategoryId, - CONCAT(\'c\', c.CategoryId) AS ItemId, - c.Priority AS ItemPriority, - ' . $lang_part . ' + $items = $this->getSubCategories( $parent['CategoryId'] ); - IF(c.IsSystem, c.Template, CONCAT("id:", c.CategoryId)) AS ItemPath, - c.ParentPath AS ParentPath, - c.ParentId As ParentId, - \'cat\' AS ItemType, - c.IsMenu, c.IsSystem, c.ThemeId, c.UseExternalUrl, c.ExternalUrl, c.UseMenuIconUrl, c.MenuIconUrl - FROM ' . TABLE_PREFIX . 'Category AS c - WHERE (c.Status = ' . STATUS_ACTIVE . ') AND (c.ParentId = ' . $parent['CategoryId'] . ')'; - $items = array_merge($items, $this->Conn->Query($sql, 'ItemId')); - // sort menu items uasort($items, Array (&$this, '_menuSort')); @@ -333,6 +319,51 @@ return $items; } + function getSubCategories($parent_id) + { + static $items_by_parent = null; + + if (!isset($items_by_parent)) { + $ml_helper =& $this->Application->recallObject('kMultiLanguageHelper'); + /* @var $ml_helper kMultiLanguageHelper */ + + $lang_part = ''; + $items_by_parent = Array (); + + for ($i = 1; $i <= $ml_helper->languageCount; $i++) { + $lang_part .= 'c.l' . $i . '_MenuTitle AS l' . $i . '_ItemName,' . "\n"; + } + + // Sub-categories from current category + $sql = 'SELECT + c.CategoryId AS CategoryId, + CONCAT(\'c\', c.CategoryId) AS ItemId, + c.Priority AS ItemPriority, + ' . $lang_part . ' + + IF(c.`Type` = ' . PAGE_TYPE_TEMPLATE . ', c.Template, CONCAT("id:", c.CategoryId)) AS ItemPath, + c.ParentPath AS ParentPath, + c.ParentId As ParentId, + \'cat\' AS ItemType, + c.IsMenu, c.Type, c.ThemeId, c.UseExternalUrl, c.ExternalUrl, c.UseMenuIconUrl, c.MenuIconUrl + FROM ' . TABLE_PREFIX . 'Category AS c + WHERE c.Status = ' . STATUS_ACTIVE; + $items = $this->Conn->Query($sql, 'ItemId'); + + foreach ($items as $item_id => $item_data) { + $item_parent_id = $item_data['ParentId']; + + if ( !array_key_exists($item_parent_id, $items_by_parent) ) { + $items_by_parent[$item_parent_id] = Array (); + } + + $items_by_parent[$item_parent_id][$item_id] = $item_data; + } + } + + return array_key_exists($parent_id, $items_by_parent) ? $items_by_parent[$parent_id] : Array (); + } + /** * Method for sorting pages by priority in decending order *