1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_ImportExport
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27: /**
28: * Export controller
29: *
30: * @category Mage
31: * @package Mage_ImportExport
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_ImportExport_Adminhtml_ExportController extends Mage_Adminhtml_Controller_Action
35: {
36: /**
37: * Custom constructor.
38: *
39: * @return void
40: */
41: protected function _construct()
42: {
43: // Define module dependent translate
44: $this->setUsedModuleName('Mage_ImportExport');
45: }
46:
47: /**
48: * Initialize layout.
49: *
50: * @return Mage_ImportExport_Adminhtml_ExportController
51: */
52: protected function _initAction()
53: {
54: $this->_title($this->__('Import/Export'))
55: ->loadLayout()
56: ->_setActiveMenu('system/importexport');
57:
58: return $this;
59: }
60:
61: /**
62: * Check access (in the ACL) for current user
63: *
64: * @return bool
65: */
66: protected function _isAllowed()
67: {
68: return Mage::getSingleton('admin/session')->isAllowed('system/convert/export');
69: }
70:
71: /**
72: * Load data with filter applying and create file for download.
73: *
74: * @return Mage_ImportExport_Adminhtml_ExportController
75: */
76: public function exportAction()
77: {
78: if ($this->getRequest()->getPost(Mage_ImportExport_Model_Export::FILTER_ELEMENT_GROUP)) {
79: try {
80: /** @var $model Mage_ImportExport_Model_Export */
81: $model = Mage::getModel('importexport/export');
82: $model->setData($this->getRequest()->getParams());
83:
84: return $this->_prepareDownloadResponse(
85: $model->getFileName(),
86: $model->export(),
87: $model->getContentType()
88: );
89: } catch (Mage_Core_Exception $e) {
90: $this->_getSession()->addError($e->getMessage());
91: } catch (Exception $e) {
92: Mage::logException($e);
93: $this->_getSession()->addError($this->__('No valid data sent'));
94: }
95: } else {
96: $this->_getSession()->addError($this->__('No valid data sent'));
97: }
98: return $this->_redirect('*/*/index');
99: }
100:
101: /**
102: * Index action.
103: *
104: * @return void
105: */
106: public function indexAction()
107: {
108: $this->_initAction()
109: ->_title($this->__('Export'))
110: ->_addBreadcrumb($this->__('Export'), $this->__('Export'));
111:
112: $this->renderLayout();
113: }
114:
115: /**
116: * Get grid-filter of entity attributes action.
117: *
118: * @return void
119: */
120: public function getFilterAction()
121: {
122: $data = $this->getRequest()->getParams();
123: if ($this->getRequest()->isXmlHttpRequest() && $data) {
124: try {
125: $this->loadLayout();
126:
127: /** @var $attrFilterBlock Mage_ImportExport_Block_Adminhtml_Export_Filter */
128: $attrFilterBlock = $this->getLayout()->getBlock('export.filter');
129: /** @var $export Mage_ImportExport_Model_Export */
130: $export = Mage::getModel('importexport/export');
131:
132: $export->filterAttributeCollection(
133: $attrFilterBlock->prepareCollection(
134: $export->setData($data)->getEntityAttributeCollection()
135: )
136: );
137: return $this->renderLayout();
138: } catch (Exception $e) {
139: $this->_getSession()->addError($e->getMessage());
140: }
141: } else {
142: $this->_getSession()->addError($this->__('No valid data sent'));
143: }
144: $this->_redirect('*/*/index');
145: }
146: }
147: