Index: trunk/core/units/general/helpers/category_helper.php =================================================================== diff -u -N --- trunk/core/units/general/helpers/category_helper.php (revision 8779) +++ trunk/core/units/general/helpers/category_helper.php (revision 0) @@ -1,242 +0,0 @@ -Application->GetVar('m_cat_id'); - - $home_element = $this->getHomeCategoryPath($params); - if (!getArrayValue($params, 'titles') && !getArrayValue($params, 'templates')) { - // no static templates given, show only category path - return $home_element . $this->getCategoryPath($main_category_id, $params); - } - - $navigation_parts = $this->getNavigationParts($params['titles'], $params['templates']); - - $ret = ''; - $block_params = Array ('category' => 0); - $block_params['separator'] = $params['separator']; - $current_template = $this->Application->GetVar('t'); - $show_category = getArrayValue($params, 'show_category'); - - foreach ($navigation_parts as $template => $title) { - $block_params['template'] = $template; - - if ($title == '__item__') { - if ($show_category) { - $ret .= $this->getCategoryPath($main_category_id, $params); - $show_category = false; - } - - $category_path = $this->getCategoryParentPath($main_category_id); - $module_info = $this->getCategoryModule($params, array_keys($category_path)); - if (!$module_info) { - continue; - } - - $module_prefix = $module_info['Var']; - $object =& $this->Application->recallObject($module_prefix); - /* @var $object kCatDBItem */ - - $title_field = $this->Application->getUnitOption($module_prefix, 'TitleField'); - $block_params['title'] = $object->GetField($title_field); - $block_params['prefix'] = $module_prefix; - $block_params['current'] = 0; - - $block_params['name'] = $this->SelectParam($params, 'module_item_render_as,render_as'); - } - else { - $block_params['current'] = ($template == $current_template); - $block_params['title'] = $this->Application->Phrase($title); - - $block_params['name'] = $template == $current_template ? $params['current_render_as'] : $params['render_as']; - } - - $ret .= $this->Application->ParseBlock($block_params); - } - - if ($show_category) { - $params['no_current'] = true; - return $home_element . ($show_category ? $this->getCategoryPath($main_category_id, $params) : '') . $ret; - } - - return $home_element . $ret; - } - - /** - * Get navigation parts - * - * @param Array $titles - * @param Array $templates - * @return Array - */ - function getNavigationParts($titles, $templates) - { - $titles = explode(',', $titles); - $templates = explode(',', $templates); - - $ret = Array (); - foreach ($templates as $template_pos => $template) { - $ret[$template] = $titles[$template_pos]; - } - - return $ret; - } - - function getCategoryPath($main_category_id, $params) - { - $category_path = $this->getCategoryParentPath($main_category_id); - if (!$category_path) { - // in "Home" category - return ''; - } - - $module_info = $this->getCategoryModule($params, array_keys($category_path)); - - $module_category_id = $module_info['RootCat']; - $module_item_id = $this->Application->GetVar($module_info['Var'].'_id'); - - $ret = ''; - $block_params['category'] = 1; - $block_params['separator'] = $params['separator']; - $no_current = isset($params['no_current']) && $params['no_current']; - - foreach ($category_path as $category_id => $category_name) { - $block_params['cat_id'] = $category_id; - $block_params['cat_name'] = $block_params['title'] = $category_name; - - if ($no_current) { - $block_params['current'] = 0; - } - else { - $block_params['current'] = ($main_category_id == $category_id) && !$module_item_id ? 1 : 0; - } - - $block_params['is_module_root'] = $category_id == $module_category_id ? 1 : 0; - $block_params['name'] = $this->SelectParam($params, 'render_as,block'); - - // which block to parse as current ? - if ($block_params['is_module_root']) { - $block_params['name'] = $this->SelectParam($params, 'module_root_render_as,render_as'); - $block_params['module_index'] = $module_info['TemplatePath'].'index'; - } - - if ($block_params['current']) { - $block_params['name'] = $this->SelectParam($params, 'current_render_as,render_as'); - } - - $this->Application->SetVar('c_id', $category_id); - $ret .= $this->Application->ParseBlock($block_params, 1); - } - - return $ret; - } - - /** - * Returns module information based on given module name or current category (relative to module root categories) - * - * @param Array $params - * @param Array $category_ids category parent path (already as array) - * @return Array - */ - function getCategoryModule($params, $category_ids) - { - if (isset($params['module'])) { - // get module by name specified - $module_info = $this->Application->findModule('Name', $params['module']); - - } - elseif ($category_ids) { - // get module by category path - $module_root_categories = $this->getModuleRootCategories(); - $module_category_id = array_shift(array_intersect($category_ids, $module_root_categories)); - $module_info = $this->Application->findModule('RootCat', $module_category_id); - } - - return $module_info; - } - - function getHomeCategoryPath($params) - { - $block_params['cat_id'] = 0; - $block_params['cat_name'] = $this->Application->ProcessParsedTag('m', 'RootCategoryName', $params); - $block_params['name'] = $this->SelectParam($params, 'root_cat_render_as,render_as'); - return $this->Application->ParseBlock($block_params); - } - - function getModuleRootCategories() - { - static $root_categories = null; - - if (!isset($root_categories)) { - $root_categories = Array (); - foreach ($this->Application->ModuleInfo as $module_name => $module_info) { - array_push($root_categories, $module_info['RootCat']); - } - - $root_categories = array_unique($root_categories); - } - - return $root_categories; - } - - function getCategoryParentPath($main_category_id) - { - static $cached_path = null; - - if ($main_category_id == 0) { - // don't query path for "Home" category - return Array (); - } - - if (!isset($cached_path[$main_category_id])) { - $ml_formatter =& $this->Application->recallObject('kMultiLanguage'); - $navbar_field = $ml_formatter->LangFieldName('CachedNavBar'); - - $id_field = $this->Application->getUnitOption('c', 'IDField'); - $table_name = $this->Application->getUnitOption('c', 'TableName'); - - $sql = 'SELECT '.$navbar_field.', ParentPath - FROM '.$table_name.' - WHERE '.$id_field.' = '.$main_category_id; - $category_data = $this->Conn->GetRow($sql); - - $cached_path[$main_category_id] = Array (); - if ($category_data) { - $category_names = explode('&|&', $category_data[$navbar_field]); - $category_ids = explode('|', substr($category_data['ParentPath'], 1, -1)); - - foreach ($category_ids as $category_index => $category_id) { - $cached_path[$main_category_id][$category_id] = $category_names[$category_index]; - } - } - } - return $cached_path[$main_category_id]; - } - - /** - * Not tag, method for parameter - * selection from list in this TagProcessor - * - * @param Array $params - * @param string $possible_names - * @return string - * @access public - */ - function SelectParam($params, $possible_names) - { - if (!is_array($params)) return; - if (!is_array($possible_names)) - - $possible_names = explode(',', $possible_names); - foreach ($possible_names as $name) - { - if( isset($params[$name]) ) return $params[$name]; - } - return false; - } - } - - -?> \ No newline at end of file