// Added Helper::createTemplate()

This commit is contained in:
tDidierjean
2011-11-04 13:31:09 +00:00
parent e986eee78b
commit ad2db3a45b
10 changed files with 85 additions and 102 deletions
@@ -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 <contact@prestashop.com>
* @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
*}
<fieldset>
<legend><img src="../img/admin/tab-tools.gif" />{l s='Shop Tools'}</legend>
<p>{l s='Several tools are available to manage your shop.'}</p>
<br />
<p>{l s='Please choose a tool by selecting a Tools sub-tab above.'}</p>
</fieldset>
+3 -7
View File
@@ -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;
+34 -11
View File
@@ -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
+7 -6
View File
@@ -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;
+25 -29
View File
@@ -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');
+7 -1
View File
@@ -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);
@@ -485,7 +485,7 @@ class AdminAttributesGroupsControllerCore extends AdminController
{
/* Hook */
Hook::exec('actionObjectAttributeGroupAddBefore');
if (Tools::getValue('submitDel'.$this->table))
{
if ($this->tabAccess['delete'] === '1')
+5 -8
View File
@@ -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').' <b>'.$values['title'].'</b> '.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;
@@ -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;
@@ -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';