Changeset View
Changeset View
Standalone View
Standalone View
branches/5.2.x/core/units/helpers/navigation_bar.php
Show First 20 Lines • Show All 265 Lines • ▼ Show 20 Line(s) | |||||
} | } | ||||
return $category_path; | return $category_path; | ||||
} | } | ||||
/** | /** | ||||
* Returns given category's parent path as array of id=>name elements | * Returns given category's parent path as array of id=>name elements | ||||
* | * | ||||
* @return Array | * @return array | ||||
* @access protected | |||||
*/ | */ | ||||
protected function getCategoryParentPath() | protected function getCategoryParentPath() | ||||
{ | { | ||||
$main_category_id = $this->_getCurrentCategoryId(); | $main_category_id = $this->_getCurrentCategoryId(); | ||||
// Don't query path for "Home" category. | |||||
if ( $main_category_id == 0 ) { | if ( $main_category_id == 0 ) { | ||||
// don't query path for "Home" category | return array(); | ||||
return Array (); | |||||
} | } | ||||
$category_title = isset($this->_params['category_title']) ? $this->_params['category_title'] : 'Name'; | $return_field = isset($this->_params['category_title']) ? $this->_params['category_title'] : 'Name'; | ||||
$cache_key = 'parent_paths_named[%CIDSerial:' . $main_category_id . '%]:' . $category_title; | $cache_key = 'parent_paths_named[%CIDSerial:' . $main_category_id . '%][%LangSerial%]:' . $return_field; | ||||
$cached_path = $this->Application->getCache($cache_key); | $cached_path = $this->Application->getCache($cache_key); | ||||
if ( $cached_path === false ) { | if ( $cached_path === false ) { | ||||
$parent_path = explode('|', substr($this->getParentPath($main_category_id), 1, -1)); | $parent_path = explode('|', substr($this->getParentPath($main_category_id), 1, -1)); | ||||
/** @var kMultiLanguage $ml_formatter */ | /** @var kMultiLanguageHelper $ml_helper */ | ||||
$ml_formatter = $this->Application->recallObject('kMultiLanguage'); | $ml_helper = $this->Application->recallObject('kMultiLanguageHelper'); | ||||
$navbar_field = $ml_formatter->LangFieldName($category_title); | $select_fields = array(); | ||||
foreach ( $ml_helper->getLanguages() as $language_id ) { | |||||
$select_fields[] = 'l' . $language_id . '_' . $return_field; | |||||
} | |||||
$id_field = $this->Application->getUnitOption('c', 'IDField'); | $id_field = $this->Application->getUnitOption('c', 'IDField'); | ||||
$table_name = $this->Application->getUnitOption('c', 'TableName'); | $table_name = $this->Application->getUnitOption('c', 'TableName'); | ||||
$this->Conn->nextQueryCachable = true; | $this->Conn->nextQueryCachable = true; | ||||
$sql = 'SELECT ' . $navbar_field . ', ' . $id_field . ' | $sql = 'SELECT ' . implode(',', $select_fields) . ', ' . $id_field . ' | ||||
FROM ' . $table_name . ' | FROM ' . $table_name . ' | ||||
WHERE ' . $id_field . ' IN (' . implode(',', $parent_path) . ')'; | WHERE ' . $id_field . ' IN (' . implode(',', $parent_path) . ')'; | ||||
$category_names = $this->Conn->GetCol($sql, $id_field); | $category_names = $this->Conn->Query($sql, $id_field); | ||||
$cached_path = Array (); | $cached_path = array(); | ||||
$skip_category = $this->Application->getBaseCategory(); | $skip_category = $this->Application->getBaseCategory(); | ||||
if ( $category_names ) { | if ( $category_names ) { | ||||
foreach ($parent_path as $category_id) { | foreach ( $parent_path as $category_id ) { | ||||
if ( $category_id == $skip_category ) { | if ( $category_id == $skip_category ) { | ||||
continue; | continue; | ||||
} | } | ||||
$cached_path[$category_id] = $category_names[$category_id]; | $cached_path[$category_id] = $category_names[$category_id]; | ||||
} | } | ||||
} | } | ||||
$this->Application->setCache($cache_key, $cached_path); | $this->Application->setCache($cache_key, $cached_path); | ||||
} | } | ||||
return $cached_path; | $ret = array(); | ||||
$current_language_id = $this->Application->GetVar('m_lang'); | |||||
$primary_language_id = $this->Application->GetDefaultLanguageId(); | |||||
foreach ( $cached_path as $category_id => $category_data ) { | |||||
if ( empty($category_data['l' . $current_language_id . '_' . $return_field]) ) { | |||||
$ret[$category_id] = $category_data['l' . $primary_language_id . '_' . $return_field]; | |||||
} | |||||
else { | |||||
$ret[$category_id] = $category_data['l' . $current_language_id . '_' . $return_field]; | |||||
} | |||||
} | |||||
return $ret; | |||||
} | } | ||||
/** | /** | ||||
* Returns parent path from a given category | * Returns parent path from a given category | ||||
* | * | ||||
* @param int $category_id | * @param int $category_id | ||||
* @return string | * @return string | ||||
* @access public | * @access public | ||||
▲ Show 20 Lines • Show All 48 Lines • Show Last 20 Lines |