TicketAdmin   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 200
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 116
dl 0
loc 200
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A configureRoutes() 0 5 1
A configureDatagridFilters() 0 38 1
A configureShowFields() 0 28 1
A configureListFields() 0 42 1
A configureFormFields() 0 24 1
A getExportFields() 0 14 1
1
<?php
2
3
namespace Stfalcon\Bundle\EventBundle\Admin;
4
5
use Sonata\AdminBundle\Admin\AbstractAdmin;
6
use Sonata\AdminBundle\Datagrid\DatagridMapper;
7
use Sonata\AdminBundle\Datagrid\ListMapper;
8
use Sonata\AdminBundle\Form\FormMapper;
9
use Sonata\AdminBundle\Route\RouteCollection;
10
use Sonata\AdminBundle\Show\ShowMapper;
11
use Stfalcon\Bundle\EventBundle\Entity\Payment;
12
13
/**
14
 * Class TicketAdmin.
15
 */
16
final class TicketAdmin extends AbstractAdmin
17
{
18
    /**
19
     * Default Datagrid values.
20
     *
21
     * @var array
22
     */
23
    protected $datagridValues =
24
        [
25
            '_page' => 1,
26
            '_sort_order' => 'DESC',
27
            '_sort_by' => 'id',
28
        ];
29
30
    /**
31
     * @return array
32
     */
33
    public function getExportFields()
34
    {
35
        return [
36
            'id',
37
            'event',
38
            'user.fullname',
39
            'user.email',
40
            'user.phone',
41
            'amount',
42
            'amountWithoutDiscount',
43
            'payment',
44
            'createdAt',
45
            'updatedAt',
46
            'used',
47
        ];
48
    }
49
50
    /**
51
     * @param RouteCollection $collection
52
     */
53
    protected function configureRoutes(RouteCollection $collection)
54
    {
55
        $collection->remove('create');
56
        $collection->add('remove_paid_ticket_from_payment', $this->getRouterIdParameter().'/remove_paid_ticket_from_payment');
57
        $collection->add('download', $this->getRouterIdParameter().'/download');
58
    }
59
60
    /**
61
     * @param ListMapper $listMapper
62
     */
63
    protected function configureListFields(ListMapper $listMapper)
64
    {
65
        $listMapper
66
            ->addIdentifier('id')
67
            ->addIdentifier('event', null, ['label' => 'Событие'])
68
            ->add(
69
                'user',
70
                'string',
71
                [
72
                    'template' => 'StfalconEventBundle:Admin:user_link_field.html.twig',
73
                    'label' => 'Пользователь',
74
                ]
75
            )
76
            ->add('user.email', 'string', ['label' => 'E-Mail'])
77
            ->add('user.phone', 'string', ['label' => 'Тел.'])
78
            ->add(
79
                'amount',
80
                'money',
81
                [
82
                    'currency' => 'UAH',
83
                    'label' => 'Цена',
84
                ]
85
            )
86
            ->add(
87
                'amountWithoutDiscount',
88
                'money',
89
                [
90
                    'currency' => 'UAH',
91
                    'label' => 'Цена без скидки',
92
                ]
93
            )
94
            ->add('promoCode', null, ['label' => 'Промокод'])
95
            ->add('payment', null, ['label' => 'Оплата'])
96
            ->add('createdAt', null, ['label' => 'Дата создания'])
97
            ->add('updatedAt', null, ['label' => 'Дата изменения'])
98
            ->add('used', null, ['label' => 'Испол.'])
99
            ->add('_action', null, [
100
                'label' => 'Действие',
101
                'actions' => [
102
                    'removeTicket' => [
103
                        'ask_confirmation' => true,
104
                        'template' => 'StfalconEventBundle:Admin:list_action_remove_ticket.html.twig',
105
                    ],
106
                ],
107
            ])
108
        ;
109
    }
110
111
    /**
112
     * @param ShowMapper $filter
113
     */
114
    protected function configureShowFields(ShowMapper $filter)
115
    {
116
        $filter->add('id')
117
            ->add('event', null, ['label' => 'Событие'])
118
            ->add('user.fullname', null, ['label' => 'Имя пользователя'])
119
            ->add('user.email', 'string', ['label' => 'E-Mail'])
120
            ->add('user.phone', 'string', ['label' => 'Тел.'])
121
            ->add(
122
                'amount',
123
                'money',
124
                [
125
                    'currency' => 'UAH',
126
                    'label' => 'Цена',
127
                ]
128
            )
129
            ->add(
130
                'amountWithoutDiscount',
131
                'money',
132
                [
133
                    'currency' => 'UAH',
134
                    'label' => 'Цена без скидки',
135
                ]
136
            )
137
            ->add('promoCode', null, ['label' => 'Промокод'])
138
            ->add('payment', null, ['label' => 'Оплата'])
139
            ->add('createdAt', null, ['label' => 'Дата создания'])
140
            ->add('updatedAt', null, ['label' => 'Дата изменения'])
141
            ->add('used', null, ['label' => 'Использован']);
142
    }
143
144
    /**
145
     * @param DatagridMapper $datagridMapper
146
     */
147
    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
148
    {
149
        $datagridMapper
150
            ->add('id')
151
            ->add('event', null, ['label' => 'Событие'])
152
            ->add('user', null, ['label' => 'Пользователь'])
153
            ->add('user.email', null, ['label' => 'E-Mail'])
154
            ->add('user.phone', null, ['label' => 'Тел.'])
155
            ->add('used', null, ['label' => 'Использован'])
156
            ->add(
157
                'payment.status',
158
                'doctrine_orm_choice',
159
                [
160
                    'label' => 'Статус оплаты',
161
                    'field_options' => [
162
                        'choices' => [
163
                            'paid' => 'оплачено',
164
                            'pending' => 'ожидание',
165
                            'returned' => 'возращен',
166
                        ],
167
                    ],
168
                    'field_type' => 'choice',
169
                ]
170
            )
171
            ->add(
172
                'payment.gate',
173
                'doctrine_orm_choice',
174
                ['label' => 'Способ оплаты'],
175
                'choice',
176
                [
177
                    'choices' => [
178
                        'interkassa' => Payment::INTERKASSA_GATE,
179
                        'wayforpay' => Payment::WAYFORPAY_GATE,
180
                        'admin' => Payment::ADMIN_GATE,
181
                        'bonus' => Payment::BONUS_GATE,
182
                        'promocode' => Payment::PROMOCODE_GATE,
183
                    ],
184
                    'required' => false,
185
                ]
186
            );
187
    }
188
189
    /**
190
     * @param FormMapper $formMapper
191
     */
192
    protected function configureFormFields(FormMapper $formMapper)
193
    {
194
        $formMapper
195
            ->add('id', 'text', ['required' => false, 'label' => 'id', 'disabled' => true])
196
            ->add(
197
                'createdAt',
198
                'sonata_type_datetime_picker',
199
                [
200
                    'required' => false,
201
                    'label' => 'Создан',
202
                    'disabled' => true,
203
                ]
204
            )
205
            ->add('event', 'text', ['required' => true, 'label' => 'Событие', 'disabled' => true])
206
            ->add(
207
                'amount',
208
                'money',
209
                [
210
                    'currency' => 'UAH',
211
                    'label' => 'Цена',
212
                ]
213
            )
214
            ->add('payment', 'text', ['label' => 'Оплата', 'disabled' => true])
215
            ->add('used', null, ['label' => 'Использован', 'disabled' => true])
216
        ;
217
    }
218
}
219