Skip to content

Commit

Permalink
// Fix #PSCFV-4512
Browse files Browse the repository at this point in the history
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@17751 b9a71923-0436-4b27-9f14-aed3839534dd
  • Loading branch information
rGaillard committed Oct 4, 2012
1 parent f90f801 commit 55a1ad4
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 56 deletions.
56 changes: 28 additions & 28 deletions classes/controller/AdminController.php
Expand Up @@ -417,6 +417,33 @@ public function ajaxProcessHelpAccess()
*/
public function processFilter()
{
// Filter memorization
if (isset($_POST) && !empty($_POST) && isset($this->table))
foreach ($_POST as $key => $value)
{
if (is_array($this->table))
{
foreach ($this->table as $table)
if (stripos($key, $table.'Filter_') === 0 || stripos($key, 'submitFilter') === 0)
$this->context->cookie->$key = !is_array($value) ? $value : serialize($value);
}
elseif (stripos($key, $this->table.'Filter_') === 0 || stripos($key, 'submitFilter') === 0)
$this->context->cookie->$key = !is_array($value) ? $value : serialize($value);
}

if (isset($_GET) && !empty($_GET) && isset($this->table))
foreach ($_GET as $key => $value)
{
if (is_array($this->table))
{
foreach ($this->table as $table)
if (stripos($key, $table.'OrderBy') === 0 || stripos($key, $table.'Orderway') === 0)
$this->context->cookie->$key = $value;
}
elseif (stripos($key, $this->table.'OrderBy') === 0 || stripos($key, $this->table.'Orderway') === 0)
$this->context->cookie->$key = $value;
}

$filters = $this->context->cookie->getFamily($this->table.'Filter_');

foreach ($filters as $key => $value)
Expand Down Expand Up @@ -808,7 +835,6 @@ public function processPosition()
public function processResetFilters()
{
$filters = $this->context->cookie->getFamily($this->table.'Filter_');

foreach ($filters as $cookie_key => $filter)
if (strncmp($cookie_key, $this->table.'Filter_', 7 + Tools::strlen($this->table)) == 0)
{
Expand All @@ -817,7 +843,7 @@ public function processResetFilters()
$tmp_tab = explode('!', $key);
$key = (count($tmp_tab) > 1 ? $tmp_tab[1] : $tmp_tab[0]);

if (array_key_exists($key, $this->fields_list))
if (is_array($this->fields_list) && array_key_exists($key, $this->fields_list))
unset($this->context->cookie->$cookie_key);
}

Expand Down Expand Up @@ -1763,32 +1789,6 @@ public function initShopContext()
*/
public function initProcess()
{
// Filter memorization
if (isset($_POST) && !empty($_POST) && isset($this->table))
foreach ($_POST as $key => $value)
{
if (is_array($this->table))
{
foreach ($this->table as $table)
if (stripos($key, $table.'Filter_') === 0 || stripos($key, 'submitFilter') === 0)
$this->context->cookie->$key = !is_array($value) ? $value : serialize($value);
}
elseif (stripos($key, $this->table.'Filter_') === 0 || stripos($key, 'submitFilter') === 0)
$this->context->cookie->$key = !is_array($value) ? $value : serialize($value);
}
if (isset($_GET) && !empty($_GET) && isset($this->table))
foreach ($_GET as $key => $value)
{
if (is_array($this->table))
{
foreach ($this->table as $table)
if (stripos($key, $table.'OrderBy') === 0 || stripos($key, $table.'Orderway') === 0)
$this->context->cookie->$key = $value;
}
elseif (stripos($key, $this->table.'OrderBy') === 0 || stripos($key, $this->table.'Orderway') === 0)
$this->context->cookie->$key = $value;
}

// Manage list filtering
if (Tools::isSubmit('submitFilter'.$this->table) || $this->context->cookie->{'submitFilter'.$this->table} !== false)
$this->filter = true;
Expand Down
14 changes: 7 additions & 7 deletions classes/helper/HelperList.php
Expand Up @@ -161,7 +161,7 @@ public function generateList($list, $fields_display)
* @param int $id_product
* @return string
*/
protected function displayEnableLink($token, $id, $value, $active, $id_category = null, $id_product = null)
public function displayEnableLink($token, $id, $value, $active, $id_category = null, $id_product = null)
{
$tpl_enable = $this->createTemplate('list_action_enable.tpl');
$tpl_enable->assign(array(
Expand Down Expand Up @@ -332,7 +332,7 @@ public function displayListContent()
/**
* Display duplicate action link
*/
protected function displayDuplicateLink($token = null, $id, $name = null)
public function displayDuplicateLink($token = null, $id, $name = null)
{
$tpl = $this->createTemplate('list_action_duplicate.tpl');
if (!array_key_exists('Bad SQL query', self::$cache_lang))
Expand Down Expand Up @@ -374,7 +374,7 @@ protected function displayDuplicateLink($token = null, $id, $name = null)
* fields_display: // attribute $fields_list of the admin controller
* }
*/
protected function displayDetailsLink($token = null, $id, $name = null)
public function displayDetailsLink($token = null, $id, $name = null)
{
$tpl = $this->createTemplate('list_action_details.tpl');
if (!array_key_exists('Details', self::$cache_lang))
Expand All @@ -398,7 +398,7 @@ protected function displayDetailsLink($token = null, $id, $name = null)
/**
* Display view action link
*/
protected function displayViewLink($token = null, $id, $name = null)
public function displayViewLink($token = null, $id, $name = null)
{
$tpl = $this->createTemplate('list_action_view.tpl');
if (!array_key_exists('View', self::$cache_lang))
Expand All @@ -416,7 +416,7 @@ protected function displayViewLink($token = null, $id, $name = null)
/**
* Display edit action link
*/
protected function displayEditLink($token = null, $id, $name = null)
public function displayEditLink($token = null, $id, $name = null)
{
$tpl = $this->createTemplate('list_action_edit.tpl');
if (!array_key_exists('Edit', self::$cache_lang))
Expand All @@ -434,7 +434,7 @@ protected function displayEditLink($token = null, $id, $name = null)
/**
* Display delete action link
*/
protected function displayDeleteLink($token = null, $id, $name = null)
public function displayDeleteLink($token = null, $id, $name = null)
{
$tpl = $this->createTemplate('list_action_delete.tpl');

Expand Down Expand Up @@ -467,7 +467,7 @@ protected function displayDeleteLink($token = null, $id, $name = null)
/**
* Display delete action link
*/
protected function displayDefaultLink($token = null, $id, $name = null)
public function displayDefaultLink($token = null, $id, $name = null)
{
$tpl = $this->createTemplate('list_action_default.tpl');
if (!array_key_exists('Default', self::$cache_lang))
Expand Down
106 changes: 85 additions & 21 deletions controllers/admin/AdminTrackingController.php
Expand Up @@ -27,6 +27,8 @@

class AdminTrackingControllerCore extends AdminController
{
protected $_helper_list;

public function postprocess()
{
if (Tools::getValue('id_product') && Tools::isSubmit('statusproduct'))
Expand All @@ -51,14 +53,21 @@ public function postprocess()

public function initContent()
{
$this->_helper_list = new HelperList();

if (!Configuration::get('PS_STOCK_MANAGEMENT'))
$this->warnings[] = $this->l('List of products without available quantities for sale are not displayed because stock management is disabled.');

$methods = get_class_methods($this);
$tpl_vars['arrayList'] = array();
foreach ($methods as $method_name)
if (preg_match('#getCustomList(.+)#', $method_name, $matches))
{
$this->clearListOptions();
$this->content .= call_user_func(array($this,$matches[0]));
}

$this->content .= $this->getCustomListProductsDisabled();

$this->context->smarty->assign(array(
'content' => $this->content,
Expand All @@ -68,14 +77,14 @@ public function initContent()

public function getCustomListCategoriesEmpty()
{
$this->clearListOptions();
$this->table = 'category';
$this->lang = true;
$this->className = 'Category';
$this->identifier = 'id_category';
$this->_orderBy = 'id_category';
$this->_orderWay = 'DESC';
self::$currentIndex = 'index.php?controller=AdminCategories';
$this->token = Tools::getAdminTokenLite('AdminCategories');
$this->_list_index = 'index.php?controller=AdminCategories';
$this->_list_token = Tools::getAdminTokenLite('AdminCategories');

$this->addRowAction('edit');
$this->addRowAction('delete');
Expand All @@ -85,7 +94,7 @@ public function getCustomListCategoriesEmpty()

$this->fields_list = (array(
'id_category' => array('title' => $this->l('ID'), 'width' => 50),
'name' => array('title' => $this->l('Name')),
'name' => array('title' => $this->l('Name'), 'filter_key' => 'b!name'),
'description' => array('title' => $this->l('Description')),
'active' => array('title' => $this->l('Status'), 'type' => 'bool', 'active' => 'status', 'width' => 50)
));
Expand All @@ -99,22 +108,24 @@ public function getCustomListCategoriesEmpty()

$this->tpl_list_vars = array('sub_title' => $this->l('List of empty categories:'));

return parent::renderList();
$this->clearFilters();

return $this->renderList();
}

public function getCustomListProductsAttributesNoStock()
{
if (!Configuration::get('PS_STOCK_MANAGEMENT'))
return;

$this->clearListOptions();
$this->table = 'product';
$this->lang = true;
$this->identifier = 'id_product';
$this->_orderBy = 'id_product';
$this->_orderWay = 'DESC';
self::$currentIndex = 'index.php?controller=AdminProducts';
$this->token = Tools::getAdminTokenLite('AdminProducts');
$this->className = 'Product';
$this->_list_index = 'index.php?controller=AdminProducts';
$this->_list_token = Tools::getAdminTokenLite('AdminProducts');
$this->show_toolbar = false;

$this->addRowAction('edit');
Expand All @@ -123,7 +134,7 @@ public function getCustomListProductsAttributesNoStock()
$this->fields_list = array(
'id_product' => array('title' => $this->l('ID'), 'width' => 50),
'reference' => array('title' => $this->l('Reference'), 'width' => 150),
'name' => array('title' => $this->l('Name')),
'name' => array('title' => $this->l('Name'), 'filter_key' => 'b!name'),
'active' => array('title' => $this->l('Status'), 'type' => 'bool', 'active' => 'status', 'width' => 50)
);
$this->_join = Shop::addSqlAssociation('product', 'a');
Expand All @@ -140,23 +151,25 @@ public function getCustomListProductsAttributesNoStock()

$this->tpl_list_vars = array('sub_title' => $this->l('List of products with attributes and without available quantities for sale:'));

return parent::renderList();
$this->clearFilters();

return $this->renderList();
}

public function getCustomListProductsNoStock()
{
{
if (!Configuration::get('PS_STOCK_MANAGEMENT'))
return;

$this->clearListOptions();
$this->table = 'product';
$this->className = 'Product';
$this->lang = true;
$this->identifier = 'id_product';
$this->_orderBy = 'id_product';
$this->_orderWay = 'DESC';
$this->show_toolbar = false;
self::$currentIndex = 'index.php?controller=AdminProducts';
$this->token = Tools::getAdminTokenLite('AdminProducts');
$this->_list_index = 'index.php?controller=AdminProducts';
$this->_list_token = Tools::getAdminTokenLite('AdminProducts');

$this->addRowAction('edit');
$this->addRowAction('delete');
Expand All @@ -180,36 +193,81 @@ public function getCustomListProductsNoStock()
)';

$this->tpl_list_vars = array('sub_title' => $this->l('List of products without attributes and without available quantities for sale:'));

return parent::renderList();

$this->clearFilters();

return $this->renderList();
}

public function getCustomListProductsDisabled()
{
$this->clearListOptions();
$this->table = 'product';
$this->className = 'Product';
$this->lang = true;
$this->identifier = 'id_product';
$this->_orderBy = 'id_product';
$this->_orderWay = 'DESC';
$this->_filter = 'AND a.`active` = 0';
$this->_filter = 'AND product_shop.`active` = 0';
$this->list_no_filter = true;
$this->tpl_list_vars = array('sub_title' => $this->l('List of disabled products:'));
$this->show_toolbar = false;
self::$currentIndex = 'index.php?controller=AdminProducts';
$this->token = Tools::getAdminTokenLite('AdminProducts');
$this->_list_index = 'index.php?controller=AdminProducts';
$this->_list_token = Tools::getAdminTokenLite('AdminProducts');

$this->addRowAction('edit');
$this->addRowAction('delete');

$this->fields_list = array(
'id_product' => array('title' => $this->l('ID'), 'width' => 50),
'reference' => array('title' => $this->l('Reference'), 'width' => 150),
'name' => array('title' => $this->l('Name'))
'name' => array('title' => $this->l('Name'), 'filter_key' => 'b!name')
);

$this->clearFilters();

$this->_join = Shop::addSqlAssociation('product', 'a');
return $this->renderList();
}


public function renderList()
{
$this->processFilter();
return parent::renderList();
}

public function displayEnableLink($token, $id, $value, $active, $id_category = null, $id_product = null)
{
$this->_helper_list->currentIndex = $this->_list_index;
$this->_helper_list->identifier = $this->identifier;
$this->_helper_list->table = $this->table;

return $this->_helper_list->displayEnableLink($this->_list_token, $id, $value, $active, $id_category, $id_product);
}

public function displayDeleteLink($token = null, $id, $name = null)
{
$this->_helper_list->currentIndex = $this->_list_index;
$this->_helper_list->identifier = $this->identifier;
$this->_helper_list->table = $this->table;

return $this->_helper_list->displayDeleteLink($this->_list_token, $id, $name);
}

public function displayEditLink($token = null, $id, $name = null)
{
$this->_helper_list->currentIndex = $this->_list_index;
$this->_helper_list->identifier = $this->identifier;
$this->_helper_list->table = $this->table;

return $this->_helper_list->displayEditLink($this->_list_token, $id, $name);
}

protected function clearFilters()
{
if ((Tools::isSubmit('submitResetcategory') && $this->table == 'category' ) || (Tools::isSubmit('submitResetproduct') && $this->table == 'product' ))
$this->processResetFilters();
}

public function clearListOptions()
{
Expand All @@ -221,8 +279,14 @@ public function clearListOptions()
$this->_orderWay = '';
$this->_filter = '';
$this->_group = '';
$this->_where = '';
$this->list_no_filter = true;
$this->list_title = $this->l('Product disabled');
}

public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = false)
{
parent::getList($id_lang, $order_by, $order_way, $start, $limit, Context::getContext()->shop->id);
}
}

0 comments on commit 55a1ad4

Please sign in to comment.