// Code review : normalise and todo

This commit is contained in:
rMalie
2012-01-20 15:19:27 +00:00
parent 1172172cdb
commit a406caa4ee
7 changed files with 60 additions and 69 deletions
+13 -23
View File
@@ -98,16 +98,7 @@ class HelperCore
} }
/** /**
* Since 1.5 - This function will be deprecated in 1.6 - use Helper::renderCategoryTree() instead * @deprecated 1.5.0
* @static
* @param $translations
* @param array $selected_cat
* @param string $input_name
* @param bool $use_radio
* @param bool $use_search
* @param array $disabled_categories
* @param bool $use_in_popup
* @return mixed
*/ */
public static function renderAdminCategorieTree($translations, public static function renderAdminCategorieTree($translations,
$selected_cat = array(), $selected_cat = array(),
@@ -117,6 +108,8 @@ class HelperCore
$disabled_categories = array(), $disabled_categories = array(),
$use_in_popup = false) $use_in_popup = false)
{ {
Tools::displayAsDeprecated();
$helper = new Helper(); $helper = new Helper();
if (isset($translations['Root'])) if (isset($translations['Root']))
$root = $translations['Root']; $root = $translations['Root'];
@@ -169,7 +162,7 @@ class HelperCore
'Check All' => $this->l('Check All'), 'Check All' => $this->l('Check All'),
'Uncheck All' => $this->l('Uncheck All'), 'Uncheck All' => $this->l('Uncheck All'),
'search' => $this->l('Find a category') 'search' => $this->l('Find a category')
); );
if (!$root) if (!$root)
{ {
@@ -180,22 +173,20 @@ class HelperCore
if (!$use_radio) if (!$use_radio)
$input_name = $input_name.'[]'; $input_name = $input_name.'[]';
$context = Context::getContext(); $this->context->controller->addCSS(_PS_JS_DIR_.'jquery/plugins/treeview/jquery.treeview.css');
$this->context->controller->addJs(array(
$context->controller->addCSS(_PS_JS_DIR_.'jquery/plugins/treeview/jquery.treeview.css');
$context->controller->addJs(array(
_PS_JS_DIR_.'jquery/plugins/treeview/jquery.treeview.js', _PS_JS_DIR_.'jquery/plugins/treeview/jquery.treeview.js',
_PS_JS_DIR_.'jquery/plugins/treeview/jquery.treeview.async.js', _PS_JS_DIR_.'jquery/plugins/treeview/jquery.treeview.async.js',
_PS_JS_DIR_.'jquery/plugins/treeview/jquery.treeview.edit.js', _PS_JS_DIR_.'jquery/plugins/treeview/jquery.treeview.edit.js',
_PS_JS_DIR_.'admin-categories-tree.js')); _PS_JS_DIR_.'admin-categories-tree.js'));
if ($use_search) if ($use_search)
$context->controller->addJs(_PS_JS_DIR_.'jquery/plugins/autocomplete/jquery.autocomplete.js'); $this->context->controller->addJs(_PS_JS_DIR_.'jquery/plugins/autocomplete/jquery.autocomplete.js');
$html = ' $html = '
<script type="text/javascript"> <script type="text/javascript">
var inputName = "'.$input_name.'"; var inputName = "'.$input_name.'";
'; ';
if (sizeof($selected_cat) > 0) if (count($selected_cat) > 0)
{ {
if (isset($selected_cat[0])) if (isset($selected_cat[0]))
$html .= 'var selectedCat = "'.implode(',', $selected_cat).'";'; $html .= 'var selectedCat = "'.implode(',', $selected_cat).'";';
@@ -232,8 +223,7 @@ class HelperCore
'; ';
$home_is_selected = false; $home_is_selected = false;
foreach ($selected_cat as $cat)
foreach($selected_cat AS $cat)
{ {
if (is_array($cat)) if (is_array($cat))
{ {
@@ -252,6 +242,7 @@ class HelperCore
$home_is_selected = true; $home_is_selected = true;
} }
} }
$html .= ' $html .= '
<ul id="categories-treeview" class="filetree"> <ul id="categories-treeview" class="filetree">
<li id="'.$root['id_category'].'" class="hasChildren"> <li id="'.$root['id_category'].'" class="hasChildren">
@@ -278,7 +269,7 @@ class HelperCore
* @param boolean $htmlentities if set to true(default), the return value will pass through htmlentities($string, ENT_QUOTES, 'utf-8') * @param boolean $htmlentities if set to true(default), the return value will pass through htmlentities($string, ENT_QUOTES, 'utf-8')
* @return string the translation if available, or the english default text. * @return string the translation if available, or the english default text.
*/ */
protected function l($string, $class = 'AdminTab', $addslashes = FALSE, $htmlentities = TRUE) protected function l($string, $class = 'AdminTab', $addslashes = false, $htmlentities = true)
{ {
// if the class is extended by a module, use modules/[module_name]/xx.php lang file // if the class is extended by a module, use modules/[module_name]/xx.php lang file
$currentClass = get_class($this); $currentClass = get_class($this);
@@ -314,11 +305,10 @@ class HelperCore
$type = 'shop'; $type = 'shop';
$assos = array(); $assos = array();
if ((int)$this->id) if ((int)$this->id)
{ {
$sql = 'SELECT `id_'.bqSQL($type).'`, `'.bqSQL($this->identifier).'` $sql = 'SELECT `id_'.$type.'`, `'.bqSQL($this->identifier).'`
FROM `'._DB_PREFIX_.bqSQL($this->table).'_'.bqSQL($type).'` FROM `'._DB_PREFIX_.bqSQL($this->table).'_'.$type.'`
WHERE `'.bqSQL($this->identifier).'` = '.(int)$this->id; WHERE `'.bqSQL($this->identifier).'` = '.(int)$this->id;
foreach (Db::getInstance()->executeS($sql) as $row) foreach (Db::getInstance()->executeS($sql) as $row)
+3
View File
@@ -25,6 +25,9 @@
* International Registered Trademark & Property of PrestaShop SA * International Registered Trademark & Property of PrestaShop SA
*/ */
/**
* @since 1.5.0
*/
class HelperFormCore extends Helper class HelperFormCore extends Helper
{ {
public $id; public $id;
-1
View File
@@ -35,7 +35,6 @@ class HelperHelpAccessCore extends Helper
public $country; public $country;
public $ps_version; public $ps_version;
public function __construct($label, $iso_lang, $country, $ps_version) public function __construct($label, $iso_lang, $country, $ps_version)
{ {
parent::__construct(); parent::__construct();
+37 -38
View File
@@ -25,6 +25,9 @@
* International Registered Trademark & Property of PrestaShop SA * International Registered Trademark & Property of PrestaShop SA
*/ */
/**
* @since 1.5.0
*/
class HelperListCore extends Helper class HelperListCore extends Helper
{ {
/** @var array Cache for query results */ /** @var array Cache for query results */
@@ -65,7 +68,8 @@ class HelperListCore extends Helper
protected $is_dnd_identifier = false; protected $is_dnd_identifier = false;
/* Customize list display /**
* @var string Customize list display
* *
* align : determine value alignment * align : determine value alignment
* prefix : displayed before value * prefix : displayed before value
@@ -111,12 +115,6 @@ class HelperListCore extends Helper
/** @var boolean ask for simple header : no filters, no paginations and no sorting */ /** @var boolean ask for simple header : no filters, no paginations and no sorting */
public $simple_header = false; 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 $ajax_params = array(); public $ajax_params = array();
public function __construct() public function __construct()
@@ -131,15 +129,15 @@ class HelperListCore extends Helper
* Return an html list given the data to fill it up * Return an html list given the data to fill it up
* *
* @param array $list entries to display (rows) * @param array $list entries to display (rows)
* @param array $fieldsDisplay fields (cols) * @param array $fields_display fields (cols)
* @return string html * @return string html
*/ */
public function generateList($list, $fields_display) public function generateList($list, $fields_display)
{ {
/*if ($this->edit AND (!isset($this->noAdd) OR !$this->noAdd)) /*if ($this->edit && (!isset($this->noAdd) || !$this->noAdd))
$this->displayAddButton();*/ $this->displayAddButton();*/
/* Append when we get a syntax error in SQL query */ // Append when we get a syntax error in SQL query
if ($list === false) if ($list === false)
{ {
$this->displayWarning($this->l('Bad SQL query', 'helper')); $this->displayWarning($this->l('Bad SQL query', 'helper'));
@@ -153,13 +151,15 @@ class HelperListCore extends Helper
$this->_list = $list; $this->_list = $list;
$this->fieldsDisplay = $fields_display; $this->fieldsDisplay = $fields_display;
/* Display list header (filtering, pagination and column names) */
$tpl_vars['header'] = $this->displayListHeader();
/* Show the content of the table */
$tpl_vars['content'] = $this->displayListContent();
/* Close list table and submit button */
$tpl_vars['footer'] = $this->displayListFooter();
// Display list header (filtering, pagination and column names)
$tpl_vars['header'] = $this->displayListHeader();
// Show the content of the table
$tpl_vars['content'] = $this->displayListContent();
// Close list table and submit button
$tpl_vars['footer'] = $this->displayListFooter();
$this->tpl->assign($tpl_vars); $this->tpl->assign($tpl_vars);
return parent::generate(); return parent::generate();
@@ -174,6 +174,7 @@ class HelperListCore extends Helper
* @param string $active status * @param string $active status
* @param int $id_category * @param int $id_category
* @param int $id_product * @param int $id_product
* @return string
*/ */
protected function displayEnableLink($token, $id, $value, $active, $id_category = null, $id_product = null) protected function displayEnableLink($token, $id, $value, $active, $id_category = null, $id_product = null)
{ {
@@ -186,12 +187,12 @@ class HelperListCore extends Helper
return $tpl_enable->fetch(); return $tpl_enable->fetch();
} }
public function displayListContent($token = null) public function displayListContent()
{ {
if ($this->is_dnd_identifier) if ($this->is_dnd_identifier)
$id_category = (int)Tools::getValue('id_'.($this->is_cms ? 'cms_' : '').'category', '1'); $id_category = (int)Tools::getValue('id_'.($this->is_cms ? 'cms_' : '').'category', '1');
else else
$id_category = 1; // default categ $id_category = Category::getRootCategory();
if (isset($this->fieldsDisplay['position'])) if (isset($this->fieldsDisplay['position']))
{ {
@@ -202,8 +203,6 @@ class HelperListCore extends Helper
$identifier = in_array($this->identifier, array('id_category', 'id_cms_category')) ? '_parent' : ''; $identifier = in_array($this->identifier, array('id_category', 'id_cms_category')) ? '_parent' : '';
$key_to_get = 'id_'.($this->is_cms ? 'cms_' : '').'category'.$identifier; $key_to_get = 'id_'.($this->is_cms ? 'cms_' : '').'category'.$identifier;
$fields = array();
foreach ($this->_list as $index => $tr) foreach ($this->_list as $index => $tr)
{ {
$id = $tr[$this->identifier]; $id = $tr[$this->identifier];
@@ -220,10 +219,9 @@ class HelperListCore extends Helper
$method_name = 'display'.ucfirst($action).'Link'; $method_name = 'display'.ucfirst($action).'Link';
if (method_exists($this->context->controller, $method_name)) if (method_exists($this->context->controller, $method_name))
$this->_list[$index][$action] = $this->context->controller->$method_name($token, $id, $name); $this->_list[$index][$action] = $this->context->controller->$method_name($this->token, $id, $name);
else if (method_exists($this, $method_name)) else if (method_exists($this, $method_name))
$this->_list[$index][$action] = $this->$method_name($token, $id, $name); $this->_list[$index][$action] = $this->$method_name($this->token, $id, $name);
} }
} }
@@ -273,7 +271,8 @@ class HelperListCore extends Helper
{ {
$image = new Image((int)$tr['id_image']); $image = new Image((int)$tr['id_image']);
$path_to_image = _PS_IMG_DIR_.$params['image'].'/'.$image->getExistingImgPath().'.'.$this->imageType; $path_to_image = _PS_IMG_DIR_.$params['image'].'/'.$image->getExistingImgPath().'.'.$this->imageType;
}else }
else
$path_to_image = _PS_IMG_DIR_.$params['image'].'/'.$item_id.(isset($tr['id_image']) ? '-'.(int)$tr['id_image'] : '').'.'.$this->imageType; $path_to_image = _PS_IMG_DIR_.$params['image'].'/'.$item_id.(isset($tr['id_image']) ? '-'.(int)$tr['id_image'] : '').'.'.$this->imageType;
$this->_list[$index][$key] = cacheImage($path_to_image, $this->table.'_mini_'.$item_id.'.'.$this->imageType, 45, $this->imageType); $this->_list[$index][$key] = cacheImage($path_to_image, $this->table.'_mini_'.$item_id.'.'.$this->imageType, 45, $this->imageType);
@@ -300,15 +299,13 @@ class HelperListCore extends Helper
else else
$echo = $tr[$key]; $echo = $tr[$key];
$this->_list[$index][$key] = isset($params['callback']) if (isset($params['callback']))
? {
call_user_func_array(array((isset($params['callback_object'])) $callback_obj = (isset($params['callback_object'])) ? $params['callback_object'] : $this->context->controller;
? $this->_list[$index][$key] = call_user_func_array(array($callback_obj, $params['callback']), array($echo, $tr));
$params['callback_object'] }
: else
$this->context->controller, $params['callback']), array($echo, $tr)) $this->_list[$index][$key] = $echo;
:
$echo;
} }
} }
} }
@@ -442,7 +439,6 @@ class HelperListCore extends Helper
)); ));
return $tpl->fetch(); return $tpl->fetch();
} }
/** /**
@@ -495,7 +491,7 @@ class HelperListCore extends Helper
/** /**
* Display list header (filtering, pagination and column names) * Display list header (filtering, pagination and column names)
*/ */
public function displayListHeader($token = null) public function displayListHeader()
{ {
$id_cat = (int)Tools::getValue('id_'.($this->is_cms ? 'cms_' : '').'category'); $id_cat = (int)Tools::getValue('id_'.($this->is_cms ? 'cms_' : '').'category');
@@ -521,7 +517,8 @@ class HelperListCore extends Helper
/* Determine current page number */ /* Determine current page number */
$page = (int)Tools::getValue('submitFilter'.$this->table); $page = (int)Tools::getValue('submitFilter'.$this->table);
if (!$page) $page = 1; if (!$page)
$page = 1;
/* Choose number of results per page */ /* Choose number of results per page */
$selected_pagination = Tools::getValue( $selected_pagination = Tools::getValue(
@@ -563,6 +560,7 @@ class HelperListCore extends Helper
{ {
case 'bool': case 'bool':
break; break;
case 'date': case 'date':
case 'datetime': case 'datetime':
if (is_string($value)) if (is_string($value))
@@ -573,6 +571,7 @@ class HelperListCore extends Helper
$name_id = str_replace('!', '__', $name); $name_id = str_replace('!', '__', $name);
$this->context->controller->addJqueryUI('ui.datepicker'); $this->context->controller->addJqueryUI('ui.datepicker');
break; break;
case 'select': case 'select':
foreach ($params['list'] as $option_value => $option_display) foreach ($params['list'] as $option_value => $option_display)
{ {
@@ -582,6 +581,7 @@ class HelperListCore extends Helper
$this->fieldsDisplay[$key]['select'][$option_value]['selected'] = 'selected'; $this->fieldsDisplay[$key]['select'][$option_value]['selected'] = 'selected';
} }
break; break;
case 'text': case 'text':
if (!Validate::isCleanHtml($value)) if (!Validate::isCleanHtml($value))
$value = ''; $value = '';
@@ -628,7 +628,7 @@ class HelperListCore extends Helper
/** /**
* Close list table and submit button * Close list table and submit button
*/ */
public function displayListFooter($token = null) public function displayListFooter()
{ {
$this->footer_tpl->assign(array_merge($this->tpl_vars, array( $this->footer_tpl->assign(array_merge($this->tpl_vars, array(
'token' => $this->token, 'token' => $this->token,
@@ -638,5 +638,4 @@ class HelperListCore extends Helper
))); )));
return $this->footer_tpl->fetch(); return $this->footer_tpl->fetch();
} }
} }
+5 -5
View File
@@ -53,7 +53,7 @@ class HelperOptionsCore extends Helper
foreach ($option_list as $category => $category_data) foreach ($option_list as $category => $category_data)
{ {
if(!is_array($category_data)) if (!is_array($category_data))
continue; continue;
if (!isset($category_data['image'])) if (!isset($category_data['image']))
@@ -92,7 +92,6 @@ class HelperOptionsCore extends Helper
// Fill values for all languages for all lang fields // Fill values for all languages for all lang fields
if (substr($field['type'], -4) == 'Lang') if (substr($field['type'], -4) == 'Lang')
{ {
foreach ($languages as $language) foreach ($languages as $language)
{ {
if ($field['type'] == 'textLang') if ($field['type'] == 'textLang')
@@ -107,6 +106,7 @@ class HelperOptionsCore extends Helper
} }
// pre-assign vars to the tpl // pre-assign vars to the tpl
// @todo move this
if ($field['type'] == 'maintenance_ip') if ($field['type'] == 'maintenance_ip')
{ {
$field['script_ip'] = ' $field['script_ip'] = '
@@ -159,7 +159,7 @@ class HelperOptionsCore extends Helper
/** /**
* Type = image * Type = image
* @ TODO * @TODO
*/ */
public function displayOptionTypeImage($key, $field, $value) public function displayOptionTypeImage($key, $field, $value)
{ {
@@ -187,7 +187,7 @@ class HelperOptionsCore extends Helper
/** /**
* Type = price * Type = price
* @ TODO * @TODO
*/ */
public function displayOptionTypePrice($key, $field, $value) public function displayOptionTypePrice($key, $field, $value)
{ {
@@ -199,7 +199,7 @@ class HelperOptionsCore extends Helper
/** /**
* Type = disabled * Type = disabled
* *
* @ TODO * @TODO
*/ */
public function displayOptionTypeDisabled($key, $field, $value) public function displayOptionTypeDisabled($key, $field, $value)
{ {
@@ -340,7 +340,6 @@ class AdminTaxRulesGroupControllerCore extends AdminController
$helper->fields_value = $this->getFieldsValue($this->object); $helper->fields_value = $this->getFieldsValue($this->object);
$helper->toolbar_btn = null; $helper->toolbar_btn = null;
$helper->submit_action = 'create_rule'; $helper->submit_action = 'create_rule';
$helper->no_back = true;
return $helper->generateForm($this->fields_form); return $helper->generateForm($this->fields_form);
} }
+2 -1
View File
@@ -1669,7 +1669,8 @@ class BlockLayered extends Module
'Uncheck All' => $this->l('Uncheck All'), 'Uncheck All' => $this->l('Uncheck All'),
'search' => $this->l('Search a category') 'search' => $this->l('Search a category')
); );
// @todo renderAdminCategorieTree is deprecated in 1.5
$html .= Helper::renderAdminCategorieTree($trads, $selectedCat, 'categoryBox'); $html .= Helper::renderAdminCategorieTree($trads, $selectedCat, 'categoryBox');
$html .= ' $html .= '