DigitalPianism_ExportReview - Version 0.1.0

Version Notes

- Use of event observer instead of block rewrites

Download this release

Release Info

Developer Digital Pianism
Extension DigitalPianism_ExportReview
Version 0.1.0
Comparing to
See all releases


Code changes from version 0.0.3 to 0.1.0

app/code/community/DigitalPianism/ExportReview/Block/Review/Grid.php DELETED
@@ -1,162 +0,0 @@
1
- <?php
2
- /*
3
- Grid to add the export button
4
- */
5
-
6
- /**
7
- * Class DigitalPianism_ExportReview_Block_Review_Grid
8
- */
9
- class DigitalPianism_ExportReview_Block_Review_Grid extends Mage_Adminhtml_Block_Review_Grid
10
- {
11
- /**
12
- * @return $this
13
- * @throws Exception
14
- */
15
- protected function _prepareColumns()
16
- {
17
-
18
- $statuses = Mage::getModel('review/review')
19
- ->getStatusCollection()
20
- ->load()
21
- ->toOptionArray();
22
-
23
- $tmpArr = array();
24
- foreach( $statuses as $key => $status ) {
25
- $tmpArr[$status['value']] = $status['label'];
26
- }
27
-
28
- $statuses = $tmpArr;
29
-
30
- $this->addColumn('review_id', array(
31
- 'header' => Mage::helper('review')->__('Review ID'),
32
- 'align' => 'right',
33
- 'width' => '50px',
34
- 'filter_index' => 'rt.review_id',
35
- 'index' => 'review_id',
36
- ));
37
-
38
- $this->addColumn('created_at', array(
39
- 'header' => Mage::helper('review')->__('Created On'),
40
- 'align' => 'left',
41
- 'type' => 'datetime',
42
- 'width' => '100px',
43
- 'filter_index' => 'rt.review_created_at',
44
- 'index' => 'review_created_at',
45
- ));
46
-
47
- if( !Mage::registry('usePendingFilter') ) {
48
- $this->addColumn('status', array(
49
- 'header' => Mage::helper('review')->__('Status'),
50
- 'align' => 'left',
51
- 'type' => 'options',
52
- 'options' => $statuses,
53
- 'width' => '100px',
54
- 'filter_index' => 'rt.status_id',
55
- 'index' => 'status_id',
56
- ));
57
- }
58
-
59
- $this->addColumn('title', array(
60
- 'header' => Mage::helper('review')->__('Title'),
61
- 'align' => 'left',
62
- 'width' => '100px',
63
- 'filter_index' => 'rdt.title',
64
- 'index' => 'title',
65
- 'type' => 'text',
66
- //'truncate' => 50, // We remove the truncate to display the entire review title
67
- 'escape' => true,
68
- ));
69
-
70
- $this->addColumn('nickname', array(
71
- 'header' => Mage::helper('review')->__('Nickname'),
72
- 'align' => 'left',
73
- 'width' => '100px',
74
- 'filter_index' => 'rdt.nickname',
75
- 'index' => 'nickname',
76
- 'type' => 'text',
77
- 'truncate' => 50,
78
- 'escape' => true,
79
- ));
80
-
81
- $this->addColumn('detail', array(
82
- 'header' => Mage::helper('review')->__('Review'),
83
- 'align' => 'left',
84
- 'index' => 'detail',
85
- 'filter_index' => 'rdt.detail',
86
- 'type' => 'text',
87
- //'truncate' => 50, // We remove the truncate to display the entire review details
88
- 'nl2br' => true,
89
- 'escape' => true,
90
- ));
91
-
92
- /**
93
- * Check is single store mode
94
- */
95
- if (!Mage::app()->isSingleStoreMode()) {
96
- $this->addColumn('visible_in', array(
97
- 'header' => Mage::helper('review')->__('Visible In'),
98
- 'index' => 'stores',
99
- 'type' => 'store',
100
- 'store_view' => true,
101
- ));
102
- }
103
-
104
- $this->addColumn('type', array(
105
- 'header' => Mage::helper('review')->__('Type'),
106
- 'type' => 'select',
107
- 'index' => 'type',
108
- 'filter' => 'adminhtml/review_grid_filter_type',
109
- 'renderer' => 'adminhtml/review_grid_renderer_type'
110
- ));
111
-
112
- $this->addColumn('name', array(
113
- 'header' => Mage::helper('review')->__('Product Name'),
114
- 'align' =>'left',
115
- 'type' => 'text',
116
- 'index' => 'name',
117
- 'escape' => true
118
- ));
119
-
120
- $this->addColumn('sku', array(
121
- 'header' => Mage::helper('review')->__('Product SKU'),
122
- 'align' => 'right',
123
- 'type' => 'text',
124
- 'width' => '50px',
125
- 'index' => 'sku',
126
- 'escape' => true
127
- ));
128
-
129
- $this->addColumn('action',
130
- array(
131
- 'header' => Mage::helper('adminhtml')->__('Action'),
132
- 'width' => '50px',
133
- 'type' => 'action',
134
- 'getter' => 'getReviewId',
135
- 'actions' => array(
136
- array(
137
- 'caption' => Mage::helper('adminhtml')->__('Edit'),
138
- 'url' => array(
139
- 'base'=>'*/catalog_product_review/edit',
140
- 'params'=> array(
141
- 'productId' => $this->getProductId(),
142
- 'customerId' => $this->getCustomerId(),
143
- 'ret' => ( Mage::registry('usePendingFilter') ) ? 'pending' : null
144
- )
145
- ),
146
- 'field' => 'id'
147
- )
148
- ),
149
- 'filter' => false,
150
- 'sortable' => false
151
- ));
152
-
153
- $this->addRssList('rss/catalog/review', Mage::helper('catalog')->__('Pending Reviews RSS'));
154
-
155
- /* Add CSV and Excel export */
156
- $this->addExportType('*/*/exportCsv', Mage::helper('review')->__('CSV'));
157
- $this->addExportType('*/*/exportExcel', Mage::helper('review')->__('Excel'));
158
-
159
- // We don't call the Mage_Adminhtml_Block_Review_Grid function as it would rewrite our columns
160
- return Mage_Adminhtml_Block_Widget_Grid::_prepareColumns();
161
- }
162
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/DigitalPianism/ExportReview/Model/Observer.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class DigitalPianism_ExportReview_Model_Observer
4
+ {
5
+ public function addMassExport(Varien_Event_Observer $observer)
6
+ {
7
+ $block = $observer->getEvent()->getBlock();
8
+
9
+ if($block instanceof Mage_Adminhtml_Block_Widget_Grid_Massaction
10
+ && $block->getRequest()->getControllerName() == 'catalog_product_review')
11
+ {
12
+ $block->addItem('exportreviewcsv', array(
13
+ 'label' => 'Export to CSV',
14
+ 'url' => $block->getUrl('exportreview/adminhtml_index/massCsvExport')
15
+ ));
16
+
17
+ $block->addItem('exportreviewwml', array(
18
+ 'label' => 'Export to XML',
19
+ 'url' => $block->getUrl('exportreview/adminhtml_index/massXmlExport')
20
+ ));
21
+ }
22
+ }
23
+ }
app/code/community/DigitalPianism/ExportReview/controllers/Adminhtml/IndexController.php ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Controller to add the CSV and XML export to the review grid
4
+ *
5
+ * Class DigitalPianism_ExportReview_Adminhtml_IndexController
6
+ */
7
+ class DigitalPianism_ExportReview_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action
8
+ {
9
+ public function massCsvExportAction()
10
+ {
11
+ $reviewIds = $this->getRequest()->getParam('reviews');
12
+ if (!is_array($reviewIds)) {
13
+ $this->_getSession()->addError($this->__('Please select review(s).'));
14
+ if( !Mage::registry('usePendingFilter') ) {
15
+ $this->_redirect('catalog_product_review/index');
16
+ }
17
+ else $this->_redirect('catalog_product_review/pending');
18
+ }
19
+ else {
20
+ //write headers to the csv file
21
+ $content = "review_id,created_at,title,nickname,detail,type,name,sku";
22
+ if( !Mage::registry('usePendingFilter') ) {
23
+ $content .= ",status";
24
+ }
25
+ $content .= "\n";
26
+ try {
27
+
28
+ if( !Mage::registry('usePendingFilter') ) {
29
+ $status = true;
30
+ }
31
+ else $status = false;
32
+
33
+ $attributesToSelect = array('review_id','created_at','title','nickname','detail','type','name','sku');
34
+
35
+ if ($status)
36
+ {
37
+ $attributesToSelect[] = 'status';
38
+ }
39
+
40
+ $model = Mage::getModel('review/review');
41
+ $collection = $model->getProductCollection();
42
+
43
+ $collection->addFieldToFilter('rt.review_id', array ('in' => array($reviewIds)))
44
+ ->addAttributeToSelect($attributesToSelect);
45
+
46
+ foreach ($collection as $review) {
47
+ $content .= "\"{$review->getReviewId()}\",\"{$review->getCreatedAt()}\",\"{$review->getTitle()}\",\"{$review->getNickname()}\",\"{$review->getDetail()}\",\"{$review->getType()}\",\"{$review->getName()}\",\"{$review->getSku()}\"";
48
+ if ($status)
49
+ {
50
+ $content .= ",\"{$review->getStatus()}\"";
51
+ }
52
+ $content .= "\n";
53
+ }
54
+ } catch (Exception $e) {
55
+ $this->_getSession()->addError($e->getMessage());
56
+ if( !Mage::registry('usePendingFilter') ) {
57
+ $this->_redirect('catalog_product_review/index');
58
+ }
59
+ else $this->_redirect('catalog_product_review/pending');
60
+ }
61
+ $this->_prepareDownloadResponse('export.csv', $content, 'text/csv');
62
+ }
63
+
64
+ }
65
+
66
+ public function massXmlExportAction()
67
+ {
68
+ $reviewIds = $this->getRequest()->getParam('reviews');
69
+ if (!is_array($reviewIds)) {
70
+ $this->_getSession()->addError($this->__('Please select review(s).'));
71
+ if( !Mage::registry('usePendingFilter') ) {
72
+ $this->_redirect('catalog_product_review/index');
73
+ }
74
+ else $this->_redirect('catalog_product_review/pending');
75
+ }
76
+ else {
77
+ //write headers to the csv file
78
+ $xml = '<?xml version="1.0" encoding="UTF-8"?>';
79
+ $xml.= '<items>';
80
+ try {
81
+
82
+ if( !Mage::registry('usePendingFilter') ) {
83
+ $status = true;
84
+ }
85
+ else $status = false;
86
+
87
+ $attributesToSelect = array('review_id','created_at','title','nickname','detail','type','name','sku');
88
+
89
+ if ($status)
90
+ {
91
+ $attributesToSelect[] = 'status';
92
+ }
93
+
94
+ $model = Mage::getModel('review/review');
95
+ $collection = $model->getProductCollection();
96
+
97
+ $collection->addFieldToFilter('rt.review_id', array ('in' => array($reviewIds)))
98
+ ->addAttributeToSelect($attributesToSelect);
99
+
100
+ foreach ($collection as $review) {
101
+ $xml.= $review->toXml();
102
+ }
103
+ } catch (Exception $e) {
104
+ $this->_getSession()->addError($e->getMessage());
105
+ if( !Mage::registry('usePendingFilter') ) {
106
+ $this->_redirect('catalog_product_review/index');
107
+ }
108
+ else $this->_redirect('catalog_product_review/pending');
109
+ }
110
+ $xml.= '</items>';
111
+ $this->_prepareDownloadResponse('export.xml', $xml, 'text/xml');
112
+ }
113
+ }
114
+ }
app/code/community/DigitalPianism/ExportReview/controllers/Catalog/Product/ReviewController.php DELETED
@@ -1,32 +0,0 @@
1
- <?php
2
-
3
- /*
4
- Controller to add the CSV and XML export for the reviews */
5
-
6
- include_once("Mage/Adminhtml/controllers/Catalog/Product/ReviewController.php");
7
-
8
- /**
9
- * Class DigitalPianism_ExportReview_Catalog_Product_ReviewController
10
- */
11
- class DigitalPianism_ExportReview_Catalog_Product_ReviewController extends Mage_Adminhtml_Catalog_Product_ReviewController
12
- {
13
- /**
14
- * Export order grid to CSV format
15
- */
16
- public function exportCsvAction()
17
- {
18
- $fileName = 'reviews.csv';
19
- $grid = $this->getLayout()->createBlock('adminhtml/review_grid');
20
- $this->_prepareDownloadResponse($fileName, $grid->getCsvFile());
21
- }
22
-
23
- /**
24
- * Export order grid to Excel XML format
25
- */
26
- public function exportExcelAction()
27
- {
28
- $fileName = 'reviews.xml';
29
- $grid = $this->getLayout()->createBlock('adminhtml/review_grid');
30
- $this->_prepareDownloadResponse($fileName, $grid->getExcelFile($fileName));
31
- }
32
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/DigitalPianism/ExportReview/etc/config.xml CHANGED
@@ -3,31 +3,43 @@
3
 
4
  <modules>
5
  <DigitalPianism_ExportReview>
6
- <version>0.0.3</version>
7
  </DigitalPianism_ExportReview>
8
  </modules>
9
 
10
  <global>
11
- <blocks>
12
- <adminhtml>
13
- <rewrite>
14
- <!-- Mage_Adminhtml_Block_Review_Grid -->
15
- <review_grid>DigitalPianism_ExportReview_Block_Review_Grid</review_grid>
16
- </rewrite>
17
- </adminhtml>
18
- </blocks>
19
  </global>
20
 
21
  <admin>
22
  <routers>
23
- <adminhtml>
 
24
  <args>
25
- <modules>
26
- <DigitalPianism_ExportReview before="Mage_Adminhtml">DigitalPianism_ExportReview</DigitalPianism_ExportReview>
27
- </modules>
28
  </args>
29
- </adminhtml>
30
  </routers>
31
  </admin>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
  </config>
3
 
4
  <modules>
5
  <DigitalPianism_ExportReview>
6
+ <version>0.1.0</version>
7
  </DigitalPianism_ExportReview>
8
  </modules>
9
 
10
  <global>
11
+ <models>
12
+ <exportreview>
13
+ <class>DigitalPianism_ExportReview_Model</class>
14
+ </exportreview>
15
+ </models>
 
 
 
16
  </global>
17
 
18
  <admin>
19
  <routers>
20
+ <exportreview>
21
+ <use>admin</use>
22
  <args>
23
+ <module>DigitalPianism_ExportReview</module>
24
+ <frontName>exportreview</frontName>
 
25
  </args>
26
+ </exportreview>
27
  </routers>
28
  </admin>
29
+
30
+ <adminhtml>
31
+ <events>
32
+ <!-- Before rendering event -->
33
+ <core_block_abstract_prepare_layout_before>
34
+ <observers>
35
+ <digitalpianism_exportreview_add>
36
+ <type>singleton</type>
37
+ <class>exportreview/observer</class>
38
+ <method>addMassExport</method>
39
+ </digitalpianism_exportreview_add>
40
+ </observers>
41
+ </core_block_abstract_prepare_layout_before>
42
+ </events>
43
+ </adminhtml>
44
 
45
  </config>
package.xml CHANGED
@@ -1,18 +1,18 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>DigitalPianism_ExportReview</name>
4
- <version>0.0.3</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Export Reviews to CSV/Excel for Magento.</summary>
10
  <description>This extension allows users to export customer reviews in both CSV / Excel types.</description>
11
- <notes>- PHPDoc for classes</notes>
12
  <authors><author><name>Digital Pianism</name><user>raphaelpetrini</user><email>raphael.petrini@free.fr</email></author></authors>
13
- <date>2014-12-19</date>
14
- <time>11:32:08</time>
15
- <contents><target name="magecommunity"><dir name="DigitalPianism"><dir name="ExportReview"><dir name="Block"><dir name="Review"><file name="Grid.php" hash="4ccfc2e6270ca92fbe4d927445c26940"/></dir></dir><dir name="controllers"><dir name="Catalog"><dir name="Product"><file name="ReviewController.php" hash="19ba923296d4d8a1f516c7335a6edc02"/></dir></dir></dir><dir name="etc"><file name="config.xml" hash="12dddc22447c83cb91b288a42dbc7cf8"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="DigitalPianism_ExportReview.xml" hash="4f5f0512a60878f5d25ffd2d12da2265"/></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>4.1.0</min><max>6.0.0</max></php></required></dependencies>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>DigitalPianism_ExportReview</name>
4
+ <version>0.1.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Export Reviews to CSV/Excel for Magento.</summary>
10
  <description>This extension allows users to export customer reviews in both CSV / Excel types.</description>
11
+ <notes>- Use of event observer instead of block rewrites</notes>
12
  <authors><author><name>Digital Pianism</name><user>raphaelpetrini</user><email>raphael.petrini@free.fr</email></author></authors>
13
+ <date>2015-07-28</date>
14
+ <time>11:30:12</time>
15
+ <contents><target name="magecommunity"><dir name="DigitalPianism"><dir name="ExportReview"><dir name="Model"><file name="Observer.php" hash="5371cf51d3e154983b57d1f01f245114"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="IndexController.php" hash="3b0bb10df0e031c6c2b111eb20886c2d"/></dir></dir><dir name="etc"><file name="config.xml" hash="b5befb9099167aa2a5877a31188af146"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="DigitalPianism_ExportReview.xml" hash="4f5f0512a60878f5d25ffd2d12da2265"/></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>4.1.0</min><max>6.0.0</max></php></required></dependencies>
18
  </package>