Index: trunk/core/units/general/helpers/helpers_config.php
===================================================================
diff -u -r8472 -r8718
--- trunk/core/units/general/helpers/helpers_config.php (.../helpers_config.php) (revision 8472)
+++ trunk/core/units/general/helpers/helpers_config.php (.../helpers_config.php) (revision 8718)
@@ -22,5 +22,6 @@
Array('pseudo'=>'CountHelper','class'=>'kCountHelper','file'=>'count_helper.php','build_event'=>'','require_classes'=>'kHelper'),
Array('pseudo'=>'ImageHelper','class'=>'ImageHelper','file'=>'image_helper.php','build_event'=>'','require_classes'=>'kHelper'),
+ Array('pseudo'=>'CategoryHelper','class'=>'CategoryHelper','file'=>'category_helper.php','build_event'=>'','require_classes'=>'kHelper'),
),
);
\ No newline at end of file
Index: trunk/core/units/general/cat_tag_processor.php
===================================================================
diff -u -r8679 -r8718
--- trunk/core/units/general/cat_tag_processor.php (.../cat_tag_processor.php) (revision 8679)
+++ trunk/core/units/general/cat_tag_processor.php (.../cat_tag_processor.php) (revision 8718)
@@ -44,7 +44,7 @@
* @param string $id_prefix
* @return string
*/
- function ItemLink($params, $id_prefix)
+ function ItemLink($params, $id_prefix = null)
{
$params = array_merge($params, Array('pass' => 'm,'.$this->Prefix) );
Index: trunk/core/units/categories/categories_tag_processor.php
===================================================================
diff -u -r8506 -r8718
--- trunk/core/units/categories/categories_tag_processor.php (.../categories_tag_processor.php) (revision 8506)
+++ trunk/core/units/categories/categories_tag_processor.php (.../categories_tag_processor.php) (revision 8718)
@@ -107,108 +107,12 @@
function CategoryPath($params)
{
- $module_name = getArrayValue($params, 'module') ? $params['module'] : 'In-Commerce';
- $module_category_id = $this->Application->findModule('Name', $module_name, 'RootCat');
- $module_item_id = $this->Application->GetVar($this->Application->findModule('Name', $module_name, 'Var').'_id');
+ $category_helper =& $this->Application->recallObject('CategoryHelper');
+ /* @var $category_helper CategoryHelper */
- $block_params['separator'] = $params['separator'];
-
- if (!isset($params['cat_id'])) {
- $params['cat_id'] = getArrayValue($params, 'cat_id') ? $params['cat_id'] : $this->Application->GetVar('m_cat_id');
- }
-
- if ($params['cat_id'] == 0) {
- $block_params['current'] = 1;
- $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,block_root_cat,rootcatblock,render_as');
- return $this->Application->ParseBlock($block_params);
- }
- else {
- $ml_formatter =& $this->Application->recallObject('kMultiLanguage');
- $navbar_field = $ml_formatter->LangFieldName('CachedNavBar');
-
- $id_field = $this->Application->getUnitOption($this->Prefix, 'IDField');
- $table_name = $this->Application->getUnitOption($this->Prefix, 'TableName');
- $sql = 'SELECT '.$navbar_field.', ParentPath
- FROM '.$table_name.'
- WHERE '.$id_field.' = '.$params['cat_id'];
- $category_data = $this->Conn->GetRow($sql);
- $ret = '';
- if ($category_data) {
- $category_names = explode('&|&', $category_data[$navbar_field]);
- $category_ids = explode('|', substr($category_data['ParentPath'], 1, -1));
-
- // add "Home" category at beginning of path
- array_unshift($category_names, $this->Application->ProcessParsedTag('m', 'RootCategoryName', $params));
- array_unshift($category_ids, 0);
-
- foreach ($category_ids as $category_pos => $category_id) {
- $block_params['cat_id'] = $category_id;
- $block_params['cat_name'] = $category_names[$category_pos];
- $block_params['current'] = ($params['cat_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 ($category_id == 0) {
- $block_params['name'] = $this->SelectParam($params, 'root_cat_render_as,block_root_cat,rootcatblock,render_as,block');
- }
-
- if ($block_params['is_module_root'] == 1) { // module root
- $block_params['name'] = $this->SelectParam($params, 'module_root_render_as,block_module_root,rootmoduleblock,render_as,block');
- }
-
- if ($block_params['current'] == 1) { // current cat (label)
- $block_params['name'] = $this->SelectParam($params, 'current_render_as,block_current,currentblock,render_as,block');
- }
-
- $this->Application->SetVar($this->Prefix.'_id', $category_id);
- $ret .= $this->Application->ParseBlock($block_params, 1);
- }
- }
-
- return $ret;
- }
+ return $category_helper->NavigationBar($params);
}
- function NavigationBar($params)
- {
- $titles = explode(',', $params['titles']);
- $templates = explode(',', $params['templates']);
-
- array_unshift($titles, $this->Application->ProcessParsedTag('m', 'RootCategoryName', $params));
- array_unshift($templates, '');
-
- $block_params = $this->prepareTagParams($params);
- $current_template = $this->Application->GetVar('t');
-
- $ret = '';
- foreach ($templates as $template_index => $template) {
- $block_params['current'] = ($template == $current_template);
- $block_params['title'] = $titles[$template_index];
- $block_params['template'] = $template;
-
- switch ($template) {
- case '':
- $block_params['name'] = $params['root_cat_render_as'];
- break;
-
- case $current_template:
- $block_params['name'] = $params['current_render_as'];
- break;
-
- default:
- $block_params['name'] = $params['render_as'];
- break;
- }
-
- $ret .= $this->Application->ParseBlock($block_params);
- }
-
- return $ret;
- }
-
function CurrentCategoryName($params)
{
$cat_object =& $this->Application->recallObject($this->getPrefixSpecial(), $this->Prefix.'_List');
Index: trunk/core/units/general/helpers/category_helper.php
===================================================================
diff -u
--- trunk/core/units/general/helpers/category_helper.php (revision 0)
+++ trunk/core/units/general/helpers/category_helper.php (revision 8718)
@@ -0,0 +1,221 @@
+Application->GetVar('m_cat_id');
+
+ $ret = $this->getHomeCategoryPath($params);
+ if (!getArrayValue($params, 'titles') && !getArrayValue($params, 'templates')) {
+ // no static templates given, show only category path
+ return $ret . $this->getCategoryPath($main_category_id, $params);
+ }
+
+ $navigation_parts = $this->getNavigationParts($params['titles'], $params['templates']);
+
+ $block_params = Array ('category' => 0);
+ $block_params['separator'] = $params['separator'];
+ $current_template = $this->Application->GetVar('t');
+
+ foreach ($navigation_parts as $template => $title) {
+ $block_params['template'] = $template;
+
+ if ($title == '__item__') {
+ if (getArrayValue($params, 'show_category')) {
+ $ret .= $this->getCategoryPath($main_category_id, $params);
+ }
+
+ $category_path = $this->getCategoryParentPath($main_category_id);
+ $module_info = $this->getCategoryModule($params, array_keys($category_path));
+ $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);
+ }
+
+ return $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'];
+ foreach ($category_path as $category_id => $category_name) {
+ $block_params['cat_id'] = $category_id;
+ $block_params['cat_name'] = $block_params['title'] = $category_name;
+ $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
Index: trunk/themes/default2007/platform/elements/navigation_bar.tpl
===================================================================
diff -u -r8614 -r8718
--- trunk/themes/default2007/platform/elements/navigation_bar.tpl (.../navigation_bar.tpl) (revision 8614)
+++ trunk/themes/default2007/platform/elements/navigation_bar.tpl (.../navigation_bar.tpl) (revision 8718)
@@ -1,36 +1,37 @@
+
+
img/icon_home.gif" width="9" height="9" alt=""/> ">
-
+
- ">
+ ">
-
+
- ">
+
+ ">
+
+ ">
+
-
+
-
+ ">
-
+
-
+
-
\ No newline at end of file