From e88b74c069a98a7870b53d8098d08ab410d5c5e2 Mon Sep 17 00:00:00 2001 From: "benoit.leulliette@gmail.com" Date: Tue, 8 Mar 2016 20:10:19 +0100 Subject: [PATCH] some code refactoring in the controllers --- .../BL/CustomGrid/Block/Grid/Grid.php | 6 +- .../CustomGrid/Block/Widget/Grid/Config.php | 2 +- .../BL/CustomGrid/Controller/Grid/Action.php | 66 +++++ .../CustomGrid/Model/Grid/Type/Abstract.php | 4 +- .../Blcg/Grid/EditorController.php | 2 +- .../Blcg/Grid/ExportController.php | 101 ++++++++ .../controllers/Blcg/Grid/MassController.php | 137 ++++++++++ .../Blcg/Grid/ProfileController.php | 41 +-- .../controllers/Blcg/GridController.php | 242 +----------------- .../Blcg/Options/SourceController.php | 4 +- 10 files changed, 322 insertions(+), 283 deletions(-) create mode 100644 app/code/community/BL/CustomGrid/controllers/Blcg/Grid/ExportController.php create mode 100644 app/code/community/BL/CustomGrid/controllers/Blcg/Grid/MassController.php diff --git a/app/code/community/BL/CustomGrid/Block/Grid/Grid.php b/app/code/community/BL/CustomGrid/Block/Grid/Grid.php index 5bb727e..06ff80a 100644 --- a/app/code/community/BL/CustomGrid/Block/Grid/Grid.php +++ b/app/code/community/BL/CustomGrid/Block/Grid/Grid.php @@ -226,7 +226,7 @@ protected function _prepareMassaction() 'mass_enable', array( 'label' => $this->__('Enable'), - 'url' => $this->getUrl('*/*/massEnable', array('_current' => true)), + 'url' => $this->getUrl('*/blcg_grid_mass/massEnable', array('_current' => true)), 'confirm' => $this->__('Are you sure?'), ) ) @@ -234,7 +234,7 @@ protected function _prepareMassaction() 'mass_disable', array( 'label' => $this->__('Disable'), - 'url' => $this->getUrl('*/*/massDisable', array('_current' => true)), + 'url' => $this->getUrl('*/blcg_grid_mass/massDisable', array('_current' => true)), 'confirm' => $this->__('Are you sure?'), ) ) @@ -242,7 +242,7 @@ protected function _prepareMassaction() 'mass_delete', array( 'label' => $this->__('Delete'), - 'url' => $this->getUrl('*/*/massDelete', array('_current' => true)), + 'url' => $this->getUrl('*/blcg_grid_mass/massDelete', array('_current' => true)), 'confirm' => $this->__('Are you sure?'), ) ); diff --git a/app/code/community/BL/CustomGrid/Block/Widget/Grid/Config.php b/app/code/community/BL/CustomGrid/Block/Widget/Grid/Config.php index d0f048e..4f27275 100644 --- a/app/code/community/BL/CustomGrid/Block/Widget/Grid/Config.php +++ b/app/code/community/BL/CustomGrid/Block/Widget/Grid/Config.php @@ -158,7 +158,7 @@ public function getDefaultParamsFormUrl() */ public function getExportFormUrl() { - return $this->getUrl('adminhtml/blcg_grid/exportForm', $this->getBaseUrlParams()); + return $this->getUrl('adminhtml/blcg_grid_export/form', $this->getBaseUrlParams()); } /** diff --git a/app/code/community/BL/CustomGrid/Controller/Grid/Action.php b/app/code/community/BL/CustomGrid/Controller/Grid/Action.php index 83da884..8d5dc36 100644 --- a/app/code/community/BL/CustomGrid/Controller/Grid/Action.php +++ b/app/code/community/BL/CustomGrid/Controller/Grid/Action.php @@ -249,6 +249,72 @@ protected function _initWindowFormLayout( return $this; } + /** + * Initialize the current grid model and profile, check the given permissions, + * then prepare the layout for the given window grid form type + * + * @param string $formType Form type + * @param array $formData Form data + * @param string|array $permissions Required user permission(s) + * @param bool $anyPermission Whether all the given permissions are required, or just any of them + * @param array $handles Layout handles + * @return BL_CustomGrid_Blcg_GridController + */ + protected function _prepareWindowGridFormLayout( + $formType, + array $formData, + $permissions = null, + $anyPermission = true, + array $handles = array('blcg_empty') + ) { + $this->_initWindowFormLayout( + 'adminhtml_blcg_grid_form_window_action', + 'adminhtml_blcg_grid_form_window_error', + 'blcg.grid.form_error', + $permissions, + $anyPermission, + $handles + ); + + if ($containerBlock = $this->getLayout()->getBlock('blcg.grid.form_container')) { + /** @var $containerBlock BL_CustomGrid_Block_Grid_Form_Container */ + $containerBlock->setFormData($formData)->setFormType($formType); + } + + return $this; + } + + /** + * Initialize the current grid model and profile, check the given permissions, + * then prepare the layout for the given profile action + * + * @param string $actionCode Profile action + * @param string|array $permissions Required user permission(s) + * @param bool $anyPermission Whether all the given permissions are required, or just one of them + * @return BL_CustomGrid_Blcg_Grid_ProfileController + */ + protected function _prepareWindowProfileFormLayout($actionCode, $permissions = null, $anyPermission = true) + { + $this->_initWindowFormLayout( + 'adminhtml_blcg_grid_profile_form_window_action', + 'adminhtml_blcg_grid_profile_form_window_error', + 'blcg.grid_profile.form_error', + $permissions, + $anyPermission + ); + + if (($gridProfile = Mage::registry('blcg_grid_profile')) + && ($containerBlock = $this->getLayout()->getBlock('blcg.grid_profile.form_container'))) { + /** + * @var BL_CustomGrid_Model_Grid_Profile $gridProfile + * @var BL_CustomGrid_Block_Grid_Profile_Form_Container $containerBlock + */ + $containerBlock->setProfileId($gridProfile->getId())->setActionCode($actionCode); + } + + return $this; + } + /** * Validate that one or more values were selected for a mass-action, * otherwise force a redirect to the index action diff --git a/app/code/community/BL/CustomGrid/Model/Grid/Type/Abstract.php b/app/code/community/BL/CustomGrid/Model/Grid/Type/Abstract.php index e34b86c..6dbe4aa 100644 --- a/app/code/community/BL/CustomGrid/Model/Grid/Type/Abstract.php +++ b/app/code/community/BL/CustomGrid/Model/Grid/Type/Abstract.php @@ -314,13 +314,13 @@ protected function _getExportTypes($blockType) return array( 'csv' => new BL_CustomGrid_Object( array( - 'route' => 'adminhtml/blcg_grid/exportCsv', + 'route' => 'adminhtml/blcg_grid_export/exportCsv', 'label' => $this->getBaseHelper()->__('CSV'), ) ), 'xml' => new BL_CustomGrid_Object( array( - 'route' => 'adminhtml/blcg_grid/exportExcel', + 'route' => 'adminhtml/blcg_grid_export/exportExcel', 'label' => $this->getBaseHelper()->__('Excel'), ) ), diff --git a/app/code/community/BL/CustomGrid/controllers/Blcg/Grid/EditorController.php b/app/code/community/BL/CustomGrid/controllers/Blcg/Grid/EditorController.php index eb96fc5..debe7cf 100644 --- a/app/code/community/BL/CustomGrid/controllers/Blcg/Grid/EditorController.php +++ b/app/code/community/BL/CustomGrid/controllers/Blcg/Grid/EditorController.php @@ -62,7 +62,7 @@ public function formAction() if (!$helper->isAjaxRequest() || ($formBlock instanceof Mage_Core_Block_Abstract)) { - $this->_prepareFormLayout($formBlock, $errorMessage); + $this->_prepareWindowProfileFormLayout($formBlock, $errorMessage); } elseif (!is_null($errorMessage)) { $this->_setActionErrorJsonResponse($errorMessage); } else { diff --git a/app/code/community/BL/CustomGrid/controllers/Blcg/Grid/ExportController.php b/app/code/community/BL/CustomGrid/controllers/Blcg/Grid/ExportController.php new file mode 100644 index 0000000..b75e18c --- /dev/null +++ b/app/code/community/BL/CustomGrid/controllers/Blcg/Grid/ExportController.php @@ -0,0 +1,101 @@ + + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + */ + +class BL_CustomGrid_Blcg_Grid_ExportController extends BL_CustomGrid_Controller_Grid_Action +{ + public function formAction() + { + $this->_prepareWindowGridFormLayout( + 'export', + array( + 'total_size' => $this->getRequest()->getParam('total_size'), + 'first_index' => $this->getRequest()->getParam('first_index'), + 'additional_params' => $this->getRequest()->getParam('additional_params', array()), + ), + BL_CustomGrid_Model_Grid_Sentry::ACTION_EXPORT_RESULTS + ); + $this->renderLayout(); + } + + /** + * Restore in the request the additional parameters from the given export config + * + * @param array $exportConfig Export config values + */ + protected function _restoreExportAdditionalParams(array $exportConfig) + { + if (isset($exportConfig['additional_params']) && is_array($exportConfig['additional_params'])) { + foreach ($exportConfig['additional_params'] as $key => $value) { + if (!$this->getRequest()->has($key)) { + $this->getRequest()->setParam($key, $value); + } + } + } + } + + /** + * Apply an export action for the given format and file name + * + * @param string $format Export format + * @param string $fileName Exported file name + */ + protected function _applyExportAction($format, $fileName) + { + try { + $gridModel = $this->_initGridModel(); + $this->_initGridProfile(); + + if (!is_array($config = $this->getRequest()->getParam('export'))) { + $config = null; + } + + $this->_restoreExportAdditionalParams($config); + + if ($format == 'csv') { + $exportOutput = $gridModel->getExporter()->exportToCsv($config); + } elseif ($format == 'xml') { + $exportOutput = $gridModel->getExporter()->exportToExcel($config); + } else { + $exportOutput = ''; + } + + $this->_prepareDownloadResponse($fileName, $exportOutput); + + } catch (Mage_Core_Exception $e) { + $this->_getSession()->addError($e->getMessage()); + $this->_redirectReferer(); + } catch (Exception $e) { + Mage::logException($e); + $this->_getSession()->addError($this->__('An error occurred while exporting grid results')); + $this->_redirectReferer(); + } + } + + public function exportCsvAction() + { + $this->_applyExportAction('csv', 'export.csv'); + } + + public function exportExcelAction() + { + $this->_applyExportAction('xml', 'export.xml'); + } + + protected function _isAllowed() + { + // Specific permissions are enforced by the models + return true; + } +} diff --git a/app/code/community/BL/CustomGrid/controllers/Blcg/Grid/MassController.php b/app/code/community/BL/CustomGrid/controllers/Blcg/Grid/MassController.php new file mode 100644 index 0000000..afd7811 --- /dev/null +++ b/app/code/community/BL/CustomGrid/controllers/Blcg/Grid/MassController.php @@ -0,0 +1,137 @@ + + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + */ + +class BL_CustomGrid_Blcg_Grid_MassController extends BL_CustomGrid_Controller_Grid_Action +{ + /** + * Apply a mass-action action with the given callback that will be used for each selected grid ID + * + * @param callback $callback Callback to use for each grid ID + * @param string $defaultErrorMessage Default error message to display if a non-Magento exception is caught + * @param string $successfulMessage Message that will be displayed with the number of successfully handled IDs + * @param string $permissionErrorsMessage Message that will be displayed with the number of IDs that could not be + * handled due to permission errors + */ + protected function _applyMassactionAction( + $callback, + $defaultErrorMessage, + $successfulMessage, + $permissionErrorsMessage + ) { + if (!$this->_validateMassActionValues('grid')) { + return; + } + + $gridsIds = $this->getRequest()->getParam('grid'); + $successfulCount = 0; + $permissionErrorsCount = 0; + + try { + foreach ($gridsIds as $gridId) { + try { + call_user_func($callback, $gridId); + ++$successfulCount; + } catch (BL_CustomGrid_Grid_Permission_Exception $e) { + ++$permissionErrorsCount; + } + } + } catch (Mage_Core_Exception $e) { + $this->_getSession()->addError($e->getMessage()); + } catch (Exception $e) { + Mage::logException($e); + $this->_getSession()->addError($this->__($defaultErrorMessage)); + } + + if ($successfulCount > 0) { + $this->_getSession()->addSuccess($this->__($successfulMessage, $successfulCount)); + } + if ($permissionErrorsCount > 0) { + $this->_getSession()->addError($this->__($permissionErrorsMessage, $permissionErrorsCount)); + } + + $this->getResponse()->setRedirect($this->getUrl('*/*/')); + } + + /** + * Disable the grid model corresponding to the ID + * + * @param int $gridId Grid model ID + */ + protected function _massDisableGrid($gridId) + { + /** @var $gridModel BL_CustomGrid_Model_Grid */ + $gridModel = Mage::getSingleton('customgrid/grid'); + $gridModel->load($gridId)->setDisabled(true)->save(); + } + + public function massDisableAction() + { + $this->_applyMassactionAction( + array($this, '_massDisableGrid'), + 'An error occurred while disabling a grid', + 'Total of %d grid(s) have been disabled', + 'You were not allowed to disable %d of the chosen grids' + ); + } + + /** + * Enable the grid model corresponding to the given ID + * + * @param int $gridId Grid model ID + */ + protected function _massEnableGrid($gridId) + { + /** @var $gridModel BL_CustomGrid_Model_Grid */ + $gridModel = Mage::getSingleton('customgrid/grid'); + $gridModel->load($gridId)->setDisabled(false)->save(); + } + + public function massEnableAction() + { + $this->_applyMassactionAction( + array($this, '_massEnableGrid'), + 'An error occurred while enabling a grid', + 'Total of %d grid(s) have been enabled', + 'You were not allowed to enable %d of the chosen grids' + ); + } + + /** + * Delete the grid model corresponding to the given ID + * + * @param int $gridId Grid model ID + */ + protected function _massDeleteGrid($gridId) + { + /** @var $gridModel BL_CustomGrid_Model_Grid */ + $gridModel = Mage::getSingleton('customgrid/grid'); + $gridModel->load($gridId)->delete(); + } + + public function massDeleteAction() + { + $this->_applyMassactionAction( + array($this, '_massDeleteGrid'), + 'An error occurred while deleting a grid', + 'Total of %d grid(s) have been deleted', + 'You were not allowed to delete %d of the chosen grids' + ); + } + + protected function _isAllowed() + { + return $this->_getAdminSession()->isAllowed('customgrid/administration/view_grids_list'); + } +} diff --git a/app/code/community/BL/CustomGrid/controllers/Blcg/Grid/ProfileController.php b/app/code/community/BL/CustomGrid/controllers/Blcg/Grid/ProfileController.php index 232273b..be7910a 100644 --- a/app/code/community/BL/CustomGrid/controllers/Blcg/Grid/ProfileController.php +++ b/app/code/community/BL/CustomGrid/controllers/Blcg/Grid/ProfileController.php @@ -20,37 +20,6 @@ protected function _setActionSuccessJsonResponse(array $actions = array()) return parent::_setActionSuccessJsonResponse(array('actions' => $actions)); } - /** - * Initialize the current grid model and profile, check the given permissions, - * then prepare the layout for the given profile action - * - * @param string $actionCode Profile action - * @param string|array $permissions Required user permission(s) - * @param bool $anyPermission Whether all the given permissions are required, or just one of them - * @return BL_CustomGrid_Blcg_Grid_ProfileController - */ - protected function _prepareFormLayout($actionCode, $permissions = null, $anyPermission = true) - { - $this->_initWindowFormLayout( - 'adminhtml_blcg_grid_profile_form_window_action', - 'adminhtml_blcg_grid_profile_form_window_error', - 'blcg.grid_profile.form_error', - $permissions, - $anyPermission - ); - - if (($gridProfile = Mage::registry('blcg_grid_profile')) - && ($containerBlock = $this->getLayout()->getBlock('blcg.grid_profile.form_container'))) { - /** - * @var BL_CustomGrid_Model_Grid_Profile $gridProfile - * @var BL_CustomGrid_Block_Grid_Profile_Form_Container $containerBlock - */ - $containerBlock->setProfileId($gridProfile->getId())->setActionCode($actionCode); - } - - return $this; - } - public function goToAction() { try { @@ -67,7 +36,7 @@ public function goToAction() public function defaultFormAction() { - $this->_prepareFormLayout( + $this->_prepareWindowProfileFormLayout( 'default', array( BL_CustomGrid_Model_Grid_Sentry::ACTION_CHOOSE_OWN_USER_DEFAULT_PROFILE, @@ -106,7 +75,7 @@ public function defaultAction() public function copyToNewFormAction() { - $this->_prepareFormLayout('copy_new', BL_CustomGrid_Model_Grid_Sentry::ACTION_COPY_PROFILES_TO_NEW); + $this->_prepareWindowProfileFormLayout('copy_new', BL_CustomGrid_Model_Grid_Sentry::ACTION_COPY_PROFILES_TO_NEW); $this->renderLayout(); } @@ -149,7 +118,7 @@ public function copyToNewAction() public function copyToExistingFormAction() { - $this->_prepareFormLayout('copy_existing', BL_CustomGrid_Model_Grid_Sentry::ACTION_COPY_PROFILES_TO_EXISTING); + $this->_prepareWindowProfileFormLayout('copy_existing', BL_CustomGrid_Model_Grid_Sentry::ACTION_COPY_PROFILES_TO_EXISTING); $this->renderLayout(); } @@ -192,7 +161,7 @@ public function copyToExistingAction() public function editFormAction() { - $this->_prepareFormLayout('edit', BL_CustomGrid_Model_Grid_Sentry::ACTION_EDIT_PROFILES); + $this->_prepareWindowProfileFormLayout('edit', BL_CustomGrid_Model_Grid_Sentry::ACTION_EDIT_PROFILES); $this->renderLayout(); } @@ -230,7 +199,7 @@ public function editAction() public function assignFormAction() { - $this->_prepareFormLayout('assign', BL_CustomGrid_Model_Grid_Sentry::ACTION_ASSIGN_PROFILES); + $this->_prepareWindowProfileFormLayout('assign', BL_CustomGrid_Model_Grid_Sentry::ACTION_ASSIGN_PROFILES); $this->renderLayout(); } diff --git a/app/code/community/BL/CustomGrid/controllers/Blcg/GridController.php b/app/code/community/BL/CustomGrid/controllers/Blcg/GridController.php index bf5871c..cf76b86 100644 --- a/app/code/community/BL/CustomGrid/controllers/Blcg/GridController.php +++ b/app/code/community/BL/CustomGrid/controllers/Blcg/GridController.php @@ -39,41 +39,6 @@ protected function _initSystemPageAction() return $this; } - /** - * Initialize the current grid model and profile, check the given permissions, - * then prepare the layout for the given window form type - * - * @param string $formType Form type - * @param array $formData Form data - * @param string|array $permissions Required user permission(s) - * @param bool $anyPermission Whether all the given permissions are required, or just any of them - * @param array $handles Layout handles - * @return BL_CustomGrid_Blcg_GridController - */ - protected function _prepareWindowFormLayout( - $formType, - array $formData, - $permissions = null, - $anyPermission = true, - array $handles = array('blcg_empty') - ) { - $this->_initWindowFormLayout( - 'adminhtml_blcg_grid_form_window_action', - 'adminhtml_blcg_grid_form_window_error', - 'blcg.grid.form_error', - $permissions, - $anyPermission, - $handles - ); - - if ($containerBlock = $this->getLayout()->getBlock('blcg.grid.form_container')) { - /** @var $containerBlock BL_CustomGrid_Block_Grid_Form_Container */ - $containerBlock->setFormData($formData)->setFormType($formType); - } - - return $this; - } - public function indexAction() { if ($this->getRequest()->getQuery('ajax')) { @@ -120,7 +85,7 @@ public function reapplyDefaultFilterAction() public function columnsListFormAction() { - $this->_prepareWindowFormLayout( + $this->_prepareWindowGridFormLayout( 'columns_list', array(), BL_CustomGrid_Model_Grid_Sentry::ACTION_CUSTOMIZE_COLUMNS, @@ -174,7 +139,7 @@ public function saveColumnsAction() public function customColumnsFormAction() { - $this->_prepareWindowFormLayout( + $this->_prepareWindowGridFormLayout( 'custom_columns', array(), BL_CustomGrid_Model_Grid_Sentry::ACTION_CUSTOMIZE_COLUMNS @@ -226,7 +191,7 @@ public function defaultParamsFormAction() $defaultParams = array(); } - $this->_prepareWindowFormLayout( + $this->_prepareWindowGridFormLayout( 'default_params', array('default_params' => $defaultParams), BL_CustomGrid_Model_Grid_Sentry::ACTION_EDIT_DEFAULT_PARAMS @@ -283,87 +248,9 @@ public function saveDefaultParamsAction() } } - public function exportFormAction() - { - $this->_prepareWindowFormLayout( - 'export', - array( - 'total_size' => $this->getRequest()->getParam('total_size'), - 'first_index' => $this->getRequest()->getParam('first_index'), - 'additional_params' => $this->getRequest()->getParam('additional_params', array()), - ), - BL_CustomGrid_Model_Grid_Sentry::ACTION_EXPORT_RESULTS - ); - $this->renderLayout(); - } - - /** - * Restore in the request the additional parameters from the given export config - * - * @param array $exportConfig Export config values - */ - protected function _restoreExportAdditionalParams(array $exportConfig) - { - if (isset($exportConfig['additional_params']) && is_array($exportConfig['additional_params'])) { - foreach ($exportConfig['additional_params'] as $key => $value) { - if (!$this->getRequest()->has($key)) { - $this->getRequest()->setParam($key, $value); - } - } - } - } - - /** - * Apply an export action for the given format and file name - * - * @param string $format Export format - * @param string $fileName Exported file name - */ - protected function _applyExportAction($format, $fileName) - { - try { - $gridModel = $this->_initGridModel(); - $this->_initGridProfile(); - - if (!is_array($config = $this->getRequest()->getParam('export'))) { - $config = null; - } - - $this->_restoreExportAdditionalParams($config); - - if ($format == 'csv') { - $exportOutput = $gridModel->getExporter()->exportToCsv($config); - } elseif ($format == 'xml') { - $exportOutput = $gridModel->getExporter()->exportToExcel($config); - } else { - $exportOutput = ''; - } - - $this->_prepareDownloadResponse($fileName, $exportOutput); - - } catch (Mage_Core_Exception $e) { - $this->_getSession()->addError($e->getMessage()); - $this->_redirectReferer(); - } catch (Exception $e) { - Mage::logException($e); - $this->_getSession()->addError($this->__('An error occurred while exporting grid results')); - $this->_redirectReferer(); - } - } - - public function exportCsvAction() - { - $this->_applyExportAction('csv', 'export.csv'); - } - - public function exportExcelAction() - { - $this->_applyExportAction('xml', 'export.xml'); - } - public function gridInfosAction() { - $this->_prepareWindowFormLayout( + $this->_prepareWindowGridFormLayout( 'grid_infos', array(), array( @@ -661,132 +548,13 @@ public function deleteAction() ); } - /** - * Apply a mass-action action with the given callback that will be used for each selected grid ID - * - * @param callback $callback Callback to use for each grid ID - * @param string $defaultErrorMessage Default error message to display if a non-Magento exception is caught - * @param string $successfulMessage Message that will be displayed with the number of successfully handled IDs - * @param string $permissionErrorsMessage Message that will be displayed with the number of IDs that could not be - * handled due to permission errors - */ - protected function _applyMassactionAction( - $callback, - $defaultErrorMessage, - $successfulMessage, - $permissionErrorsMessage - ) { - if (!$this->_validateMassActionValues('grid')) { - return; - } - - $gridsIds = $this->getRequest()->getParam('grid'); - $successfulCount = 0; - $permissionErrorsCount = 0; - - try { - foreach ($gridsIds as $gridId) { - try { - call_user_func($callback, $gridId); - ++$successfulCount; - } catch (BL_CustomGrid_Grid_Permission_Exception $e) { - ++$permissionErrorsCount; - } - } - } catch (Mage_Core_Exception $e) { - $this->_getSession()->addError($e->getMessage()); - } catch (Exception $e) { - Mage::logException($e); - $this->_getSession()->addError($this->__($defaultErrorMessage)); - } - - if ($successfulCount > 0) { - $this->_getSession()->addSuccess($this->__($successfulMessage, $successfulCount)); - } - if ($permissionErrorsCount > 0) { - $this->_getSession()->addError($this->__($permissionErrorsMessage, $permissionErrorsCount)); - } - $this->getResponse()->setRedirect($this->getUrl('*/*/')); - } - - /** - * Disable the grid model corresponding to the ID - * - * @param int $gridId Grid model ID - */ - protected function _massDisableGrid($gridId) - { - /** @var $gridModel BL_CustomGrid_Model_Grid */ - $gridModel = Mage::getSingleton('customgrid/grid'); - $gridModel->load($gridId)->setDisabled(true)->save(); - } - - public function massDisableAction() - { - $this->_applyMassactionAction( - array($this, '_massDisableGrid'), - 'An error occurred while disabling a grid', - 'Total of %d grid(s) have been disabled', - 'You were not allowed to disable %d of the chosen grids' - ); - } - - /** - * Enable the grid model corresponding to the given ID - * - * @param int $gridId Grid model ID - */ - protected function _massEnableGrid($gridId) - { - /** @var $gridModel BL_CustomGrid_Model_Grid */ - $gridModel = Mage::getSingleton('customgrid/grid'); - $gridModel->load($gridId)->setDisabled(false)->save(); - } - - public function massEnableAction() - { - $this->_applyMassactionAction( - array($this, '_massEnableGrid'), - 'An error occurred while enabling a grid', - 'Total of %d grid(s) have been enabled', - 'You were not allowed to enable %d of the chosen grids' - ); - } - - /** - * Delete the grid model corresponding to the given ID - * - * @param int $gridId Grid model ID - */ - protected function _massDeleteGrid($gridId) - { - /** @var $gridModel BL_CustomGrid_Model_Grid */ - $gridModel = Mage::getSingleton('customgrid/grid'); - $gridModel->load($gridId)->delete(); - } - - public function massDeleteAction() - { - $this->_applyMassactionAction( - array($this, '_massDeleteGrid'), - 'An error occurred while deleting a grid', - 'Total of %d grid(s) have been deleted', - 'You were not allowed to delete %d of the chosen grids' - ); - } - protected function _isAllowed() { // Specific permissions are enforced by the models switch ($this->getRequest()->getActionName()) { case 'index': case 'grid': - case 'massDelete': - case 'massDisable': - case 'massEnable': - /** @var $session Mage_Admin_Model_Session */ - $session = Mage::getSingleton('admin/session'); - return $session->isAllowed('customgrid/administration/view_grids_list'); + return $this->_getAdminSession()->isAllowed('customgrid/administration/view_grids_list'); } return true; } diff --git a/app/code/community/BL/CustomGrid/controllers/Blcg/Options/SourceController.php b/app/code/community/BL/CustomGrid/controllers/Blcg/Options/SourceController.php index a03e854..77aa446 100644 --- a/app/code/community/BL/CustomGrid/controllers/Blcg/Options/SourceController.php +++ b/app/code/community/BL/CustomGrid/controllers/Blcg/Options/SourceController.php @@ -207,8 +207,6 @@ public function massDeleteAction() protected function _isAllowed() { - /** @var $session Mage_Admin_Model_Session */ - $session = Mage::getSingleton('admin/session'); - return $session->isAllowed('system/customgrid/options_source'); + return $this->_getAdminSession()->isAllowed('system/customgrid/options_source'); } }