* @copyright 2007-2014 PrestaShop SA * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ class HelperCore { public $currentIndex; public $table = 'configuration'; public $identifier; public $token; public $toolbar_btn; public $ps_help_context; public $title; public $show_toolbar = true; public $context; public $toolbar_scroll = false; public $bootstrap = false; /** * @var Module */ public $module; /** @var string Helper tpl folder */ public $base_folder; /** @var string Controller tpl folder */ public $override_folder; /** * @var smartyTemplate base template object */ protected $tpl; /** * @var string base template name */ public $base_tpl = 'content.tpl'; public $tpl_vars = array(); public function __construct() { $this->context = Context::getContext(); } public function setTpl($tpl) { $this->tpl = $this->createTemplate($tpl); } /** * Create a template from the override file, else from the base file. * * @param string $tpl_name filename * @return Template */ public function createTemplate($tpl_name) { if ($this->override_folder) { if ($this->context->controller instanceof ModuleAdminController) $override_tpl_path = $this->context->controller->getTemplatePath().$this->override_folder.$this->base_folder.$tpl_name; else if ($this->module) $override_tpl_path = _PS_MODULE_DIR_.$this->module->name.'/views/templates/admin/_configure/'.$this->override_folder.$this->base_folder.$tpl_name; else { if (file_exists($this->context->smarty->getTemplateDir(1).$this->override_folder.$this->base_folder.$tpl_name)) $override_tpl_path = $this->context->smarty->getTemplateDir(1).$this->override_folder.$this->base_folder.$tpl_name; else if (file_exists($this->context->smarty->getTemplateDir(0).'controllers'.DIRECTORY_SEPARATOR.$this->override_folder.$this->base_folder.$tpl_name)) $override_tpl_path = $this->context->smarty->getTemplateDir(0).'controllers'.DIRECTORY_SEPARATOR.$this->override_folder.$this->base_folder.$tpl_name; } } else if ($this->module) $override_tpl_path = _PS_MODULE_DIR_.$this->module->name.'/views/templates/admin/_configure/'.$this->base_folder.$tpl_name; if (isset($override_tpl_path) && file_exists($override_tpl_path)) return $this->context->smarty->createTemplate($override_tpl_path, $this->context->smarty); else return $this->context->smarty->createTemplate($this->base_folder.$tpl_name, $this->context->smarty); } /** * default behaviour for helper is to return a tpl fetched * * @return string */ public function generate() { $this->tpl->assign($this->tpl_vars); return $this->tpl->fetch(); } /** * @deprecated 1.5.0 */ public static function renderAdminCategorieTree($translations, $selected_cat = array(), $input_name = 'categoryBox', $use_radio = false, $use_search = false, $disabled_categories = array(), $use_in_popup = false) { Tools::displayAsDeprecated(); $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 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 * ( * [0] => 1 * [1] => 2 * ) * OR * Array * ( * [1] => Array * ( * [id_category] => 1 * [name] => Home page * ) * ) * @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 * @param bool $use_shop_context * @return string */ public function renderCategoryTree($root = null, $selected_cat = array(), $input_name = 'categoryBox', $use_radio = false, $use_search = false, $disabled_categories = array(), $use_in_popup = false, $use_shop_context = 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') ); $top_category = Category::getTopCategory(); if (Tools::isSubmit('id_shop')) $id_shop = Tools::getValue('id_shop'); else if (Context::getContext()->shop->id) $id_shop = Context::getContext()->shop->id; else if (!Shop::isFeatureActive()) $id_shop = Configuration::get('PS_SHOP_DEFAULT'); else $id_shop = 0; $shop = new Shop($id_shop); $root_category = Category::getRootCategory(null, $shop); $disabled_categories[] = $top_category->id; if (!$root) $root = array('name' => $root_category->name, 'id_category' => $root_category->id); if (!$use_radio) $input_name = $input_name.'[]'; if ($use_search) $this->context->controller->addJs(_PS_JS_DIR_.'jquery/plugins/autocomplete/jquery.autocomplete.js'); $html = ' '; $html .= '
'; $html .= '