[*] BO: you can now export listing of some tabs in CSV

This commit is contained in:
Rémi Gaillard
2013-02-13 16:15:37 +01:00
parent cc1ff8ef0f
commit e3e38b19e1
8 changed files with 63 additions and 13 deletions
+45
View File
@@ -170,6 +170,8 @@ class AdminControllerCore extends Controller
/** @var bool boolean List content lines are clickable if true */ /** @var bool boolean List content lines are clickable if true */
protected $list_no_link = false; protected $list_no_link = false;
protected $allow_export = false;
/** @var array $cache_lang cache for traduction */ /** @var array $cache_lang cache for traduction */
public static $cache_lang = array(); public static $cache_lang = array();
@@ -565,6 +567,39 @@ class AdminControllerCore extends Controller
return $object; return $object;
} }
public function processExport()
{
// clean buffer
ob_clean();
$this->getList($this->context->language->id);
if (!count($this->_list))
return;
header('Content-type: text/csv');
header('Content-Type: application/force-download; charset=UTF-8');
header('Cache-Control: no-store, no-cache');
header('Content-disposition: attachment; filename="'.$this->table.'_'.date('Y-m-d_His').'.csv"');
$headers = array();
foreach ($this->fields_list as $datas)
$headers[] = $datas['title'];
$content = array();
foreach ($this->_list as $i => $row)
{
$content[$i] = array();
foreach ($this->fields_list as $key => $value)
$content[$i][] = $row[$key];
}
$this->context->smarty->assign(array(
'export_headers' => $headers,
'export_content' => $content
)
);
$this->layout = 'layout-export.tpl';
}
/** /**
* Object Delete * Object Delete
*/ */
@@ -1025,6 +1060,11 @@ class AdminControllerCore extends Controller
'href' => self::$currentIndex.'&add'.$this->table.'&token='.$this->token, 'href' => self::$currentIndex.'&add'.$this->table.'&token='.$this->token,
'desc' => $this->l('Add new') 'desc' => $this->l('Add new')
); );
if ($this->allow_export)
$this->toolbar_btn['export'] = array(
'href' => self::$currentIndex.'&export'.$this->table.'&token='.$this->token,
'desc' => $this->l('Export')
);
} }
$this->addToolBarModulesListButton(); $this->addToolBarModulesListButton();
} }
@@ -1929,6 +1969,11 @@ class AdminControllerCore extends Controller
else else
$this->errors[] = Tools::displayError('You do not have permission to view here.'); $this->errors[] = Tools::displayError('You do not have permission to view here.');
} }
elseif (isset($_GET['export'.$this->table]))
{
if ($this->tabAccess['view'] === '1')
$this->action = 'export';
}
/* Cancel all filters for this tab */ /* Cancel all filters for this tab */
elseif (isset($_POST['submitReset'.$this->table])) elseif (isset($_POST['submitReset'.$this->table]))
$this->action = 'reset_filters'; $this->action = 'reset_filters';
+9 -12
View File
@@ -44,6 +44,8 @@ class AdminAddressesControllerCore extends AdminController
$this->addRowAction('delete'); $this->addRowAction('delete');
$this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'))); $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?')));
$this->allow_export = true;
if (!Tools::getValue('realedit')) if (!Tools::getValue('realedit'))
$this->deleted = true; $this->deleted = true;
@@ -61,6 +63,13 @@ class AdminAddressesControllerCore extends AdminController
'country' => array('title' => $this->l('Country'), 'width' => 100, 'type' => 'select', 'list' => $this->countries_array, 'filter_key' => 'cl!id_country')); 'country' => array('title' => $this->l('Country'), 'width' => 100, 'type' => 'select', 'list' => $this->countries_array, 'filter_key' => 'cl!id_country'));
parent::__construct(); parent::__construct();
$this->_select = 'cl.`name` as country';
$this->_join = '
LEFT JOIN `'._DB_PREFIX_.'country_lang` cl ON (cl.`id_country` = a.`id_country` AND cl.`id_lang` = '.(int)$this->context->language->id.')
LEFT JOIN `'._DB_PREFIX_.'customer` c ON a.id_customer = c.id_customer
';
$this->_where = 'AND a.id_customer != 0 '.Shop::addSqlRestriction(Shop::SHARE_CUSTOMER, 'c');
} }
public function initToolbar() public function initToolbar()
@@ -72,18 +81,6 @@ class AdminAddressesControllerCore extends AdminController
); );
} }
public function renderList()
{
$this->_select = 'cl.`name` as country';
$this->_join = '
LEFT JOIN `'._DB_PREFIX_.'country_lang` cl ON (cl.`id_country` = a.`id_country` AND cl.`id_lang` = '.(int)$this->context->language->id.')
LEFT JOIN `'._DB_PREFIX_.'customer` c ON a.id_customer = c.id_customer
';
$this->_where = 'AND a.id_customer != 0 '.Shop::addSqlRestriction(Shop::SHARE_CUSTOMER, 'c');
return parent::renderList();
}
public function renderForm() public function renderForm()
{ {
$this->fields_form = array( $this->fields_form = array(
@@ -35,6 +35,7 @@ class AdminCartsControllerCore extends AdminController
$this->addRowAction('view'); $this->addRowAction('view');
$this->addRowAction('delete'); $this->addRowAction('delete');
$this->allow_export = true;
$this->_select = 'CONCAT(LEFT(c.`firstname`, 1), \'. \', c.`lastname`) `customer`, a.id_cart total, ca.name carrier, o.id_order, IF(co.id_guest, 1, 0) id_guest'; $this->_select = 'CONCAT(LEFT(c.`firstname`, 1), \'. \', c.`lastname`) `customer`, a.id_cart total, ca.name carrier, o.id_order, IF(co.id_guest, 1, 0) id_guest';
$this->_join = 'LEFT JOIN '._DB_PREFIX_.'customer c ON (c.id_customer = a.id_customer) $this->_join = 'LEFT JOIN '._DB_PREFIX_.'customer c ON (c.id_customer = a.id_customer)
@@ -45,6 +45,7 @@ class AdminCategoriesControllerCore extends AdminController
$this->lang = true; $this->lang = true;
$this->deleted = false; $this->deleted = false;
$this->explicitSelect = true; $this->explicitSelect = true;
$this->allow_export = true;
$this->context = Context::getContext(); $this->context = Context::getContext();
@@ -42,6 +42,8 @@ class AdminCustomersControllerCore extends AdminController
$this->deleted = true; $this->deleted = true;
$this->explicitSelect = true; $this->explicitSelect = true;
$this->allow_export = true;
$this->addRowAction('edit'); $this->addRowAction('edit');
$this->addRowAction('view'); $this->addRowAction('view');
$this->addRowAction('delete'); $this->addRowAction('delete');
@@ -35,6 +35,7 @@ class AdminManufacturersControllerCore extends AdminController
$this->className = 'Manufacturer'; $this->className = 'Manufacturer';
$this->lang = false; $this->lang = false;
$this->deleted = false; $this->deleted = false;
$this->allow_export = true;
$this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'))); $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?')));
@@ -71,6 +71,7 @@ class AdminProductsControllerCore extends AdminController
$this->_defaultOrderBy = 'position'; $this->_defaultOrderBy = 'position';
$this->max_file_size = (int)(Configuration::get('PS_LIMIT_UPLOAD_FILE_VALUE') * 1000000); $this->max_file_size = (int)(Configuration::get('PS_LIMIT_UPLOAD_FILE_VALUE') * 1000000);
$this->max_image_size = (int)Configuration::get('PS_PRODUCT_PICTURE_MAX_SIZE'); $this->max_image_size = (int)Configuration::get('PS_PRODUCT_PICTURE_MAX_SIZE');
$this->allow_export = true;
// @since 1.5 : translations for tabs // @since 1.5 : translations for tabs
$this->available_tabs_lang = array ( $this->available_tabs_lang = array (
@@ -34,6 +34,8 @@ class AdminSuppliersControllerCore extends AdminController
$this->addRowAction('view'); $this->addRowAction('view');
$this->addRowAction('edit'); $this->addRowAction('edit');
$this->addRowAction('delete'); $this->addRowAction('delete');
$this->allow_export = true;
$this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'))); $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?')));
$this->_select = 'COUNT(DISTINCT ps.`id_product`) AS products'; $this->_select = 'COUNT(DISTINCT ps.`id_product`) AS products';