6
6
7
7
namespace Magento \Backend \Block \Widget \Grid ;
8
8
9
- use Magento \Backend \Block \Template \Context ;
10
- use Magento \Backend \Block \Widget ;
11
- use Magento \Backend \Block \Widget \Button ;
12
9
use Magento \Framework \App \Filesystem \DirectoryList ;
13
- use Magento \Framework \Convert \Excel ;
14
- use Magento \Framework \Data \Collection ;
15
- use Magento \Framework \Data \CollectionFactory ;
16
- use Magento \Framework \DataObject ;
17
- use Magento \Framework \Exception \FileSystemException ;
18
- use Magento \Framework \Exception \LocalizedException ;
19
- use Magento \Framework \Filesystem \Directory \WriteInterface ;
20
- use Magento \Framework \Filesystem \File \WriteInterface as FileWriteInterface ;
21
10
22
11
/**
23
12
* Class Export for exporting grid data as CSV file or MS Excel 2003 XML Document file
27
16
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
28
17
* @since 100.0.2
29
18
*/
30
- class Export extends Widget implements ExportInterface
19
+ class Export extends \ Magento \ Backend \ Block \ Widget implements \ Magento \ Backend \ Block \ Widget \ Grid \ ExportInterface
31
20
{
32
21
/**
33
22
* Grid export types
34
23
*
35
- * @var DataObject[]
24
+ * @var \Magento\Framework\ DataObject[]
36
25
*/
37
26
protected $ _exportTypes = [];
38
27
@@ -51,12 +40,12 @@ class Export extends Widget implements ExportInterface
51
40
protected $ _template = "Magento_Backend::widget/grid/export.phtml " ;
52
41
53
42
/**
54
- * @var CollectionFactory
43
+ * @var \Magento\Framework\Data\ CollectionFactory
55
44
*/
56
45
protected $ _collectionFactory ;
57
46
58
47
/**
59
- * @var WriteInterface
48
+ * @var \Magento\Framework\Filesystem\Directory\ WriteInterface
60
49
*/
61
50
protected $ _directory ;
62
51
@@ -68,13 +57,13 @@ class Export extends Widget implements ExportInterface
68
57
protected $ _path = 'export ' ;
69
58
70
59
/**
71
- * @param Context $context
72
- * @param CollectionFactory $collectionFactory
60
+ * @param \Magento\Backend\Block\Template\ Context $context
61
+ * @param \Magento\Framework\Data\ CollectionFactory $collectionFactory
73
62
* @param array $data
74
63
*/
75
64
public function __construct (
76
- Context $ context ,
77
- CollectionFactory $ collectionFactory ,
65
+ \ Magento \ Backend \ Block \ Template \ Context $ context ,
66
+ \ Magento \ Framework \ Data \ CollectionFactory $ collectionFactory ,
78
67
array $ data = []
79
68
) {
80
69
$ this ->_collectionFactory = $ collectionFactory ;
@@ -85,15 +74,15 @@ public function __construct(
85
74
* Internal constructor, that is called from real constructor
86
75
*
87
76
* @return void
88
- * @throws LocalizedException
77
+ * @throws \Magento\Framework\Exception\ LocalizedException
89
78
*/
90
79
protected function _construct ()
91
80
{
92
81
parent ::_construct ();
93
82
if ($ this ->hasData ('exportTypes ' )) {
94
83
foreach ($ this ->getData ('exportTypes ' ) as $ type ) {
95
84
if (!isset ($ type ['urlPath ' ]) || !isset ($ type ['label ' ])) {
96
- throw new LocalizedException (
85
+ throw new \ Magento \ Framework \ Exception \ LocalizedException (
97
86
__ ('Invalid export type supplied for grid export block ' )
98
87
);
99
88
}
@@ -106,7 +95,7 @@ protected function _construct()
106
95
/**
107
96
* Retrieve grid columns
108
97
*
109
- * @return Column[]
98
+ * @return \Magento\Backend\Block\Widget\Grid\ Column[]
110
99
*/
111
100
protected function _getColumns ()
112
101
{
@@ -116,7 +105,7 @@ protected function _getColumns()
116
105
/**
117
106
* Retrieve totals
118
107
*
119
- * @return DataObject
108
+ * @return \Magento\Framework\ DataObject
120
109
*/
121
110
protected function _getTotals ()
122
111
{
@@ -137,7 +126,7 @@ public function getCountTotals()
137
126
/**
138
127
* Get collection object
139
128
*
140
- * @return Collection
129
+ * @return \Magento\Framework\Data\ Collection
141
130
*/
142
131
protected function _getCollection ()
143
132
{
@@ -147,7 +136,7 @@ protected function _getCollection()
147
136
/**
148
137
* Retrieve grid export types
149
138
*
150
- * @return DataObject[]|false
139
+ * @return \Magento\Framework\ DataObject[]|false
151
140
*/
152
141
public function getExportTypes ()
153
142
{
@@ -168,14 +157,13 @@ public function getId()
168
157
* Prepare export button
169
158
*
170
159
* @return $this
171
- * @throws LocalizedException
172
160
*/
173
161
protected function _prepareLayout ()
174
162
{
175
163
$ this ->setChild (
176
164
'export_button ' ,
177
165
$ this ->getLayout ()->createBlock (
178
- Button::class
166
+ \ Magento \ Backend \ Block \ Widget \ Button::class
179
167
)->setData (
180
168
[
181
169
'label ' => __ ('Export ' ),
@@ -206,7 +194,7 @@ public function getExportButtonHtml()
206
194
*/
207
195
public function addExportType ($ url , $ label )
208
196
{
209
- $ this ->_exportTypes [] = new DataObject (
197
+ $ this ->_exportTypes [] = new \ Magento \ Framework \ DataObject (
210
198
['url ' => $ this ->getUrl ($ url , ['_current ' => true ]), 'label ' => $ label ]
211
199
);
212
200
return $ this ;
@@ -217,7 +205,6 @@ public function addExportType($url, $label)
217
205
*
218
206
* @param array $fileData
219
207
* @return string
220
- * @throws FileSystemException
221
208
*/
222
209
protected function _getFileContainerContent (array $ fileData )
223
210
{
@@ -268,7 +255,7 @@ protected function _getExportTotals()
268
255
*/
269
256
public function _exportIterateCollection ($ callback , array $ args )
270
257
{
271
- /** @var $originalCollection Collection */
258
+ /** @var $originalCollection \Magento\Framework\Data\ Collection */
272
259
$ originalCollection = $ this ->getParentBlock ()->getPreparedCollection ();
273
260
$ count = null ;
274
261
$ page = 1 ;
@@ -304,14 +291,13 @@ public function _exportIterateCollection($callback, array $args)
304
291
/**
305
292
* Write item data to csv export file
306
293
*
307
- * @param DataObject $item
308
- * @param FileWriteInterface $stream
294
+ * @param \Magento\Framework\ DataObject $item
295
+ * @param \Magento\Framework\Filesystem\File\WriteInterface $stream
309
296
* @return void
310
- * @throws FileSystemException
311
297
*/
312
298
protected function _exportCsvItem (
313
- DataObject $ item ,
314
- FileWriteInterface $ stream
299
+ \ Magento \ Framework \ DataObject $ item ,
300
+ \ Magento \ Framework \ Filesystem \ File \ WriteInterface $ stream
315
301
) {
316
302
$ row = [];
317
303
foreach ($ this ->_getColumns () as $ column ) {
@@ -357,6 +343,7 @@ public function getCsvFile()
357
343
* Retrieve Grid data as CSV
358
344
*
359
345
* @return string
346
+ * @SuppressWarnings(PHPMD.CyclomaticComplexity)
360
347
*/
361
348
public function getCsv ()
362
349
{
@@ -432,10 +419,10 @@ public function getXml()
432
419
/**
433
420
* Get a row data of the particular columns
434
421
*
435
- * @param DataObject $data
422
+ * @param \Magento\Framework\ DataObject $data
436
423
* @return string[]
437
424
*/
438
- public function getRowRecord (DataObject $ data )
425
+ public function getRowRecord (\ Magento \ Framework \ DataObject $ data )
439
426
{
440
427
$ row = [];
441
428
foreach ($ this ->_getColumns () as $ column ) {
@@ -458,7 +445,7 @@ public function getExcelFile($sheetName = '')
458
445
{
459
446
$ collection = $ this ->_getPreparedCollection ();
460
447
461
- $ convert = new Excel ($ collection ->getIterator (), [$ this , 'getRowRecord ' ]);
448
+ $ convert = new \ Magento \ Framework \ Convert \ Excel ($ collection ->getIterator (), [$ this , 'getRowRecord ' ]);
462
449
463
450
$ name = hash ('sha256 ' , microtime ());
464
451
$ file = $ this ->_path . '/ ' . $ name . '.xml ' ;
@@ -521,30 +508,30 @@ public function getExcel()
521
508
$ data [] = $ row ;
522
509
}
523
510
524
- $ convert = new Excel (new \ArrayIterator ($ data ));
511
+ $ convert = new \ Magento \ Framework \ Convert \ Excel (new \ArrayIterator ($ data ));
525
512
return $ convert ->convert ('single_sheet ' );
526
513
}
527
514
528
515
/**
529
516
* Reformat base collection into collection without sub-collection in items
530
517
*
531
- * @param Collection $baseCollection
532
- * @return Collection
518
+ * @param \Magento\Framework\Data\ Collection $baseCollection
519
+ * @return \Magento\Framework\Data\ Collection
533
520
*/
534
- protected function _getRowCollection (Collection $ baseCollection = null )
521
+ protected function _getRowCollection (\ Magento \ Framework \ Data \ Collection $ baseCollection = null )
535
522
{
536
523
if (null === $ baseCollection ) {
537
524
$ baseCollection = $ this ->getParentBlock ()->getPreparedCollection ();
538
525
}
539
526
$ collection = $ this ->_collectionFactory ->create ();
540
527
541
- /** @var $item DataObject */
528
+ /** @var $item \Magento\Framework\ DataObject */
542
529
foreach ($ baseCollection as $ item ) {
543
530
if ($ item ->getIsEmpty ()) {
544
531
continue ;
545
532
}
546
533
if ($ item ->hasChildren () && count ($ item ->getChildren ()) > 0 ) {
547
- /** @var $subItem DataObject */
534
+ /** @var $subItem \Magento\Framework\ DataObject */
548
535
foreach ($ item ->getChildren () as $ subItem ) {
549
536
$ tmpItem = clone $ item ;
550
537
$ tmpItem ->unsChildren ();
@@ -562,11 +549,11 @@ protected function _getRowCollection(Collection $baseCollection = null)
562
549
/**
563
550
* Return prepared collection as row collection with additional conditions
564
551
*
565
- * @return Collection
552
+ * @return \Magento\Framework\Data\ Collection
566
553
*/
567
554
public function _getPreparedCollection ()
568
555
{
569
- /** @var $collection Collection */
556
+ /** @var $collection \Magento\Framework\Data\ Collection */
570
557
$ collection = $ this ->getParentBlock ()->getPreparedCollection ();
571
558
$ collection ->setPageSize (0 );
572
559
$ collection ->load ();
0 commit comments