xtest - Version 0.1.0

Version Notes

Notes

Download this release

Release Info

Developer Magento Core Team
Extension xtest
Version 0.1.0
Comparing to
See all releases


Version 0.1.0

app/code/local/NL/XTest/Block/Adminhtml/XTest.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class NL_XTest_Block_Adminhtml_XTest extends Mage_Adminhtml_Block_Widget_Grid_Container
3
+ {
4
+ public function __construct()
5
+ {
6
+ $this->_controller = 'adminhtml_xtest';
7
+ $this->_blockGroup = 'xtest';
8
+ $this->_headerText = Mage::helper('xtest')->__('Item Manager');
9
+ $this->_addButtonLabel = Mage::helper('xtest')->__('Add Item');
10
+ parent::__construct();
11
+ }
12
+ }
app/code/local/NL/XTest/Block/Adminhtml/XTest/Edit.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class NL_XTest_Block_Adminhtml_XTest_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+
9
+ $this->_objectId = 'id';
10
+ $this->_blockGroup = 'xtest';
11
+ $this->_controller = 'adminhtml_xtest';
12
+
13
+ $this->_updateButton('save', 'label', Mage::helper('xtest')->__('Save Item'));
14
+ $this->_updateButton('delete', 'label', Mage::helper('xtest')->__('Delete Item'));
15
+
16
+ $this->_addButton('saveandcontinue', array(
17
+ 'label' => Mage::helper('adminhtml')->__('Save And Continue Edit'),
18
+ 'onclick' => 'saveAndContinueEdit()',
19
+ 'class' => 'save',
20
+ ), -100);
21
+
22
+ $this->_formScripts[] = "
23
+ function toggleEditor() {
24
+ if (tinyMCE.getInstanceById('xtest_content') == null) {
25
+ tinyMCE.execCommand('mceAddControl', false, 'xtest_content');
26
+ } else {
27
+ tinyMCE.execCommand('mceRemoveControl', false, 'xtest_content');
28
+ }
29
+ }
30
+
31
+ function saveAndContinueEdit(){
32
+ editForm.submit($('edit_form').action+'back/edit/');
33
+ }
34
+ ";
35
+ }
36
+
37
+ public function getHeaderText()
38
+ {
39
+ if( Mage::registry('xtest_data') && Mage::registry('xtest_data')->getId() ) {
40
+ return Mage::helper('xtest')->__("Edit Item '%s'", $this->htmlEscape(Mage::registry('xtest_data')->getTitle()));
41
+ } else {
42
+ return Mage::helper('xtest')->__('Add Item');
43
+ }
44
+ }
45
+ }
app/code/local/NL/XTest/Block/Adminhtml/XTest/Edit/Form.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class NL_XTest_Block_Adminhtml_XTest_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
4
+ {
5
+ protected function _prepareForm()
6
+ {
7
+ $form = new Varien_Data_Form(array(
8
+ 'id' => 'edit_form',
9
+ 'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
10
+ 'method' => 'post',
11
+ 'enctype' => 'multipart/form-data'
12
+ )
13
+ );
14
+
15
+ $form->setUseContainer(true);
16
+ $this->setForm($form);
17
+ return parent::_prepareForm();
18
+ }
19
+ }
app/code/local/NL/XTest/Block/Adminhtml/XTest/Edit/Tab/Form.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class NL_XTest_Block_Adminhtml_XTest_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
4
+ {
5
+ protected function _prepareForm()
6
+ {
7
+ $form = new Varien_Data_Form();
8
+ $this->setForm($form);
9
+ $fieldset = $form->addFieldset('xtest_form', array('legend'=>Mage::helper('xtest')->__('Item information')));
10
+
11
+ $fieldset->addField('title', 'text', array(
12
+ 'label' => Mage::helper('xtest')->__('Title'),
13
+ 'class' => 'required-entry',
14
+ 'required' => true,
15
+ 'name' => 'title',
16
+ ));
17
+
18
+ $fieldset->addField('filename', 'file', array(
19
+ 'label' => Mage::helper('xtest')->__('File'),
20
+ 'required' => false,
21
+ 'name' => 'filename',
22
+ ));
23
+
24
+ $fieldset->addField('status', 'select', array(
25
+ 'label' => Mage::helper('xtest')->__('Status'),
26
+ 'name' => 'status',
27
+ 'values' => array(
28
+ array(
29
+ 'value' => 1,
30
+ 'label' => Mage::helper('xtest')->__('Enabled'),
31
+ ),
32
+
33
+ array(
34
+ 'value' => 2,
35
+ 'label' => Mage::helper('xtest')->__('Disabled'),
36
+ ),
37
+ ),
38
+ ));
39
+
40
+ $fieldset->addField('content', 'editor', array(
41
+ 'name' => 'content',
42
+ 'label' => Mage::helper('xtest')->__('Content'),
43
+ 'title' => Mage::helper('xtest')->__('Content'),
44
+ 'style' => 'width:700px; height:500px;',
45
+ 'wysiwyg' => false,
46
+ 'required' => true,
47
+ ));
48
+
49
+ if ( Mage::getSingleton('adminhtml/session')->getXTestData() )
50
+ {
51
+ $form->setValues(Mage::getSingleton('adminhtml/session')->getXTestData());
52
+ Mage::getSingleton('adminhtml/session')->setXTestData(null);
53
+ } elseif ( Mage::registry('xtest_data') ) {
54
+ $form->setValues(Mage::registry('xtest_data')->getData());
55
+ }
56
+ return parent::_prepareForm();
57
+ }
58
+ }
app/code/local/NL/XTest/Block/Adminhtml/XTest/Edit/Tabs.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class NL_XTest_Block_Adminhtml_XTest_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
4
+ {
5
+
6
+ public function __construct()
7
+ {
8
+ parent::__construct();
9
+ $this->setId('xtest_tabs');
10
+ $this->setDestElementId('edit_form');
11
+ $this->setTitle(Mage::helper('xtest')->__('Item Information'));
12
+ }
13
+
14
+ protected function _beforeToHtml()
15
+ {
16
+ $this->addTab('form_section', array(
17
+ 'label' => Mage::helper('xtest')->__('Item Information'),
18
+ 'title' => Mage::helper('xtest')->__('Item Information'),
19
+ 'content' => $this->getLayout()->createBlock('xtest/adminhtml_xtest_edit_tab_form')->toHtml(),
20
+ ));
21
+
22
+ return parent::_beforeToHtml();
23
+ }
24
+ }
app/code/local/NL/XTest/Block/Adminhtml/XTest/Grid.php ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class NL_XTest_Block_Adminhtml_XTest_Grid extends Mage_Adminhtml_Block_Widget_Grid
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+ $this->setId('xtestGrid');
9
+ $this->setDefaultSort('xtest_id');
10
+ $this->setDefaultDir('ASC');
11
+ $this->setSaveParametersInSession(true);
12
+ }
13
+
14
+ protected function _prepareCollection()
15
+ {
16
+ $collection = Mage::getModel('xtest/xtest')->getCollection();
17
+ $this->setCollection($collection);
18
+ return parent::_prepareCollection();
19
+ }
20
+
21
+ protected function _prepareColumns()
22
+ {
23
+ $this->addColumn('xtest_id', array(
24
+ 'header' => Mage::helper('xtest')->__('ID'),
25
+ 'align' =>'right',
26
+ 'width' => '50px',
27
+ 'index' => 'xtest_id',
28
+ ));
29
+
30
+ $this->addColumn('title', array(
31
+ 'header' => Mage::helper('xtest')->__('Title'),
32
+ 'align' =>'left',
33
+ 'index' => 'title',
34
+ ));
35
+
36
+ /*
37
+ $this->addColumn('content', array(
38
+ 'header' => Mage::helper('xtest')->__('Item Content'),
39
+ 'width' => '150px',
40
+ 'index' => 'content',
41
+ ));
42
+ */
43
+
44
+ $this->addColumn('status', array(
45
+ 'header' => Mage::helper('xtest')->__('Status'),
46
+ 'align' => 'left',
47
+ 'width' => '80px',
48
+ 'index' => 'status',
49
+ 'type' => 'options',
50
+ 'options' => array(
51
+ 1 => 'Enabled',
52
+ 2 => 'Disabled',
53
+ ),
54
+ ));
55
+
56
+ $this->addColumn('action',
57
+ array(
58
+ 'header' => Mage::helper('xtest')->__('Action'),
59
+ 'width' => '100',
60
+ 'type' => 'action',
61
+ 'getter' => 'getId',
62
+ 'actions' => array(
63
+ array(
64
+ 'caption' => Mage::helper('xtest')->__('Edit'),
65
+ 'url' => array('base'=> '*/*/edit'),
66
+ 'field' => 'id'
67
+ )
68
+ ),
69
+ 'filter' => false,
70
+ 'sortable' => false,
71
+ 'index' => 'stores',
72
+ 'is_system' => true,
73
+ ));
74
+
75
+ $this->addExportType('*/*/exportCsv', Mage::helper('xtest')->__('CSV'));
76
+ $this->addExportType('*/*/exportXml', Mage::helper('xtest')->__('XML'));
77
+
78
+ return parent::_prepareColumns();
79
+ }
80
+
81
+ protected function _prepareMassaction()
82
+ {
83
+ $this->setMassactionIdField('xtest_id');
84
+ $this->getMassactionBlock()->setFormFieldName('xtest');
85
+
86
+ $this->getMassactionBlock()->addItem('delete', array(
87
+ 'label' => Mage::helper('xtest')->__('Delete'),
88
+ 'url' => $this->getUrl('*/*/massDelete'),
89
+ 'confirm' => Mage::helper('xtest')->__('Are you sure?')
90
+ ));
91
+
92
+ $statuses = Mage::getSingleton('xtest/status')->getOptionArray();
93
+
94
+ array_unshift($statuses, array('label'=>'', 'value'=>''));
95
+ $this->getMassactionBlock()->addItem('status', array(
96
+ 'label'=> Mage::helper('xtest')->__('Change status'),
97
+ 'url' => $this->getUrl('*/*/massStatus', array('_current'=>true)),
98
+ 'additional' => array(
99
+ 'visibility' => array(
100
+ 'name' => 'status',
101
+ 'type' => 'select',
102
+ 'class' => 'required-entry',
103
+ 'label' => Mage::helper('xtest')->__('Status'),
104
+ 'values' => $statuses
105
+ )
106
+ )
107
+ ));
108
+ return $this;
109
+ }
110
+
111
+ public function getRowUrl($row)
112
+ {
113
+ return $this->getUrl('*/*/edit', array('id' => $row->getId()));
114
+ }
115
+
116
+ }
app/code/local/NL/XTest/Block/XTest.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class NL_XTest_Block_XTest extends Mage_Core_Block_Template
3
+ {
4
+ public function _prepareLayout()
5
+ {
6
+ return parent::_prepareLayout();
7
+ }
8
+
9
+ public function getXTest()
10
+ {
11
+ if (!$this->hasData('xtest')) {
12
+ $this->setData('xtest', Mage::registry('xtest'));
13
+ }
14
+ return $this->getData('xtest');
15
+
16
+ }
17
+ }
app/code/local/NL/XTest/Helper/Data.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class NL_XTest_Helper_Data extends Mage_Core_Helper_Abstract
4
+ {
5
+
6
+ }
app/code/local/NL/XTest/Model/Mysql4/XTest.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class NL_XTest_Model_Mysql4_XTest extends Mage_Core_Model_Mysql4_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ // Note that the xtest_id refers to the key field in your database table.
8
+ $this->_init('xtest/xtest', 'xtest_id');
9
+ }
10
+ }
app/code/local/NL/XTest/Model/Mysql4/XTest/Collection.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class NL_XTest_Model_Mysql4_XTest_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->_init('xtest/xtest');
9
+ }
10
+ }
app/code/local/NL/XTest/Model/Status.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class NL_XTest_Model_Status extends Varien_Object
4
+ {
5
+ const STATUS_ENABLED = 1;
6
+ const STATUS_DISABLED = 2;
7
+
8
+ static public function getOptionArray()
9
+ {
10
+ return array(
11
+ self::STATUS_ENABLED => Mage::helper('xtest')->__('Enabled'),
12
+ self::STATUS_DISABLED => Mage::helper('xtest')->__('Disabled')
13
+ );
14
+ }
15
+ }
app/code/local/NL/XTest/Model/XTest.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class NL_XTest_Model_XTest extends Mage_Core_Model_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->_init('xtest/xtest');
9
+ }
10
+ }
app/code/local/NL/XTest/controllers/Adminhtml/XTestController.php ADDED
@@ -0,0 +1,214 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class NL_XTest_Adminhtml_XTestController extends Mage_Adminhtml_Controller_action
4
+ {
5
+
6
+ protected function _initAction() {
7
+ $this->loadLayout()
8
+ ->_setActiveMenu('xtest/items')
9
+ ->_addBreadcrumb(Mage::helper('adminhtml')->__('Items Manager'), Mage::helper('adminhtml')->__('Item Manager'));
10
+
11
+ return $this;
12
+ }
13
+
14
+ public function indexAction() {
15
+ $this->_initAction()
16
+ ->renderLayout();
17
+ }
18
+
19
+ public function editAction() {
20
+ $id = $this->getRequest()->getParam('id');
21
+ $model = Mage::getModel('xtest/xtest')->load($id);
22
+
23
+ if ($model->getId() || $id == 0) {
24
+ $data = Mage::getSingleton('adminhtml/session')->getFormData(true);
25
+ if (!empty($data)) {
26
+ $model->setData($data);
27
+ }
28
+
29
+ Mage::register('xtest_data', $model);
30
+
31
+ $this->loadLayout();
32
+ $this->_setActiveMenu('xtest/items');
33
+
34
+ $this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item Manager'), Mage::helper('adminhtml')->__('Item Manager'));
35
+ $this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item News'), Mage::helper('adminhtml')->__('Item News'));
36
+
37
+ $this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
38
+
39
+ $this->_addContent($this->getLayout()->createBlock('xtest/adminhtml_xtest_edit'))
40
+ ->_addLeft($this->getLayout()->createBlock('xtest/adminhtml_xtest_edit_tabs'));
41
+
42
+ $this->renderLayout();
43
+ } else {
44
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('xtest')->__('Item does not exist'));
45
+ $this->_redirect('*/*/');
46
+ }
47
+ }
48
+
49
+ public function newAction() {
50
+ $this->_forward('edit');
51
+ }
52
+
53
+ public function saveAction() {
54
+ if ($data = $this->getRequest()->getPost()) {
55
+
56
+ if(isset($_FILES['filename']['name']) && $_FILES['filename']['name'] != '') {
57
+ try {
58
+ /* Starting upload */
59
+ $uploader = new Varien_File_Uploader('filename');
60
+
61
+ // Any extention would work
62
+ $uploader->setAllowedExtensions(array('jpg','jpeg','gif','png'));
63
+ $uploader->setAllowRenameFiles(false);
64
+
65
+ // Set the file upload mode
66
+ // false -> get the file directly in the specified folder
67
+ // true -> get the file in the product like folders
68
+ // (file.jpg will go in something like /media/f/i/file.jpg)
69
+ $uploader->setFilesDispersion(false);
70
+
71
+ // We set media as the upload dir
72
+ $path = Mage::getBaseDir('media') . DS ;
73
+ $uploader->save($path, $_FILES['filename']['name'] );
74
+
75
+ } catch (Exception $e) {
76
+
77
+ }
78
+
79
+ //this way the name is saved in DB
80
+ $data['filename'] = $_FILES['filename']['name'];
81
+ }
82
+
83
+
84
+ $model = Mage::getModel('xtest/xtest');
85
+ $model->setData($data)
86
+ ->setId($this->getRequest()->getParam('id'));
87
+
88
+ try {
89
+ if ($model->getCreatedTime == NULL || $model->getUpdateTime() == NULL) {
90
+ $model->setCreatedTime(now())
91
+ ->setUpdateTime(now());
92
+ } else {
93
+ $model->setUpdateTime(now());
94
+ }
95
+
96
+ $model->save();
97
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('xtest')->__('Item was successfully saved'));
98
+ Mage::getSingleton('adminhtml/session')->setFormData(false);
99
+
100
+ if ($this->getRequest()->getParam('back')) {
101
+ $this->_redirect('*/*/edit', array('id' => $model->getId()));
102
+ return;
103
+ }
104
+ $this->_redirect('*/*/');
105
+ return;
106
+ } catch (Exception $e) {
107
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
108
+ Mage::getSingleton('adminhtml/session')->setFormData($data);
109
+ $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
110
+ return;
111
+ }
112
+ }
113
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('xtest')->__('Unable to find item to save'));
114
+ $this->_redirect('*/*/');
115
+ }
116
+
117
+ public function deleteAction() {
118
+ if( $this->getRequest()->getParam('id') > 0 ) {
119
+ try {
120
+ $model = Mage::getModel('xtest/xtest');
121
+
122
+ $model->setId($this->getRequest()->getParam('id'))
123
+ ->delete();
124
+
125
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Item was successfully deleted'));
126
+ $this->_redirect('*/*/');
127
+ } catch (Exception $e) {
128
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
129
+ $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
130
+ }
131
+ }
132
+ $this->_redirect('*/*/');
133
+ }
134
+
135
+ public function massDeleteAction() {
136
+ $xtestIds = $this->getRequest()->getParam('xtest');
137
+ if(!is_array($xtestIds)) {
138
+ Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select item(s)'));
139
+ } else {
140
+ try {
141
+ foreach ($xtestIds as $xtestId) {
142
+ $xtest = Mage::getModel('xtest/xtest')->load($xtestId);
143
+ $xtest->delete();
144
+ }
145
+ Mage::getSingleton('adminhtml/session')->addSuccess(
146
+ Mage::helper('adminhtml')->__(
147
+ 'Total of %d record(s) were successfully deleted', count($xtestIds)
148
+ )
149
+ );
150
+ } catch (Exception $e) {
151
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
152
+ }
153
+ }
154
+ $this->_redirect('*/*/index');
155
+ }
156
+
157
+ public function massStatusAction()
158
+ {
159
+ $xtestIds = $this->getRequest()->getParam('xtest');
160
+ if(!is_array($xtestIds)) {
161
+ Mage::getSingleton('adminhtml/session')->addError($this->__('Please select item(s)'));
162
+ } else {
163
+ try {
164
+ foreach ($xtestIds as $xtestId) {
165
+ $xtest = Mage::getSingleton('xtest/xtest')
166
+ ->load($xtestId)
167
+ ->setStatus($this->getRequest()->getParam('status'))
168
+ ->setIsMassupdate(true)
169
+ ->save();
170
+ }
171
+ $this->_getSession()->addSuccess(
172
+ $this->__('Total of %d record(s) were successfully updated', count($xtestIds))
173
+ );
174
+ } catch (Exception $e) {
175
+ $this->_getSession()->addError($e->getMessage());
176
+ }
177
+ }
178
+ $this->_redirect('*/*/index');
179
+ }
180
+
181
+ public function exportCsvAction()
182
+ {
183
+ $fileName = 'xtest.csv';
184
+ $content = $this->getLayout()->createBlock('xtest/adminhtml_xtest_grid')
185
+ ->getCsv();
186
+
187
+ $this->_sendUploadResponse($fileName, $content);
188
+ }
189
+
190
+ public function exportXmlAction()
191
+ {
192
+ $fileName = 'xtest.xml';
193
+ $content = $this->getLayout()->createBlock('xtest/adminhtml_xtest_grid')
194
+ ->getXml();
195
+
196
+ $this->_sendUploadResponse($fileName, $content);
197
+ }
198
+
199
+ protected function _sendUploadResponse($fileName, $content, $contentType='application/octet-stream')
200
+ {
201
+ $response = $this->getResponse();
202
+ $response->setHeader('HTTP/1.1 200 OK','');
203
+ $response->setHeader('Pragma', 'public', true);
204
+ $response->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true);
205
+ $response->setHeader('Content-Disposition', 'attachment; filename='.$fileName);
206
+ $response->setHeader('Last-Modified', date('r'));
207
+ $response->setHeader('Accept-Ranges', 'bytes');
208
+ $response->setHeader('Content-Length', strlen($content));
209
+ $response->setHeader('Content-type', $contentType);
210
+ $response->setBody($content);
211
+ $response->sendResponse();
212
+ die;
213
+ }
214
+ }
app/code/local/NL/XTest/controllers/IndexController.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class NL_XTest_IndexController extends Mage_Core_Controller_Front_Action
3
+ {
4
+ public function indexAction()
5
+ {
6
+
7
+ /*
8
+ * Load an object by id
9
+ * Request looking like:
10
+ * http://site.com/xtest?id=15
11
+ * or
12
+ * http://site.com/xtest/id/15
13
+ */
14
+ /*
15
+ $xtest_id = $this->getRequest()->getParam('id');
16
+
17
+ if($xtest_id != null && $xtest_id != '') {
18
+ $xtest = Mage::getModel('xtest/xtest')->load($xtest_id)->getData();
19
+ } else {
20
+ $xtest = null;
21
+ }
22
+ */
23
+
24
+ /*
25
+ * If no param we load a the last created item
26
+ */
27
+ /*
28
+ if($xtest == null) {
29
+ $resource = Mage::getSingleton('core/resource');
30
+ $read= $resource->getConnection('core_read');
31
+ $xtestTable = $resource->getTableName('xtest');
32
+
33
+ $select = $read->select()
34
+ ->from($xtestTable,array('xtest_id','title','content','status'))
35
+ ->where('status',1)
36
+ ->order('created_time DESC') ;
37
+
38
+ $xtest = $read->fetchRow($select);
39
+ }
40
+ Mage::register('xtest', $xtest);
41
+ */
42
+
43
+
44
+ $this->loadLayout();
45
+ $this->renderLayout();
46
+ }
47
+ }
app/code/local/NL/XTest/etc/config.xml ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <NL_XTest>
5
+ <version>0.1.0</version>
6
+ </NL_XTest>
7
+ </modules>
8
+ <frontend>
9
+ <routers>
10
+ <xtest>
11
+ <use>standard</use>
12
+ <args>
13
+ <module>NL_XTest</module>
14
+ <frontName>xtest</frontName>
15
+ </args>
16
+ </xtest>
17
+ </routers>
18
+ <layout>
19
+ <updates>
20
+ <xtest>
21
+ <file>xtest.xml</file>
22
+ </xtest>
23
+ </updates>
24
+ </layout>
25
+ </frontend>
26
+ <admin>
27
+ <routers>
28
+ <xtest>
29
+ <use>admin</use>
30
+ <args>
31
+ <module>NL_XTest</module>
32
+ <frontName>xtest</frontName>
33
+ </args>
34
+ </xtest>
35
+ </routers>
36
+ </admin>
37
+ <adminhtml>
38
+ <menu>
39
+ <xtest module="xtest">
40
+ <title>XTest</title>
41
+ <sort_order>71</sort_order>
42
+ <children>
43
+ <items module="xtest">
44
+ <title>Manage Items</title>
45
+ <sort_order>0</sort_order>
46
+ <action>xtest/adminhtml_xtest</action>
47
+ </items>
48
+ </children>
49
+ </xtest>
50
+ </menu>
51
+ <acl>
52
+ <resources>
53
+ <all>
54
+ <title>Allow Everything</title>
55
+ </all>
56
+ <admin>
57
+ <children>
58
+ <NL_XTest>
59
+ <title>XTest Module</title>
60
+ <sort_order>10</sort_order>
61
+ </NL_XTest>
62
+ </children>
63
+ </admin>
64
+ </resources>
65
+ </acl>
66
+ <layout>
67
+ <updates>
68
+ <xtest>
69
+ <file>xtest.xml</file>
70
+ </xtest>
71
+ </updates>
72
+ </layout>
73
+ </adminhtml>
74
+ <global>
75
+ <models>
76
+ <xtest>
77
+ <class>NL_XTest_Model</class>
78
+ <resourceModel>xtest_mysql4</resourceModel>
79
+ </xtest>
80
+ <xtest_mysql4>
81
+ <class>NL_XTest_Model_Mysql4</class>
82
+ <entities>
83
+ <xtest>
84
+ <table>xtest</table>
85
+ </xtest>
86
+ </entities>
87
+ </xtest_mysql4>
88
+ </models>
89
+ <resources>
90
+ <xtest_setup>
91
+ <setup>
92
+ <module>NL_XTest</module>
93
+ </setup>
94
+ <connection>
95
+ <use>core_setup</use>
96
+ </connection>
97
+ </xtest_setup>
98
+ <xtest_write>
99
+ <connection>
100
+ <use>core_write</use>
101
+ </connection>
102
+ </xtest_write>
103
+ <xtest_read>
104
+ <connection>
105
+ <use>core_read</use>
106
+ </connection>
107
+ </xtest_read>
108
+ </resources>
109
+ <blocks>
110
+ <xtest>
111
+ <class>NL_XTest_Block</class>
112
+ </xtest>
113
+ </blocks>
114
+ <helpers>
115
+ <xtest>
116
+ <class>NL_XTest_Helper</class>
117
+ </xtest>
118
+ </helpers>
119
+ </global>
120
+ </config>
app/code/local/NL/XTest/sql/xtest_setup/mysql4-install-0.1.0.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+
5
+ $installer->startSetup();
6
+
7
+ $installer->run("
8
+
9
+ -- DROP TABLE IF EXISTS {$this->getTable('xtest')};
10
+ CREATE TABLE {$this->getTable('xtest')} (
11
+ `xtest_id` int(11) unsigned NOT NULL auto_increment,
12
+ `title` varchar(255) NOT NULL default '',
13
+ `filename` varchar(255) NOT NULL default '',
14
+ `content` text NOT NULL default '',
15
+ `status` smallint(6) NOT NULL default '0',
16
+ `created_time` datetime NULL,
17
+ `update_time` datetime NULL,
18
+ PRIMARY KEY (`xtest_id`)
19
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
20
+
21
+ ");
22
+
23
+ $installer->endSetup();
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>xtest</name>
4
+ <version>0.1.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Summary</summary>
10
+ <description>Description</description>
11
+ <notes>Notes</notes>
12
+ <authors><author><name>Kevin</name><user>auto-converted</user><email>kevin.magento@gmail.com</email></author></authors>
13
+ <date>2011-05-10</date>
14
+ <time>18:14:41</time>
15
+ <contents><target name="magelocal"><dir name="NL"><dir name="XTest"><dir name="Block"><dir name="Adminhtml"><dir name="XTest"><dir name="Edit"><dir name="Tab"><file name="Form.php" hash="5c33defa5bbc07f5d1af772e563a3ff9"/></dir><file name="Form.php" hash="e5596f43e97b77546e2dfb354a946448"/><file name="Tabs.php" hash="bbba39b9866daac8b3fb142c36e4df06"/></dir><file name="Edit.php" hash="598f458682acf962b216ade0e2d902b0"/><file name="Grid.php" hash="1e5f9c1d17c36d8baaef01518e57f969"/></dir><file name="XTest.php" hash="4fa62b25d7722e8f6d6ecefeae7755d0"/></dir><file name="XTest.php" hash="e3b54336430e3f00b3e2c63daa96171a"/></dir><dir name="Helper"><file name="Data.php" hash="8005074c2cb9abf65f723c456087439c"/></dir><dir name="Model"><dir name="Mysql4"><dir name="XTest"><file name="Collection.php" hash="04ee221f22a3b866f0161c9a8f47c29a"/></dir><file name="XTest.php" hash="54000a00d6b875b50436d97ba0e76b32"/></dir><file name="Status.php" hash="0c6df086fdbc6185b4d0e58e643418df"/><file name="XTest.php" hash="3c4717a1f6d8754993ed5caf7f7bc16f"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="XTestController.php" hash="353e19b37481b5210cba2a8e18a8d215"/></dir><file name="IndexController.php" hash="e1f6ad6e64fb10a2b0705872a6f423b9"/></dir><dir name="etc"><file name="config.xml" hash="eefc5e77037fbb3a6655dd33c663f5e7"/></dir><dir name="sql"><dir name="xtest_setup"><file name="mysql4-install-0.1.0.php" hash="3994d05b97e2f31ddc193eed27437de3"/></dir></dir></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies/>
18
+ </package>