From ad2db3a45b4d7b38407e95009e8664f7877db075 Mon Sep 17 00:00:00 2001 From: tDidierjean Date: Fri, 4 Nov 2011 13:31:09 +0000 Subject: [PATCH] // Added Helper::createTemplate() --- admin-dev/themes/template/tools/content.tpl | 32 ----------- classes/AdminController.php | 10 ++-- classes/Helper.php | 45 ++++++++++++---- classes/HelperForm.php | 13 ++--- classes/HelperList.php | 54 +++++++++---------- classes/HelperOptions.php | 8 ++- .../admin/AdminAttributesGroupsController.php | 2 +- controllers/admin/AdminDbController.php | 13 ++--- .../admin/AdminDeliverySlipController.php | 4 +- .../admin/AdminTaxRulesGroupController.php | 6 +-- 10 files changed, 85 insertions(+), 102 deletions(-) delete mode 100644 admin-dev/themes/template/tools/content.tpl diff --git a/admin-dev/themes/template/tools/content.tpl b/admin-dev/themes/template/tools/content.tpl deleted file mode 100644 index ea438ce38..000000000 --- a/admin-dev/themes/template/tools/content.tpl +++ /dev/null @@ -1,32 +0,0 @@ -{* -* 2007-2011 PrestaShop -* -* NOTICE OF LICENSE -* -* This source file is subject to the Academic Free License (AFL 3.0) -* that is bundled with this package in the file LICENSE.txt. -* It is also available through the world-wide-web at this URL: -* http://opensource.org/licenses/afl-3.0.php -* If you did not receive a copy of the license and are unable to -* obtain it through the world-wide-web, please send an email -* to license@prestashop.com so we can send you a copy immediately. -* -* DISCLAIMER -* -* Do not edit or add to this file if you wish to upgrade PrestaShop to newer -* versions in the future. If you wish to customize PrestaShop for your -* needs please refer to http://www.prestashop.com for more information. -* -* @author PrestaShop SA -* @copyright 2007-2011 PrestaShop SA -* @version Release: $Revision$ -* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*} - -
- {l s='Shop Tools'} -

{l s='Several tools are available to manage your shop.'}

-
-

{l s='Please choose a tool by selecting a Tools sub-tab above.'}

-
diff --git a/classes/AdminController.php b/classes/AdminController.php index 90c4923de..b67d8de7b 100644 --- a/classes/AdminController.php +++ b/classes/AdminController.php @@ -1230,7 +1230,7 @@ class AdminControllerCore extends Controller $helper->shopLink = $this->shopLink; $helper->shopLinkType = $this->shopLinkType; $helper->identifier = $this->identifier; - $helper->tpl_folder = $this->tpl_folder; + $helper->override_folder = $this->tpl_folder; $helper->token = $this->token; $helper->specificConfirmDelete = $this->specificConfirmDelete; $helper->imageType = $this->imageType; @@ -1254,9 +1254,7 @@ class AdminControllerCore extends Controller { $this->getlanguages(); $helper = new HelperForm($this); - // Check if form template has been overriden - if (file_exists($this->context->smarty->template_dir[0].'/'.$this->tpl_folder.'form.tpl')) - $helper->setTpl($this->tpl_folder.'form.tpl'); + $helper->override_folder = $this->tpl_folder; $helper->currentIndex = self::$currentIndex; $helper->token = $this->token; $helper->table = $this->table; @@ -1288,9 +1286,7 @@ class AdminControllerCore extends Controller if ($this->options && is_array($this->options)) { $helper = new HelperOptions(); - // Check if form template has been overriden - if (file_exists($this->context->smarty->template_dir[0].'/'.$this->tpl_folder.'options.tpl')) - $helper->setTpl($this->tpl_folder.'options.tpl'); + $helper->override_folder = $this->tpl_folder; $helper->id = $this->id; $helper->token = $this->token; $helper->shopLinkType = $this->shopLinkType; diff --git a/classes/Helper.php b/classes/Helper.php index eae14e7a1..ebb58188f 100755 --- a/classes/Helper.php +++ b/classes/Helper.php @@ -42,29 +42,53 @@ class HelperCore public $no_back = false; public $context; + /** @var string Helper tpl folder */ + public $base_folder; + + /** @var string Controller tpl folder */ + public $override_folder; + /** - * @var string filename, then smartyTemplate object + * @var smartyTemplate base template object */ - protected $tpl = 'content.tpl'; - + protected $tpl; + + /** + * @var string base template name + */ + protected $base_tpl = 'content.tpl'; + public $tpl_vars = array(); public function __construct() { $this->context = Context::getContext(); - $this->tpl = $this->context->smarty->createTemplate($this->tpl); - } - - public function setTpl($tpl) + } + + /*public function setTpl($tpl) { - if (file_exists($this->context->smarty->template_dir[0].'/'.$tpl)) - $this->tpl = $this->context->smarty->createTemplate($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) + { + // Overrides exists? + if ($this->override_folder && file_exists($this->context->smarty->template_dir[0].$this->override_folder.$tpl_name)) + return $this->context->smarty->createTemplate($this->override_folder.$tpl_name); + + return $this->context->smarty->createTemplate($this->base_folder.$tpl_name); } /** * default behaviour for helper is to return a tpl fetched - * + * * @return void */ public function generate() @@ -73,7 +97,6 @@ class HelperCore return $this->tpl->fetch(); } - /** * * @param type $trads values of translations keys diff --git a/classes/HelperForm.php b/classes/HelperForm.php index 6c0b905ec..168b2996b 100644 --- a/classes/HelperForm.php +++ b/classes/HelperForm.php @@ -27,9 +27,7 @@ class HelperFormCore extends Helper { - public $id; - public $first_call = true; public $toolbar = true; @@ -39,9 +37,7 @@ class HelperFormCore extends Helper * */ protected $fields_form = array(); - public $fields_value = array(); - public $table; /** @@ -51,12 +47,16 @@ class HelperFormCore extends Helper public $submit_action = ''; public $token; - public $languages = null; public $default_form_language = null; public $allow_employee_form_lang = null; - protected $tpl = 'helper/form/form.tpl'; + public function __construct() + { + $this->base_folder = 'helper/form/'; + $this->base_tpl = 'form.tpl'; + parent::__construct(); + } public function generateForm($fields_form) { @@ -66,6 +66,7 @@ class HelperFormCore extends Helper public function generate() { + $this->tpl = $this->createTemplate($this->base_tpl); if ($this->submit_action == '') $this->submit_action = 'submitAdd'.$this->table; diff --git a/classes/HelperList.php b/classes/HelperList.php index d2872a1c2..e93f3f51a 100644 --- a/classes/HelperList.php +++ b/classes/HelperList.php @@ -55,9 +55,6 @@ class HelperListCore extends Helper protected $deleted = 0; - /** @var string Folder of controller */ - public $tpl_folder; - /** @var array $cache_lang use to cache texts in current language */ public static $cache_lang = array(); @@ -81,10 +78,9 @@ class HelperListCore extends Helper /** @var boolean Content line is clickable if true */ public $no_link = false; - protected $tpl = 'helper/list/list.tpl'; - protected $header_tpl = 'helper/list/list_header.tpl'; - protected $content_tpl = 'helper/list/list_content.tpl'; - protected $footer_tpl = 'helper/list/list_footer.tpl'; + protected $header_tpl = 'list_header.tpl'; + protected $content_tpl = 'list_content.tpl'; + protected $footer_tpl = 'list_footer.tpl'; /** @var array list of required actions for each list row */ public $actions = array(); @@ -113,25 +109,18 @@ class HelperListCore extends Helper /** @var boolean ask for simple header : no filters, no paginations and no sorting */ public $simple_header = false; + /** + * @var bool + * Usage : Set the value to false if you want to simply display the back button + */ + public $no_back = true; + public function __construct() { + $this->base_folder = 'helper/list/'; + $this->base_tpl = 'list.tpl'; + parent::__construct(); - $smarty = $this->context->smarty; - $controller = $this->context->controller; - - // handle template overriding (smarty 3 template inheritance) - if (file_exists($smarty->template_dir[0].'/'.$controller->tpl_folder.'list_header.tpl')) - $this->header_tpl = $controller->tpl_folder.'list_header.tpl'; - - if (file_exists($smarty->template_dir[0].'/'.$controller->tpl_folder.'list_content.tpl')) - $this->content_tpl = $controller->tpl_folder.'list_content.tpl'; - - if (file_exists($smarty->template_dir[0].'/'.$controller->tpl_folder.'list_footer.tpl')) - $this->footer_tpl = $controller->tpl_folder.'list_footer.tpl'; - - $this->header_tpl = $this->context->smarty->createTemplate($this->header_tpl); - $this->content_tpl = $this->context->smarty->createTemplate($this->content_tpl); - $this->footer_tpl = $this->context->smarty->createTemplate($this->footer_tpl); } /** @@ -152,6 +141,12 @@ class HelperListCore extends Helper $this->displayWarning($this->l('Bad SQL query')); return false; } + + $this->tpl = $this->createTemplate($this->base_tpl); + $this->header_tpl = $this->createTemplate($this->header_tpl); + $this->content_tpl = $this->createTemplate($this->content_tpl); + $this->footer_tpl = $this->createTemplate($this->footer_tpl); + $this->_list = $list; $this->fieldsDisplay = $fields_display; @@ -162,6 +157,7 @@ class HelperListCore extends Helper /* Close list table and submit button */ $tpl_vars['footer'] = $this->displayListFooter(); + $this->tpl->assign($tpl_vars); return parent::generate(); } @@ -178,7 +174,7 @@ class HelperListCore extends Helper */ protected function displayEnableLink($token, $id, $value, $active, $id_category = null, $id_product = null) { - $tpl_enable = $this->context->smarty->createTemplate('helper/list/list_action_enable.tpl'); + $tpl_enable = $this->createTemplate('list_action_enable.tpl'); $tpl_enable->assign(array( 'enabled' => (bool)$value, 'url_enable' => $this->currentIndex.'&'.$this->identifier.'='.$id.'&'.$active.$this->table. @@ -353,7 +349,7 @@ class HelperListCore extends Helper */ protected function displayDuplicateLink($token = null, $id) { - $tpl = $this->context->smarty->createTemplate('helper/list/list_action_duplicate.tpl'); + $tpl = $this->createTemplate('list_action_duplicate.tpl'); if (!array_key_exists('Duplicate', self::$cache_lang)) self::$cache_lang['Duplicate'] = $this->l('Duplicate'); @@ -395,7 +391,7 @@ class HelperListCore extends Helper */ protected function displayDetailsLink($token = null, $id) { - $tpl = $this->context->smarty->createTemplate('helper/list/list_action_details.tpl'); + $tpl = $this->createTemplate('list_action_details.tpl'); if (!array_key_exists('Details', self::$cache_lang)) self::$cache_lang['Details'] = $this->l('Details'); $tpl->assign(array( @@ -412,7 +408,7 @@ class HelperListCore extends Helper */ protected function displayViewLink($token = null, $id) { - $tpl = $this->context->smarty->createTemplate('helper/list/list_action_view.tpl'); + $tpl = $this->createTemplate('list_action_view.tpl'); if (!array_key_exists('View', self::$cache_lang)) self::$cache_lang['View'] = $this->l('View'); @@ -430,7 +426,7 @@ class HelperListCore extends Helper */ protected function displayEditLink($token = null, $id) { - $tpl = $this->context->smarty->createTemplate('helper/list/list_action_edit.tpl'); + $tpl = $this->createTemplate('list_action_edit.tpl'); if (!array_key_exists('Edit', self::$cache_lang)) self::$cache_lang['Edit'] = $this->l('Edit'); @@ -449,7 +445,7 @@ class HelperListCore extends Helper */ protected function displayDeleteLink($token = null, $id) { - $tpl = $this->context->smarty->createTemplate('helper/list/list_action_delete.tpl'); + $tpl = $this->createTemplate('list_action_delete.tpl'); if (!array_key_exists('Delete', self::$cache_lang)) self::$cache_lang['Delete'] = $this->l('Delete'); diff --git a/classes/HelperOptions.php b/classes/HelperOptions.php index efb112e7c..48efcaaee 100644 --- a/classes/HelperOptions.php +++ b/classes/HelperOptions.php @@ -42,7 +42,12 @@ class HelperOptionsCore extends Helper public $fields_value = array(); - public $tpl = 'helper/options/options.tpl'; + public function __construct() + { + $this->base_folder = 'helper/options/'; + $this->base_tpl = 'options.tpl'; + parent::__construct(); + } /** * Generate a form for options @@ -51,6 +56,7 @@ class HelperOptionsCore extends Helper */ public function generateOptions($option_list) { + $this->tpl = $this->createTemplate($this->base_tpl); $tab = Tab::getTab($this->context->language->id, $this->id); if (!isset($languages)) $languages = Language::getLanguages(false); diff --git a/controllers/admin/AdminAttributesGroupsController.php b/controllers/admin/AdminAttributesGroupsController.php index 88be5cfbd..947785d49 100644 --- a/controllers/admin/AdminAttributesGroupsController.php +++ b/controllers/admin/AdminAttributesGroupsController.php @@ -485,7 +485,7 @@ class AdminAttributesGroupsControllerCore extends AdminController { /* Hook */ Hook::exec('actionObjectAttributeGroupAddBefore'); - + if (Tools::getValue('submitDel'.$this->table)) { if ($this->tabAccess['delete'] === '1') diff --git a/controllers/admin/AdminDbController.php b/controllers/admin/AdminDbController.php index b6b632245..760e6a5c6 100644 --- a/controllers/admin/AdminDbController.php +++ b/controllers/admin/AdminDbController.php @@ -58,14 +58,10 @@ class AdminDbControllerCore extends AdminController public function initContent() { - parent::initContent(); - $this->warnings[] = $this->l('Be VERY CAREFUL with these settings, as changes may cause your PrestaShop online store to malfunction. For all issues, check the config/settings.inc.php file.'); - $helper = new HelperOptions(); - $helper->id = $this->id; - $helper->currentIndex = self::$currentIndex; - $this->content .= $helper->generateOptions($this->options); + $this->content .= $this->initToolbar(); + $this->content .= $this->initOptions(); $table_status = $this->getTablesStatus(); foreach ($table_status as $key => $table) @@ -76,6 +72,7 @@ class AdminDbControllerCore extends AdminController 'update_url' => self::$currentIndex.'&submitAdd'.$this->table.'=1&token='.$this->token, 'table_status' => $table_status, 'engines' => $this->getEngines(), + 'content' => $this->content, )); } @@ -91,7 +88,7 @@ class AdminDbControllerCore extends AdminController if ($this->action == 'update_options') { - foreach ($this->optionsList['database']['fields'] AS $field => $values) + foreach ($this->options['database']['fields'] AS $field => $values) if (isset($values['required']) AND $values['required']) if (($value = Tools::getValue($field)) == false AND (string)$value != '0') $this->_errors[] = Tools::displayError('field').' '.$values['title'].' '.Tools::displayError('is required.'); @@ -100,7 +97,7 @@ class AdminDbControllerCore extends AdminController { /* Datas are not saved in database but in config/settings.inc.php */ $settings = array(); - foreach ($this->optionsList['database']['fields'] as $k => $data) + foreach ($this->options['database']['fields'] as $k => $data) if ($value = Tools::getValue($k)) $settings['_'.Tools::strtoupper($k).'_'] = $value; diff --git a/controllers/admin/AdminDeliverySlipController.php b/controllers/admin/AdminDeliverySlipController.php index 78354086a..eb3ad2516 100644 --- a/controllers/admin/AdminDeliverySlipController.php +++ b/controllers/admin/AdminDeliverySlipController.php @@ -117,9 +117,7 @@ class AdminDeliverySlipControllerCore extends AdminController { $this->initForm(); $helper = new HelperForm(); - // Check if form template has been overriden - if (file_exists($this->context->smarty->template_dir[0].'/'.$this->tpl_folder.'form.tpl')) - $helper->tpl = $this->tpl_folder.'form.tpl'; + $helper->override_folder = $this->tpl_folder; $helper->currentIndex = self::$currentIndex; $helper->token = $this->token; $helper->table = $this->table; diff --git a/controllers/admin/AdminTaxRulesGroupController.php b/controllers/admin/AdminTaxRulesGroupController.php index a0fc0a9b2..c0876e4b8 100644 --- a/controllers/admin/AdminTaxRulesGroupController.php +++ b/controllers/admin/AdminTaxRulesGroupController.php @@ -124,7 +124,7 @@ class AdminTaxRulesGroupControllerCore extends AdminController t.rate'; $this->_join = ' - LEFT JOIN `'._DB_PREFIX_.'country_lang` c + LEFT JOIN `'._DB_PREFIX_.'country_lang` c ON (a.`id_country` = c.`id_country` AND id_lang = '.(int)$this->context->language->id.') LEFT JOIN `'._DB_PREFIX_.'state` s ON (a.`id_state` = s.`id_state`) @@ -332,9 +332,7 @@ class AdminTaxRulesGroupControllerCore extends AdminController $this->getlanguages(); $helper = new HelperForm(); - // Check if form template has been overriden - if (file_exists($this->context->smarty->template_dir[0].'/'.$this->tpl_folder.'form.tpl')) - $helper->setTpl($this->tpl_folder.'form.tpl'); + $helper->override_tpl = $this->tpl_folder; $helper->currentIndex = self::$currentIndex; $helper->token = $this->token; $helper->table = 'tax_rule';