diff --git a/classes/helper/Helper.php b/classes/helper/Helper.php index fc5a3c866..3479948eb 100755 --- a/classes/helper/Helper.php +++ b/classes/helper/Helper.php @@ -97,10 +97,40 @@ class HelperCore return $this->tpl->fetch(); } + /** + * @deprecated since 1.5 - use Helper::renderCategoryTree() instead + * @static + * @param $translations + * @param array $selected_cat + * @param string $input_name + * @param bool $use_radio + * @param bool $use_search + * @param array $disabled_categories + * @param bool $use_in_popup + * @return mixed + */ + public static function renderAdminCategorieTree($translations, + $selected_cat = array(), + $input_name = 'categoryBox', + $use_radio = false, + $use_search = false, + $disabled_categories = array(), + $use_in_popup = false) + { + $helper = new Helper(); + if (isset($translations['Root'])) + $root = $translations['Root']; + else if (isset($translations['Home'])) + $root = array('name' => $translations['Home'], 'id_category' => 1); + else + throw new PrestaShopException('Missing root category parameter.'); + + return $helper->renderCategoryTree($root, $selected_cat, $input_name, $use_radio, $use_search, $disabled_categories, $use_in_popup); + } + /** * - * @param type $trads values of translations keys - * For the moment, translation are not automatic + * @param array $root array with the name and ID of the tree root category, if null the Shop's root category will be used * @param type $selected_cat array of selected categories * Format * Array @@ -118,18 +148,42 @@ class HelperCore * [link_rewrite] => home * ) * ) - * @param type $input_name name of input + * @param string $input_name name of input + * @param bool $use_radio use radio tree or checkbox tree + * @param bool $use_search display a find category search box + * @param array $disabled_categories + * @param bool $use_in_popup * @return string */ - public static function renderAdminCategorieTree($trads, $selected_cat = array(), $input_name = 'categoryBox', $use_radio = false, $use_search = false, $disabled_categories = array(), $use_in_popup = false) + public function renderCategoryTree($root = null, + $selected_cat = array(), + $input_name = 'categoryBox', + $use_radio = false, + $use_search = false, + $disabled_categories = array(), + $use_in_popup = false) { + $translations = array( + 'selected' => $this->l('selected'), + 'Collapse All' => $this->l('Collapse All'), + 'Expand All' => $this->l('Expand All'), + 'Check All' => $this->l('Check All'), + 'Uncheck All' => $this->l('Uncheck All'), + 'search' => $this->l('Find a category') + ); + + if (!$root) + { + $root_category = Category::getRootCategory(); + $root = array('name' => $root_category->name, 'id_category' => $root_category->id); + } + if (!$use_radio) $input_name = $input_name.'[]'; $context = Context::getContext(); $context->controller->addCSS(_PS_JS_DIR_.'jquery/plugins/treeview/jquery.treeview.css'); - $context->controller->addJs(array( _PS_JS_DIR_.'jquery/plugins/treeview/jquery.treeview.js', _PS_JS_DIR_.'jquery/plugins/treeview/jquery.treeview.async.js', @@ -152,8 +206,8 @@ class HelperCore else $html .= 'var selectedCat = "";'; $html .= ' - var selectedLabel = \''.$trads['selected'].'\'; - var home = \''.$trads['Root']['name'].'\'; + var selectedLabel = \''.$translations['selected'].'\'; + var home = \''.$root['name'].'\'; var use_radio = '.(int)$use_radio.';'; if (!$use_in_popup) $html .= ' @@ -166,15 +220,15 @@ class HelperCore $html .= '
- '.$trads['Collapse All'].' + '.$translations['Collapse All'].' | - '.$trads['Expand All'].' + '.$translations['Expand All'].' '.(!$use_radio ? ' | - '.$trads['Check All'].' + '.$translations['Check All'].' | - '.$trads['Uncheck All'].'| - ' : '').($use_search ? ''.$trads['search'].' : ' : '').' + '.$translations['Uncheck All'].'| + ' : '').($use_search ? ''.$translations['search'].' : ' : '').'
'; @@ -185,7 +239,7 @@ class HelperCore if (is_array($cat)) { $disabled = in_array($cat['id_category'], $disabled_categories); - if ($cat['id_category'] != $trads['Root']['id_category']) + if ($cat['id_category'] != $root['id_category']) $html .= ''; else $home_is_selected = true; @@ -193,7 +247,7 @@ class HelperCore else { $disabled = in_array($cat, $disabled_categories); - if ($cat != $trads['Root']['id_category']) + if ($cat != $root['id_category']) $html .= ''; else $home_is_selected = true; @@ -201,8 +255,13 @@ class HelperCore } $html .= '