From c6a19483414fd30939ea9ae6d07b3bf9d02677fe Mon Sep 17 00:00:00 2001 From: dMetzger Date: Mon, 9 Jul 2012 14:12:37 +0000 Subject: [PATCH] [*] BO : Added an override capability for the admin templates --- classes/Dispatcher.php | 2 +- classes/controller/AdminController.php | 35 +++++++++++++++----------- classes/helper/Helper.php | 7 +++++- install-dev/data/db_structure.sql | 2 +- 4 files changed, 29 insertions(+), 17 deletions(-) diff --git a/classes/Dispatcher.php b/classes/Dispatcher.php index e97cb99c9..e8be5c7d6 100644 --- a/classes/Dispatcher.php +++ b/classes/Dispatcher.php @@ -245,7 +245,7 @@ class DispatcherCore { // Dispatch front office controller case self::FC_FRONT : - $controllers = Dispatcher::getControllers(_PS_FRONT_CONTROLLER_DIR_); + $controllers = Dispatcher::getControllers(_PS_FRONT_CONTROLLER_DIR_, _PS_OVERRIDE_DIR_.'controllers/front/'); $controllers['index'] = 'IndexController'; if (isset($controllers['auth'])) diff --git a/classes/controller/AdminController.php b/classes/controller/AdminController.php index 6e5cca4d8..8118f8e95 100644 --- a/classes/controller/AdminController.php +++ b/classes/controller/AdminController.php @@ -269,7 +269,10 @@ class AdminControllerCore extends Controller $this->multishop_context = Shop::CONTEXT_ALL | Shop::CONTEXT_GROUP | Shop::CONTEXT_SHOP; $this->bo_theme = ((Validate::isLoadedObject($this->context->employee) && $this->context->employee->bo_theme) ? $this->context->employee->bo_theme : 'default'); - $this->context->smarty->setTemplateDir(_PS_BO_ALL_THEMES_DIR_.$this->bo_theme.'/template'); + $this->context->smarty->setTemplateDir(array( + _PS_BO_ALL_THEMES_DIR_.$this->bo_theme.DIRECTORY_SEPARATOR.'template', + _PS_OVERRIDE_DIR_.'controllers'.DIRECTORY_SEPARATOR.'admin'.DIRECTORY_SEPARATOR.'templates' + )); $this->id = Tab::getIdFromClassName($this->controller_name); $this->token = Tools::getAdminToken($this->controller_name.(int)$this->id.(int)$this->context->employee->id); @@ -1099,14 +1102,14 @@ class AdminControllerCore extends Controller // Check if action template has been override - // new smarty : template_dir is an array. - // @todo : add override path to the smarty config, and checking all array item - if (file_exists($this->context->smarty->getTemplateDir(0).'/'.$tpl_action) && $this->display != 'view' && $this->display != 'options') - { - if (method_exists($this, $this->display.Tools::toCamelCase($this->className))) - $this->{$this->display.Tools::toCamelCase($this->className)}(); - $this->context->smarty->assign('content', $this->context->smarty->fetch($tpl_action)); - } + foreach ($this->context->smarty->getTemplateDir() as $template_dir) + if (file_exists($template_dir.DIRECTORY_SEPARATOR.$tpl_action) && $this->display != 'view' && $this->display != 'options') + { + if (method_exists($this, $this->display.Tools::toCamelCase($this->className))) + $this->{$this->display.Tools::toCamelCase($this->className)}(); + $this->context->smarty->assign('content', $this->context->smarty->fetch($tpl_action)); + break; + } if (!$this->ajax) { @@ -1448,7 +1451,8 @@ class AdminControllerCore extends Controller $helper = new HelperView($this); $this->setHelperDisplay($helper); $helper->tpl_vars = $this->tpl_view_vars; - !is_null($this->base_tpl_view) ? $helper->base_tpl = $this->base_tpl_view : ''; + if (!is_null($this->base_tpl_view)) + $helper->base_tpl = $this->base_tpl_view; $view = $helper->generateView(); return $view; @@ -2630,10 +2634,13 @@ class AdminControllerCore extends Controller { // Use override tpl if it exists // If view access is denied, we want to use the default template that will be used to display an error - if ($this->viewAccess() - && $this->override_folder - && file_exists($this->context->smarty->getTemplateDir(0).'controllers/'.$this->override_folder.$tpl_name)) - return $this->context->smarty->createTemplate('controllers/'.$this->override_folder.$tpl_name, $this->context->smarty); + if ($this->viewAccess() && $this->override_folder) + { + if (file_exists($this->context->smarty->getTemplateDir(0).'controllers'.DIRECTORY_SEPARATOR.$this->override_folder.$tpl_name)) + return $this->context->smarty->createTemplate('controllers'.DIRECTORY_SEPARATOR.$this->override_folder.$tpl_name, $this->context->smarty); + if (file_exists($this->context->smarty->getTemplateDir(1).DIRECTORY_SEPARATOR.$this->override_folder.$tpl_name)) + return $this->context->smarty->createTemplate($this->override_folder.$tpl_name, $this->context->smarty); + } return $this->context->smarty->createTemplate($this->context->smarty->getTemplateDir(0).$tpl_name, $this->context->smarty); } diff --git a/classes/helper/Helper.php b/classes/helper/Helper.php index e02ee7fc5..de0250031 100755 --- a/classes/helper/Helper.php +++ b/classes/helper/Helper.php @@ -86,7 +86,12 @@ class HelperCore 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 - $override_tpl_path = $this->context->smarty->getTemplateDir(0).'controllers/'.$this->override_folder.$this->base_folder.$tpl_name; + { + if (file_exists($this->context->smarty->getTemplateDir(0).DIRECTORY_SEPARATOR.'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; + elseif (file_exists($this->context->smarty->getTemplateDir(1).DIRECTORY_SEPARATOR.$this->override_folder.$this->base_folder.$tpl_name)) + $override_tpl_path = $this->context->smarty->getTemplateDir(1).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; diff --git a/install-dev/data/db_structure.sql b/install-dev/data/db_structure.sql index 0ec4b9110..b835f5bbf 100644 --- a/install-dev/data/db_structure.sql +++ b/install-dev/data/db_structure.sql @@ -2368,7 +2368,7 @@ INDEX (`id_specific_price_rule_condition_group`) ) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8; CREATE TABLE IF NOT EXISTS `PREFIX_risk` ( - `id_risk` int(11) NOT NULL AUTO_INCREMENT, + `id_risk` int(11) unsigned NOT NULL AUTO_INCREMENT, `percent` tinyint(3) NOT NULL, `color` varchar(32) NULL, PRIMARY KEY (`id_risk`)