|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Adds an "Export list" button to the bottom of a {@link GridField}. |
|
5
|
|
|
* |
|
6
|
|
|
* @package forms |
|
7
|
|
|
* @subpackage fields-gridfield |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
class GridFieldPrintAllInvoicesButton implements GridField_HTMLProvider, GridField_ActionProvider, GridField_URLHandler |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* |
|
14
|
|
|
* @config |
|
15
|
|
|
* @var int |
|
16
|
|
|
*/ |
|
17
|
|
|
private static $invoice_bulk_printing_limit = 30; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* HTML Fragment to render the field. |
|
21
|
|
|
* |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $targetFragment; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @param string $targetFragment The HTML fragment to write the button into |
|
28
|
|
|
* @param array $exportColumns The columns to include in the export |
|
|
|
|
|
|
29
|
|
|
*/ |
|
30
|
|
|
public function __construct($targetFragment = "after") |
|
31
|
|
|
{ |
|
32
|
|
|
$this->targetFragment = $targetFragment; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Place the export button in a <p> tag below the field |
|
37
|
|
|
*/ |
|
38
|
|
|
public function getHTMLFragments($gridField) |
|
39
|
|
|
{ |
|
40
|
|
|
$button = new GridField_FormAction( |
|
41
|
|
|
$gridField, |
|
42
|
|
|
'printallinvoices', |
|
43
|
|
|
_t('TableListField.PRINT_ALL_INVOICES', 'Print all Invoices'), |
|
44
|
|
|
'printallinvoices', |
|
45
|
|
|
null |
|
|
|
|
|
|
46
|
|
|
); |
|
47
|
|
|
$button->setAttribute('data-icon', 'grid_print'); |
|
48
|
|
|
$button->addExtraClass('no-ajax action_print_all_invoices'); |
|
49
|
|
|
$button->setForm($gridField->getForm()); |
|
50
|
|
|
return array( |
|
51
|
|
|
$this->targetFragment => '<p class="grid-print-button">' . $button->Field() . '</p>', |
|
52
|
|
|
); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* export is an action button |
|
57
|
|
|
*/ |
|
58
|
|
|
public function getActions($gridField) |
|
59
|
|
|
{ |
|
60
|
|
|
return array('printallinvoices'); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function handleAction(GridField $gridField, $actionName, $arguments, $data) |
|
64
|
|
|
{ |
|
65
|
|
|
if ($actionName == 'printallinvoices') { |
|
66
|
|
|
return $this->handlePrint($gridField); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* it is also a URL |
|
72
|
|
|
*/ |
|
73
|
|
|
public function getURLHandlers($gridField) |
|
74
|
|
|
{ |
|
75
|
|
|
return array( |
|
76
|
|
|
'printallinvoices' => 'handlePrint', |
|
77
|
|
|
); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Handle the print, for both the action button and the URL |
|
82
|
|
|
*/ |
|
83
|
|
|
public function handlePrint($gridField, $request = null) |
|
|
|
|
|
|
84
|
|
|
{ |
|
85
|
|
|
$limit = Config::inst()->get('GridFieldPrintAllInvoicesButton', 'invoice_bulk_printing_limit'); |
|
86
|
|
|
$list = $gridField->getList()->limit($limit); |
|
87
|
|
|
$gridField->setList($list); |
|
88
|
|
|
$al = ArrayList::create(); |
|
89
|
|
|
foreach ($list as $order) { |
|
90
|
|
|
$al->push($order); |
|
91
|
|
|
} |
|
92
|
|
|
Requirements::clear(); |
|
93
|
|
|
Config::inst()->update('SSViewer', 'theme_enabled', true); |
|
94
|
|
|
Requirements::themedCSS('OrderReport', 'ecommerce'); |
|
95
|
|
|
Requirements::themedCSS('Order_Invoice', 'ecommerce'); |
|
96
|
|
|
Requirements::themedCSS('Order_Invoice_Print_Only', 'ecommerce', 'print'); |
|
97
|
|
|
$curr = Controller::curr(); |
|
98
|
|
|
$curr->Orders = $al; |
|
99
|
|
|
return $curr->renderWith('PrintAllInvoices'); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.