// Code review and refactoring
This commit is contained in:
+33
-22
@@ -55,6 +55,7 @@ class HelperListCore extends Helper
|
|||||||
|
|
||||||
protected $deleted = 0;
|
protected $deleted = 0;
|
||||||
|
|
||||||
|
/** @var array $cache_lang use to cache texts in current language */
|
||||||
public static $cache_lang = array();
|
public static $cache_lang = array();
|
||||||
|
|
||||||
protected $is_cms = false;
|
protected $is_cms = false;
|
||||||
@@ -161,7 +162,8 @@ class HelperListCore extends Helper
|
|||||||
sort($positions);
|
sort($positions);
|
||||||
}
|
}
|
||||||
|
|
||||||
$key_to_get = 'id_'.($this->is_cms ? 'cms_' : '').'category'.(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;
|
||||||
|
|
||||||
$fields = array();
|
$fields = array();
|
||||||
|
|
||||||
@@ -235,11 +237,10 @@ class HelperListCore extends Helper
|
|||||||
else if (isset($params['icon']) && (isset($params['icon'][$tr[$key]]) || isset($params['icon']['default'])))
|
else if (isset($params['icon']) && (isset($params['icon'][$tr[$key]]) || isset($params['icon']['default'])))
|
||||||
$this->_list[$index][$key] = isset($params['icon'][$tr[$key]]) ? $params['icon'][$tr[$key]] : $params['icon']['default'];
|
$this->_list[$index][$key] = isset($params['icon'][$tr[$key]]) ? $params['icon'][$tr[$key]] : $params['icon']['default'];
|
||||||
else if (isset($params['price']))
|
else if (isset($params['price']))
|
||||||
$this->_list[$index][$key] = Tools::displayPrice($tr[$key], (isset($params['currency'])
|
{
|
||||||
?
|
$currency = isset($params['currency']) ? Currency::getCurrencyInstance($tr['id_currency']) : $this->context->currency;
|
||||||
Currency::getCurrencyInstance($tr['id_currency'])
|
$this->_list[$index][$key] = Tools::displayPrice($tr[$key], ($currency), false);
|
||||||
:
|
}
|
||||||
$this->context->currency), false);
|
|
||||||
else if (isset($params['float']))
|
else if (isset($params['float']))
|
||||||
$this->_list[$index][$key] = rtrim(rtrim($tr[$key], '0'), '.');
|
$this->_list[$index][$key] = rtrim(rtrim($tr[$key], '0'), '.');
|
||||||
else if (isset($params['type']) && $params['type'] == 'date')
|
else if (isset($params['type']) && $params['type'] == 'date')
|
||||||
@@ -291,6 +292,9 @@ class HelperListCore extends Helper
|
|||||||
return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/list_content.tpl');
|
return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/list_content.tpl');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display duplicate action link
|
||||||
|
*/
|
||||||
protected function _displayDuplicateLink($token = null, $id)
|
protected function _displayDuplicateLink($token = null, $id)
|
||||||
{
|
{
|
||||||
if (!array_key_exists('Duplicate', self::$cache_lang))
|
if (!array_key_exists('Duplicate', self::$cache_lang))
|
||||||
@@ -310,9 +314,11 @@ class HelperListCore extends Helper
|
|||||||
));
|
));
|
||||||
|
|
||||||
return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/list_action_duplicate.tpl');
|
return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/list_action_duplicate.tpl');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display view action link
|
||||||
|
*/
|
||||||
protected function _displayViewLink($token = null, $id)
|
protected function _displayViewLink($token = null, $id)
|
||||||
{
|
{
|
||||||
if (!array_key_exists('View', self::$cache_lang))
|
if (!array_key_exists('View', self::$cache_lang))
|
||||||
@@ -327,6 +333,9 @@ class HelperListCore extends Helper
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display edit action link
|
||||||
|
*/
|
||||||
protected function _displayEditLink($token = null, $id)
|
protected function _displayEditLink($token = null, $id)
|
||||||
{
|
{
|
||||||
if (!array_key_exists('Edit', self::$cache_lang))
|
if (!array_key_exists('Edit', self::$cache_lang))
|
||||||
@@ -341,6 +350,9 @@ class HelperListCore extends Helper
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display delete action link
|
||||||
|
*/
|
||||||
protected function _displayDeleteLink($token = null, $id)
|
protected function _displayDeleteLink($token = null, $id)
|
||||||
{
|
{
|
||||||
if (!array_key_exists('Delete', self::$cache_lang))
|
if (!array_key_exists('Delete', self::$cache_lang))
|
||||||
@@ -370,23 +382,21 @@ class HelperListCore extends Helper
|
|||||||
$token = $this->token;
|
$token = $this->token;
|
||||||
|
|
||||||
/* Determine total page number */
|
/* Determine total page number */
|
||||||
$total_pages = ceil($this->_listTotal / Tools::getValue('pagination', (isset($this->context->cookie->{$this->table.'_pagination'})
|
if (isset($this->context->cookie->{$this->table.'_pagination'}))
|
||||||
?
|
$default_pagination = $this->context->cookie->{$this->table.'_pagination'};
|
||||||
$this->context->cookie->{$this->table.'_pagination'}
|
else
|
||||||
:
|
$default_pagination = $this->_pagination[0];
|
||||||
$this->_pagination[0])));
|
|
||||||
|
$total_pages = ceil($this->_listTotal / Tools::getValue('pagination', ($default_pagination)));
|
||||||
|
|
||||||
if (!$total_pages) $total_pages = 1;
|
if (!$total_pages) $total_pages = 1;
|
||||||
|
|
||||||
$action = $this->currentIndex
|
$identifier = Tools::getIsset($this->identifier) ? '&'.$this->identifier.'='.(int)Tools::getValue($this->identifier) : '';
|
||||||
.(Tools::getIsset($this->identifier)
|
$order = '';
|
||||||
? '&'.$this->identifier.'='.(int)Tools::getValue($this->identifier)
|
if (Tools::getIsset($this->table.'Orderby'))
|
||||||
: '')
|
$order = '&'.$this->table.'Orderby='.urlencode($this->_orderBy).'&'.$this->table.'Orderway='.urlencode(strtolower($this->_orderWay));
|
||||||
.'&token='.$token
|
|
||||||
.(Tools::getIsset($this->table.'Orderby')
|
$action = $this->currentIndex.$identifier.'&token='.$token.$order.'#'.$this->table;
|
||||||
? '&'.$this->table.'Orderby='.urlencode($this->_orderBy).'&'.$this->table.'Orderway='.urlencode(strtolower($this->_orderWay))
|
|
||||||
: '')
|
|
||||||
.'#'.$this->table;
|
|
||||||
|
|
||||||
/* Determine current page number */
|
/* Determine current page number */
|
||||||
$page = (int)Tools::getValue('submitFilter'.$this->table);
|
$page = (int)Tools::getValue('submitFilter'.$this->table);
|
||||||
@@ -499,4 +509,5 @@ class HelperListCore extends Helper
|
|||||||
));
|
));
|
||||||
return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/list_footer.tpl');
|
return $this->context->smarty->fetch(_PS_ADMIN_DIR_.'/themes/template/list_footer.tpl');
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user