Completed
Push — master ( 63d470...84e35a )
by Adam
18:27
created

InvoiceDataGrid::configureOptions()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 16
nc 1
nop 1
1
<?php
2
/*
3
 * WellCommerce Open-Source E-Commerce Platform
4
 *
5
 * This file is part of the WellCommerce package.
6
 *
7
 * (c) Adam Piotrowski <[email protected]>
8
 *
9
 * For the full copyright and license information,
10
 * please view the LICENSE file that was distributed with this source code.
11
 */
12
13
namespace WellCommerce\Bundle\InvoiceBundle\DataGrid;
14
15
use WellCommerce\Bundle\CoreBundle\DataGrid\AbstractDataGrid;
16
use WellCommerce\Component\DataGrid\Column\Column;
17
use WellCommerce\Component\DataGrid\Column\ColumnCollection;
18
use WellCommerce\Component\DataGrid\Column\Options\Appearance;
19
use WellCommerce\Component\DataGrid\Column\Options\Filter;
20
use WellCommerce\Component\DataGrid\Column\Options\Sorting;
21
use WellCommerce\Component\DataGrid\Configuration\EventHandler\ClickRowEventHandler;
22
use WellCommerce\Component\DataGrid\Configuration\EventHandler\DeleteGroupEventHandler;
23
use WellCommerce\Component\DataGrid\Configuration\EventHandler\DeleteRowEventHandler;
24
use WellCommerce\Component\DataGrid\Configuration\EventHandler\LoadEventHandler;
25
use WellCommerce\Component\DataGrid\DataGridInterface;
26
use WellCommerce\Component\DataGrid\Options\OptionsInterface;
27
28
/**
29
 * Class InvoiceDataGrid
30
 *
31
 * @author  Adam Piotrowski <[email protected]>
32
 */
33
class InvoiceDataGrid extends AbstractDataGrid
34
{
35
    public function configureColumns(ColumnCollection $collection)
36
    {
37
        $collection->add(new Column([
38
            'id'         => 'id',
39
            'caption'    => 'invoice.label.id',
40
            'appearance' => new Appearance([
41
                'width'   => 40,
42
                'visible' => false,
43
                'align'   => Appearance::ALIGN_CENTER,
44
            ]),
45
            'filter'     => new Filter([
46
                'type' => Filter::FILTER_BETWEEN,
47
            ]),
48
        ]));
49
        
50
        $collection->add(new Column([
51
            'id'         => 'number',
52
            'caption'    => 'invoice.label.number',
53
            'filter'     => new Filter([
54
                'type' => Filter::FILTER_INPUT,
55
            ]),
56
            'sorting'    => new Sorting([
57
                'default_order' => Sorting::SORT_DIR_DESC,
58
            ]),
59
            'appearance' => new Appearance([
60
                'width' => 40,
61
                'align' => Appearance::ALIGN_CENTER,
62
            ]),
63
        ]));
64
        
65
        $collection->add(new Column([
66
            'id'         => 'date',
67
            'caption'    => 'invoice.label.date',
68
            'filter'     => new Filter([
69
                'type' => Filter::FILTER_BETWEEN,
70
            ]),
71
            'appearance' => new Appearance([
72
                'width' => 40,
73
                'align' => Appearance::ALIGN_CENTER,
74
            ]),
75
        ]));
76
        
77
        $collection->add(new Column([
78
            'id'         => 'amountPaid',
79
            'caption'    => 'invoice.label.amount_paid',
80
            'filter'     => new Filter([
81
                'type' => Filter::FILTER_BETWEEN,
82
            ]),
83
            'appearance' => new Appearance([
84
                'width' => 40,
85
                'align' => Appearance::ALIGN_CENTER,
86
            ]),
87
        ]));
88
        
89
        $collection->add(new Column([
90
            'id'         => 'amountDue',
91
            'caption'    => 'invoice.label.amount_due',
92
            'filter'     => new Filter([
93
                'type' => Filter::FILTER_BETWEEN,
94
            ]),
95
            'appearance' => new Appearance([
96
                'width' => 40,
97
                'align' => Appearance::ALIGN_CENTER,
98
            ]),
99
        ]));
100
        
101
        $collection->add(new Column([
102
            'id'         => 'dueDate',
103
            'caption'    => 'invoice.label.due_date',
104
            'filter'     => new Filter([
105
                'type' => Filter::FILTER_BETWEEN,
106
            ]),
107
            'appearance' => new Appearance([
108
                'width' => 40,
109
                'align' => Appearance::ALIGN_CENTER,
110
            ]),
111
        ]));
112
        
113
        $collection->add(new Column([
114
            'id'         => 'createdAt',
115
            'caption'    => 'invoice.label.created_at',
116
            'filter'     => new Filter([
117
                'type' => Filter::FILTER_BETWEEN,
118
            ]),
119
            'appearance' => new Appearance([
120
                'width' => 40,
121
                'align' => Appearance::ALIGN_CENTER,
122
            ]),
123
        ]));
124
    }
125
    
126
    public function configureOptions(OptionsInterface $options)
127
    {
128
        $eventHandlers = $options->getEventHandlers();
129
        
130
        $eventHandlers->add(new LoadEventHandler([
131
            'function' => $this->getJavascriptFunctionName('load'),
132
            'route'    => $this->getActionUrl('grid'),
133
        ]));
134
        
135
        $eventHandlers->add(new ClickRowEventHandler([
136
            'function' => $this->getJavascriptFunctionName('click'),
137
            'route'    => $this->getActionUrl('edit'),
138
        ]));
139
        
140
        $eventHandlers->add(new DeleteRowEventHandler([
141
            'function'   => $this->getJavascriptFunctionName('delete'),
142
            'row_action' => DataGridInterface::ACTION_DELETE,
143
            'route'      => $this->getActionUrl('delete'),
144
        ]));
145
        
146
        $eventHandlers->add(new DeleteGroupEventHandler([
147
            'function'     => $this->getJavascriptFunctionName('delete_group'),
148
            'group_action' => DataGridInterface::ACTION_DELETE_GROUP,
149
            'route'        => $this->getActionUrl('delete_group'),
150
        ]));
151
    }
152
    
153
    public function getIdentifier(): string
154
    {
155
        return 'invoice';
156
    }
157
}
158