Passed
Push — 1.0 ( dbac97...74fb09 )
by Morven
04:14
created

CancelHandler::getI18nLabel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SilverCommerce\CatalogueAdmin\BulkManager;
4
5
use SilverStripe\Control\HTTPResponse;
6
use SilverStripe\Control\HTTPRequest;
7
use SilverStripe\Core\Convert;
8
use Colymba\BulkManager\BulkAction\Handler as GridFieldBulkActionHandler;
9
10
/**
11
 * A {@link GridFieldBulkActionHandler} for bulk cancelling records
12
 *
13
 * @author i-lateral (http://www.i-lateral.com)
14
 * @package orders-admin
15
 */
16
class CancelHandler extends GridFieldBulkActionHandler
17
{
18
    private static $url_segment = 'cancel';
0 ignored issues
show
introduced by
The private property $url_segment is not used, and could be removed.
Loading history...
19
20
    private static $allowed_actions = [
0 ignored issues
show
introduced by
The private property $allowed_actions is not used, and could be removed.
Loading history...
21
        'cancel'
22
    ];
23
24
    private static $url_handlers = [
0 ignored issues
show
introduced by
The private property $url_handlers is not used, and could be removed.
Loading history...
25
        "" => "cancel"
26
    ];
27
28
    /**
29
     * Front-end label for this handler's action
30
     * 
31
     * @var string
32
     */
33
    protected $label = 'Cancel';
34
35
    /**
36
     * Front-end icon path for this handler's action.
37
     * 
38
     * @var string
39
     */
40
    protected $icon = '';
41
42
    /**
43
     * Whether this handler should be called via an XHR from the front-end
44
     * 
45
     * @var boolean
46
     */
47
    protected $xhr = true;
48
    
49
    /**
50
     * Set to true is this handler will destroy any data.
51
     * A warning and confirmation will be shown on the front-end.
52
     * 
53
     * @var boolean
54
     */
55
    protected $destructive = false;
56
57
    /**
58
     * Return i18n localized front-end label
59
     *
60
     * @return array
61
     */
62
    public function getI18nLabel()
63
    {
64
        return _t('OrdersAdmin.Cancel', $this->getLabel());
65
    }
66
67
    public function cancel(HTTPRequest $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

67
    public function cancel(/** @scrutinizer ignore-unused */ HTTPRequest $request)

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

Loading history...
68
    {
69
        $ids = [];
70
71
        foreach ($this->getRecords() as $record) {
72
            array_push($ids, $record->ID);
73
            $record->markCanceled();
74
            $record->write();
75
        }
76
77
        $response = new HTTPResponse(Convert::raw2json([
78
            'done' => true,
79
            'records' => $ids
80
        ]));
81
82
        $response->addHeader('Content-Type', 'text/json');
83
84
        return $response;
85
    }
86
}
87