From d1afff824a9fd5bc30222fa995f0b83a4e110fc9 Mon Sep 17 00:00:00 2001 From: fSerny Date: Thu, 2 Feb 2012 10:39:17 +0000 Subject: [PATCH] [*] BO : Each module hooked on displayAdminProductsExtra add a Product Tab git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@12924 b9a71923-0436-4b27-9f14-aed3839534dd --- classes/Module.php | 20 +++++++++++++ controllers/admin/AdminProductsController.php | 30 +++++++++++++++---- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/classes/Module.php b/classes/Module.php index 93ff00b0b..2d5216367 100644 --- a/classes/Module.php +++ b/classes/Module.php @@ -827,6 +827,26 @@ abstract class ModuleCore return str_replace('\'', '\\\'', Tools::htmlentitiesDecodeUTF8($string)); } + + public static function getModuleName($module) + { + // Config file + $configFile = _PS_MODULE_DIR_.$module.'/config.xml'; + if (!file_exists($configFile)) + return 'Module '.ucfirst($module); + + // Load config.xml + libxml_use_internal_errors(true); + $xml_module = simplexml_load_file($configFile); + foreach (libxml_get_errors() as $error) + return 'Module '.ucfirst($module); + libxml_clear_errors(); + + // Return Name + return Module::findTranslation($xml_module->name, Module::configXmlStringFormat($xml_module->displayName), (string)$xml_module->name); + } + + /** * Return available modules * diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index 28586d7db..a1ce6ac3b 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -38,6 +38,7 @@ class AdminProductsControllerCore extends AdminController * @var string name of the tab to display */ protected $tab_display; + protected $tab_display_module; /** * The order in the array decides the order in the list of tab. If an element's value is a number, it will be preloaded. @@ -166,10 +167,11 @@ class AdminProductsControllerCore extends AdminController /* Adding tab if modules are hooked */ $modules_list = Hook::getHookModuleExecList('displayAdminProductsExtra'); if (is_array($modules_list) && count($modules_list) > 0) - { - $this->available_tabs['Others'] = 23; - $this->available_tabs_lang['Others'] = $this->l('Others'); - } + foreach ($modules_list as $m) + { + $this->available_tabs['Module'.ucfirst($m['module'])] = 23; + $this->available_tabs_lang['Module'.ucfirst($m['module'])] = Module::getModuleName($m['module']); + } /* Join categories table */ @@ -1820,6 +1822,13 @@ class AdminProductsControllerCore extends AdminController $this->addJS(_PS_JS_DIR_.'admin-products.js'); $this->fields_form = array(); + // Check if Module + if (substr($this->tab_display, 0, 6) == 'Module') + { + $this->tab_display_module = strtolower(substr($this->tab_display, 6, strlen($this->tab_display) - 6)); + $this->tab_display = 'Modules'; + } + if (method_exists($this, 'initForm'.$this->tab_display)) $this->tpl_form = strtolower($this->tab_display).'.tpl'; @@ -1828,6 +1837,14 @@ class AdminProductsControllerCore extends AdminController else { $product_tabs = array(); + + // Check if Module + if (substr($this->tab_display, 0, 6) == 'Module') + { + $this->tab_display = 'Module'; + $this->tab_display_module = strtolower(substr($this->tab_display, 6, strlen($this->tab_display) - 6)); + } + // tab_display defines which tab to display first if (!method_exists($this, 'initForm'.$this->tab_display)) $this->tab_display = $this->default_tab; @@ -3778,9 +3795,10 @@ class AdminProductsControllerCore extends AdminController /** * AdminProducts display hook */ - public function initFormOthers($obj) + public function initFormModules($obj) { - $this->tpl_form_vars['custom_form'] = hook::exec('displayAdminProductsExtra'); + $id_module = Db::getInstance()->getValue('SELECT `id_module` FROM `'._DB_PREFIX_.'module` WHERE `name` = \''.pSQL($this->tab_display_module).'\''); + $this->tpl_form_vars['custom_form'] = hook::exec('displayAdminProductsExtra', array(), (int)$id_module); }