OrderDataGrid::getIdentifier()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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
namespace WellCommerce\Bundle\OrderBundle\DataGrid;
13
14
use WellCommerce\Bundle\CoreBundle\DataGrid\AbstractDataGrid;
15
use WellCommerce\Component\DataGrid\Column\Column;
16
use WellCommerce\Component\DataGrid\Column\ColumnCollection;
17
use WellCommerce\Component\DataGrid\Column\Options\Appearance;
18
use WellCommerce\Component\DataGrid\Column\Options\Filter;
19
use WellCommerce\Component\DataGrid\Column\Options\Sorting;
20
use WellCommerce\Component\DataGrid\Configuration\EventHandler\CustomGroupEventHandler;
21
use WellCommerce\Component\DataGrid\Configuration\EventHandler\CustomRowEventHandler;
22
use WellCommerce\Component\DataGrid\Configuration\EventHandler\LoadedEventHandler;
23
use WellCommerce\Component\DataGrid\Configuration\EventHandler\ProcessEventHandler;
24
use WellCommerce\Component\DataGrid\Options\OptionsInterface;
25
26
/**
27
 * Class OrderDataGrid
28
 *
29
 * @author  Adam Piotrowski <[email protected]>
30
 */
31
class OrderDataGrid extends AbstractDataGrid
32
{
33
    /**
34
     * @var OrderStatusFilter
35
     */
36
    private $statuses;
37
    
38
    /**
39
     * @var PaymentMethodFilter
40
     */
41
    private $paymentMethods;
42
    
43
    /**
44
     * @var ShippingMethodFilter
45
     */
46
    private $shippingMethods;
47
    
48
    public function __construct(OrderStatusFilter $statuses, PaymentMethodFilter $paymentMethods, ShippingMethodFilter $shippingMethods)
49
    {
50
        $this->statuses        = $statuses;
51
        $this->paymentMethods  = $paymentMethods;
52
        $this->shippingMethods = $shippingMethods;
53
    }
54
    
55
    public function configureColumns(ColumnCollection $collection)
56
    {
57
        $collection->add(new Column([
58
            'id'         => 'id',
59
            'caption'    => 'order.label.id',
60
            'appearance' => new Appearance([
61
                'width'   => 40,
62
                'visible' => false,
63
                'align'   => Appearance::ALIGN_CENTER,
64
            ]),
65
            'filter'     => new Filter([
66
                'type' => Filter::FILTER_BETWEEN,
67
            ]),
68
        ]));
69
        
70
        $collection->add(new Column([
71
            'id'         => 'number',
72
            'caption'    => 'order.label.number',
73
            'filter'     => new Filter([
74
                'type' => Filter::FILTER_INPUT,
75
            ]),
76
            'sorting'    => new Sorting([
77
                'default_order' => Sorting::SORT_DIR_DESC,
78
            ]),
79
            'appearance' => new Appearance([
80
                'width' => 40,
81
                'align' => Appearance::ALIGN_CENTER,
82
            ]),
83
        ]));
84
        
85
        $collection->add(new Column([
86
            'id'         => 'client',
87
            'caption'    => 'order.label.client',
88
            'filter'     => new Filter([
89
                'type' => Filter::FILTER_INPUT,
90
            ]),
91
            'appearance' => new Appearance([
92
                'width' => 140,
93
                'align' => Appearance::ALIGN_LEFT,
94
            ]),
95
        ]));
96
        
97
        $collection->add(new Column([
98
            'id'         => 'products',
99
            'caption'    => 'order.label.products',
100
            'filter'     => new Filter([
101
                'type' => Filter::FILTER_INPUT,
102
            ]),
103
            'appearance' => new Appearance([
104
                'width' => 140,
105
                'align' => Appearance::ALIGN_LEFT,
106
            ]),
107
        ]));
108
        
109
        $collection->add(new Column([
110
            'id'         => 'productTotal',
111
            'caption'    => 'order.label.product_total.gross_price',
112
            'filter'     => new Filter([
113
                'type' => Filter::FILTER_BETWEEN,
114
            ]),
115
            'appearance' => new Appearance([
116
                'width' => 40,
117
                'align' => Appearance::ALIGN_CENTER,
118
            ]),
119
        ]));
120
        
121
        $collection->add(new Column([
122
            'id'         => 'orderTotal',
123
            'caption'    => 'order.label.order_total',
124
            'filter'     => new Filter([
125
                'type' => Filter::FILTER_BETWEEN,
126
            ]),
127
            'appearance' => new Appearance([
128
                'width' => 40,
129
                'align' => Appearance::ALIGN_CENTER,
130
            ]),
131
        ]));
132
        
133
        $collection->add(new Column([
134
            'id'         => 'currency',
135
            'caption'    => 'order.label.currency',
136
            'filter'     => new Filter([
137
                'type' => Filter::FILTER_BETWEEN,
138
            ]),
139
            'appearance' => new Appearance([
140
                'width'   => 40,
141
                'visible' => false,
142
                'align'   => Appearance::ALIGN_CENTER,
143
            ]),
144
        ]));
145
        
146
        $collection->add(new Column([
147
            'id'         => 'currentStatusName',
148
            'caption'    => 'order.label.current_status',
149
            'filter'     => new Filter([
150
                'type'            => Filter::FILTER_TREE,
151
                'filtered_column' => 'currentStatusId',
152
                'options'         => $this->statuses->getOptions(),
153
            ]),
154
            'appearance' => new Appearance([
155
                'width' => 60,
156
                'align' => Appearance::ALIGN_CENTER,
157
            ]),
158
        ]));
159
        
160
        $collection->add(new Column([
161
            'id'         => 'paymentMethodName',
162
            'caption'    => 'order.label.payment_method',
163
            'filter'     => new Filter([
164
                'type'            => Filter::FILTER_TREE,
165
                'filtered_column' => 'paymentMethodId',
166
                'options'         => $this->paymentMethods->getOptions(),
167
            ]),
168
            'appearance' => new Appearance([
169
                'width' => 60,
170
                'align' => Appearance::ALIGN_CENTER,
171
            ]),
172
        ]));
173
        
174
        $collection->add(new Column([
175
            'id'         => 'shippingMethodName',
176
            'caption'    => 'order.label.shipping_method',
177
            'filter'     => new Filter([
178
                'type'            => Filter::FILTER_TREE,
179
                'filtered_column' => 'shippingMethodId',
180
                'options'         => $this->shippingMethods->getOptions(),
181
            ]),
182
            'appearance' => new Appearance([
183
                'width' => 60,
184
                'align' => Appearance::ALIGN_CENTER,
185
            ]),
186
        ]));
187
        
188
        $collection->add(new Column([
189
            'id'         => 'createdAt',
190
            'caption'    => 'order.label.created_at',
191
            'filter'     => new Filter([
192
                'type' => Filter::FILTER_BETWEEN,
193
            ]),
194
            'appearance' => new Appearance([
195
                'width' => 40,
196
                'align' => Appearance::ALIGN_CENTER,
197
            ]),
198
        ]));
199
    }
200
    
201
    public function configureOptions(OptionsInterface $options)
202
    {
203
        parent::configureOptions($options);
204
        
205
        $options->getMechanics()->set('default_sorting', 'createdAt');
206
        
207
        $eventHandlers = $options->getEventHandlers();
208
        
209
        $eventHandlers->add(new ProcessEventHandler([
210
            'function' => $this->getJavascriptFunctionName('process'),
211
        ]));
212
        
213
        $eventHandlers->add(new LoadedEventHandler([
214
            'function' => $this->getJavascriptFunctionName('loaded'),
215
        ]));
216
        
217
        $eventHandlers->add(new CustomGroupEventHandler([
218
            'group_action' => $this->getJavascriptFunctionName('changeStatusMulti'),
219
        ]));
220
        
221
        $eventHandlers->add(new CustomRowEventHandler([
222
            'function'      => $this->getJavascriptFunctionName('changeStatus'),
223
            'function_name' => 'changeStatus',
224
            'row_action'    => 'action_changeStatus',
225
        ]));
226
    }
227
    
228
    public function getIdentifier(): string
229
    {
230
        return 'order';
231
    }
232
}
233