GridFieldPrintAllInvoicesButton::getURLHandlers()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
nc 1
nop 1
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
0 ignored issues
show
Bug introduced by
There is no parameter named $exportColumns. Was it maybe removed?

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 $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
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
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
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)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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