[*] Bo : removed empty filters from the cookie (thus limiting its size)

This commit is contained in:
Damien Metzger
2013-12-03 11:44:51 +01:00
parent 8a72e4d810
commit de456e45ec
4 changed files with 55 additions and 41 deletions
+1 -1
View File
@@ -116,7 +116,7 @@ abstract class AdminTabCore
protected $_tmpTableFilter = ''; protected $_tmpTableFilter = '';
/** @var array Number of results in list per page (used in select field) */ /** @var array Number of results in list per page (used in select field) */
protected $_pagination = array(20, 50, 100, 300); protected $_pagination = array(20, 50, 100, 300, 1000);
/** @var string ORDER BY clause determined by field/arrows in list header */ /** @var string ORDER BY clause determined by field/arrows in list header */
protected $_orderBy; protected $_orderBy;
+42 -29
View File
@@ -150,7 +150,10 @@ class AdminControllerCore extends Controller
protected $_tmpTableFilter = ''; protected $_tmpTableFilter = '';
/** @var array Number of results in list per page (used in select field) */ /** @var array Number of results in list per page (used in select field) */
protected $_pagination = array(20, 50, 100, 300); protected $_pagination = array(20, 50, 100, 300, 1000);
/** @var integer Default number of results in list per page */
protected $_default_pagination = 50;
/** @var string ORDER BY clause determined by field/arrows in list header */ /** @var string ORDER BY clause determined by field/arrows in list header */
protected $_orderBy; protected $_orderBy;
@@ -497,20 +500,35 @@ class AdminControllerCore extends Controller
$this->list_id = $this->table; $this->list_id = $this->table;
$prefix = str_replace(array('admin', 'controller'), '', Tools::strtolower(get_class($this))); $prefix = str_replace(array('admin', 'controller'), '', Tools::strtolower(get_class($this)));
// Filter memorization
if (isset($_POST) && !empty($_POST) && isset($this->list_id)) if (isset($this->list_id))
{
foreach ($_POST as $key => $value) foreach ($_POST as $key => $value)
{ {
if (stripos($key, $this->list_id.'Filter_') === 0) if (empty($value))
unset($this->context->cookie->{$prefix.$key});
elseif (stripos($key, $this->list_id.'Filter_') === 0)
$this->context->cookie->{$prefix.$key} = !is_array($value) ? $value : serialize($value); $this->context->cookie->{$prefix.$key} = !is_array($value) ? $value : serialize($value);
elseif(stripos($key, 'submitFilter') === 0) elseif (stripos($key, 'submitFilter') === 0)
$this->context->cookie->$key = !is_array($value) ? $value : serialize($value); $this->context->cookie->$key = !is_array($value) ? $value : serialize($value);
} }
if (isset($_GET) && !empty($_GET) && isset($this->list_id))
foreach ($_GET as $key => $value) foreach ($_GET as $key => $value)
if (stripos($key, $this->list_id.'OrderBy') === 0 || stripos($key, $this->list_id.'Orderway') === 0) if (stripos($key, $this->list_id.'OrderBy') === 0)
$this->context->cookie->{$prefix.$key} = $value; {
if (empty($value) || $value == $this->_defaultOrderBy)
unset($this->context->cookie->{$prefix.$key});
else
$this->context->cookie->{$prefix.$key} = $value;
}
elseif (stripos($key, $this->list_id.'Orderway') === 0)
{
if (empty($value) || $value == $this->_defaultOrderWay)
unset($this->context->cookie->{$prefix.$key});
else
$this->context->cookie->{$prefix.$key} = $value;
}
}
$filters = $this->context->cookie->getFamily($prefix.$this->list_id.'Filter_'); $filters = $this->context->cookie->getFamily($prefix.$this->list_id.'Filter_');
@@ -959,32 +977,28 @@ class AdminControllerCore extends Controller
*/ */
public function processResetFilters($list_id = null) public function processResetFilters($list_id = null)
{ {
if (!isset($list_id)) if ($list_id === null)
$list_id = isset($this->list_id) ? $this->list_id : $this->table; $list_id = isset($this->list_id) ? $this->list_id : $this->table;
$prefix = str_replace(array('admin', 'controller'), '', Tools::strtolower(get_class($this))); $prefix = str_replace(array('admin', 'controller'), '', Tools::strtolower(get_class($this)));
$filters = $this->context->cookie->getFamily($prefix.$list_id.'Filter_'); $filters = $this->context->cookie->getFamily($prefix.$list_id.'Filter_');
foreach ($filters as $cookie_key => $filter) foreach ($filters as $cookie_key => $filter)
if (strncmp($cookie_key, $prefix.$list_id.'Filter_', 7 + Tools::strlen($prefix.$list_id)) == 0) if (strncmp($cookie_key, $prefix.$list_id.'Filter_', 7 + Tools::strlen($prefix.$list_id)) == 0)
{ {
$key = substr($cookie_key, 7 + Tools::strlen($prefix.$list_id)); $key = substr($cookie_key, 7 + Tools::strlen($prefix.$list_id));
if (is_array($this->fields_list) && array_key_exists($key, $this->fields_list)) if (is_array($this->fields_list) && array_key_exists($key, $this->fields_list))
$this->context->cookie->$cookie_key = null; $this->context->cookie->$cookie_key = null;
unset($this->context->cookie->$cookie_key); unset($this->context->cookie->$cookie_key);
} }
if (isset($this->context->cookie->{'submitFilter'.$list_id})) if (isset($this->context->cookie->{'submitFilter'.$list_id}))
unset($this->context->cookie->{'submitFilter'.$list_id}); unset($this->context->cookie->{'submitFilter'.$list_id});
if (isset($this->context->cookie->{$prefix.$list_id.'Orderby'})) if (isset($this->context->cookie->{$prefix.$list_id.'Orderby'}))
unset($this->context->cookie->{$prefix.$list_id.'Orderby'}); unset($this->context->cookie->{$prefix.$list_id.'Orderby'});
if (isset($this->context->cookie->{$prefix.$list_id.'Orderway'})) if (isset($this->context->cookie->{$prefix.$list_id.'Orderway'}))
unset($this->context->cookie->{$prefix.$list_id.'Orderway'}); unset($this->context->cookie->{$prefix.$list_id.'Orderway'});
unset($_POST); $_POST = array();
$this->_filter = false; $this->_filter = false;
unset($this->_filterHaving); unset($this->_filterHaving);
unset($this->_having); unset($this->_having);
@@ -2374,7 +2388,7 @@ class AdminControllerCore extends Controller
if (isset($this->context->cookie->{$this->list_id.'_pagination'}) && $this->context->cookie->{$this->list_id.'_pagination'}) if (isset($this->context->cookie->{$this->list_id.'_pagination'}) && $this->context->cookie->{$this->list_id.'_pagination'})
$limit = $this->context->cookie->{$this->list_id.'_pagination'}; $limit = $this->context->cookie->{$this->list_id.'_pagination'};
else else
$limit = $this->_pagination[1]; $limit = $this->_default_pagination;
} }
if (!Validate::isTableOrIdentifier($this->table)) if (!Validate::isTableOrIdentifier($this->table))
@@ -2401,7 +2415,10 @@ class AdminControllerCore extends Controller
} }
$limit = (int)Tools::getValue($this->list_id.'_pagination', $limit); $limit = (int)Tools::getValue($this->list_id.'_pagination', $limit);
$this->context->cookie->{$this->list_id.'_pagination'} = $limit; if (in_array($limit, $this->_pagination) && $limit != $this->_default_pagination)
$this->context->cookie->{$this->list_id.'_pagination'} = $limit;
else
unset($this->context->cookie->{$this->list_id.'_pagination'});
/* Check params validity */ /* Check params validity */
if (!Validate::isOrderBy($order_by) || !Validate::isOrderWay($order_way) if (!Validate::isOrderBy($order_by) || !Validate::isOrderWay($order_way)
@@ -2416,20 +2433,17 @@ class AdminControllerCore extends Controller
$order_by = $this->fields_list[$order_by]['order_key']; $order_by = $this->fields_list[$order_by]['order_key'];
/* Determine offset from current page */ /* Determine offset from current page */
$start = 0;
if ((int)Tools::getValue('submitFilter'.$this->list_id))
if ((isset($_POST['submitFilter'.$this->list_id]) || $start = ((int)Tools::getValue('submitFilter'.$this->list_id) - 1) * $limit;
isset($_POST['submitFilter'.$this->list_id.'_x']) ||
isset($_POST['submitFilter'.$this->list_id.'_y'])) &&
!empty($_POST['submitFilter'.$this->list_id]) &&
is_numeric($_POST['submitFilter'.$this->list_id]))
$start = ((int)$_POST['submitFilter'.$this->list_id] - 1) * $limit;
elseif (empty($start) && isset($this->context->cookie->{$this->list_id.'_start'}) && Tools::isSubmit('export'.$this->table)) elseif (empty($start) && isset($this->context->cookie->{$this->list_id.'_start'}) && Tools::isSubmit('export'.$this->table))
$start = $this->context->cookie->{$this->list_id.'_start'}; $start = $this->context->cookie->{$this->list_id.'_start'};
else
$start = 0;
$this->context->cookie->{$this->list_id.'_start'} = $start; // Either save or reset the offset in the cookie
if ($start)
$this->context->cookie->{$this->list_id.'_start'} = $start;
elseif (isset($this->context->cookie->{$this->list_id.'_start'}))
unset($this->context->cookie->{$this->list_id.'_start'});
/* Cache */ /* Cache */
$this->_lang = (int)$id_lang; $this->_lang = (int)$id_lang;
@@ -2549,7 +2563,6 @@ class AdminControllerCore extends Controller
'list' => &$this->_list, 'list' => &$this->_list,
'list_total' => &$this->_listTotal, 'list_total' => &$this->_listTotal,
)); ));
} }
public function getModulesList($filter_modules_list) public function getModulesList($filter_modules_list)
+11 -10
View File
@@ -39,7 +39,10 @@ class HelperListCore extends Helper
protected $_filter; protected $_filter;
/** @var array Number of results in list per page (used in select field) */ /** @var array Number of results in list per page (used in select field) */
protected $_pagination = array(20, 50, 100, 300); protected $_pagination = array(20, 50, 100, 300, 1000);
/** @var integer Default number of results in list per page */
protected $_default_pagination = 50;
/** @var string ORDER BY clause determined by field/arrows in list header */ /** @var string ORDER BY clause determined by field/arrows in list header */
public $orderBy; public $orderBy;
@@ -511,15 +514,13 @@ class HelperListCore extends Helper
$token = $this->token; $token = $this->token;
/* Determine total page number */ /* Determine total page number */
if (isset($this->context->cookie->{$this->list_id.'_pagination'}) && $this->context->cookie->{$this->list_id.'_pagination'}) $pagination = $this->_default_pagination;
$default_pagination = $this->context->cookie->{$this->list_id.'_pagination'}; if (in_array((int)Tools::getValue($this->list_id.'_pagination'), $this->_pagination))
else $pagination = (int)Tools::getValue($this->list_id.'_pagination');
$default_pagination = $this->_pagination[0]; elseif (isset($this->context->cookie->{$this->list_id.'_pagination'}) && $this->context->cookie->{$this->list_id.'_pagination'})
$pagination = $this->context->cookie->{$this->list_id.'_pagination'};
$total_pages = ceil($this->listTotal / Tools::getValue($this->list_id.'_pagination', ($default_pagination))); $total_pages = max(1, ceil($this->listTotal / $pagination));
if (!$total_pages)
$total_pages = 1;
$identifier = Tools::getIsset($this->identifier) ? '&'.$this->identifier.'='.(int)Tools::getValue($this->identifier) : ''; $identifier = Tools::getIsset($this->identifier) ? '&'.$this->identifier.'='.(int)Tools::getValue($this->identifier) : '';
$order = ''; $order = '';
@@ -535,7 +536,7 @@ class HelperListCore extends Helper
/* Choose number of results per page */ /* Choose number of results per page */
$selected_pagination = Tools::getValue($this->list_id.'_pagination', $selected_pagination = Tools::getValue($this->list_id.'_pagination',
isset($this->context->cookie->{$this->list_id.'_pagination'}) ? $this->context->cookie->{$this->list_id.'_pagination'} : null isset($this->context->cookie->{$this->list_id.'_pagination'}) ? $this->context->cookie->{$this->list_id.'_pagination'} : $this->_default_pagination
); );
if (!isset($this->table_id) && $this->position_identifier && (int)Tools::getValue($this->position_identifier, 1)) if (!isset($this->table_id) && $this->position_identifier && (int)Tools::getValue($this->position_identifier, 1))
+1 -1
View File
@@ -142,7 +142,7 @@ class CompareControllerCore extends FrontController
)); ));
$this->context->smarty->assign('HOOK_EXTRA_PRODUCT_COMPARISON', Hook::exec('displayProductComparison', array('list_ids_product' => $ids))); $this->context->smarty->assign('HOOK_EXTRA_PRODUCT_COMPARISON', Hook::exec('displayProductComparison', array('list_ids_product' => $ids)));
} }
else if (isset($this->context->cookie->id_compare)) elseif (isset($this->context->cookie->id_compare))
{ {
$object = new CompareProduct((int)$this->context->cookie->id_compare); $object = new CompareProduct((int)$this->context->cookie->id_compare);
if (Validate::isLoadedObject($object)) if (Validate::isLoadedObject($object))