1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace VideoGamesRecords\CoreBundle\Admin; |
6
|
|
|
|
7
|
|
|
use Sonata\AdminBundle\Admin\AbstractAdmin; |
8
|
|
|
use Sonata\AdminBundle\Datagrid\DatagridMapper; |
9
|
|
|
use Sonata\AdminBundle\Datagrid\ListMapper; |
10
|
|
|
use Sonata\AdminBundle\Form\FormMapper; |
11
|
|
|
use Sonata\AdminBundle\Form\Type\ModelAutocompleteType; |
12
|
|
|
use Sonata\AdminBundle\Form\Type\ModelListType; |
13
|
|
|
use Sonata\AdminBundle\Route\RouteCollectionInterface; |
14
|
|
|
use Sonata\AdminBundle\Show\ShowMapper; |
15
|
|
|
use Sonata\DoctrineORMAdminBundle\Filter\ChoiceFilter; |
16
|
|
|
use Sonata\DoctrineORMAdminBundle\Filter\ModelFilter; |
17
|
|
|
use Sonata\Form\Type\CollectionType; |
18
|
|
|
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; |
19
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; |
20
|
|
|
use Symfony\Component\Form\Extension\Core\Type\DateType; |
21
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType; |
22
|
|
|
use VideoGamesRecords\CoreBundle\Contracts\SecurityInterface; |
23
|
|
|
use VideoGamesRecords\CoreBundle\Traits\Accessor\SetSecurity; |
24
|
|
|
use VideoGamesRecords\CoreBundle\ValueObject\GameStatus; |
25
|
|
|
|
26
|
|
|
class GameAdmin extends AbstractAdmin implements SecurityInterface |
27
|
|
|
{ |
28
|
|
|
use SetSecurity; |
29
|
|
|
|
30
|
|
|
protected $baseRouteName = 'vgrcorebundle_admin_game'; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param RouteCollectionInterface $collection |
34
|
|
|
*/ |
35
|
|
|
protected function configureRoutes(RouteCollectionInterface $collection): void |
36
|
|
|
{ |
37
|
|
|
parent::configureRoutes($collection); |
38
|
|
|
$collection |
39
|
|
|
->add('copy', $this->getRouterIdParameter() . '/copy') |
40
|
|
|
->add('maj', $this->getRouterIdParameter() . '/maj') |
41
|
|
|
->add('set-video-proof-only', $this->getRouterIdParameter() . '/set-video-proof-only') |
42
|
|
|
->add('import-csv', $this->getRouterIdParameter() . '/import-csv'); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function configureActionButtons(array $buttonList, string $action, ?object $object = null): array |
46
|
|
|
{ |
47
|
|
|
if (in_array($action, ['show', 'edit', 'acl']) && $object) { |
48
|
|
|
if ($this->getSecurity()->isGranted(self::ROLE_SUPER_ADMIN)) { |
49
|
|
|
$buttonList['copy'] = [ |
50
|
|
|
'template' => '@VideoGamesRecordsCore/Admin/ActionButton/btn.copy.html.twig', |
51
|
|
|
]; |
52
|
|
|
} |
53
|
|
|
$buttonList['set-video-proof-only'] = [ |
54
|
|
|
'template' => '@VideoGamesRecordsCore/Admin/ActionButton/btn.set_video_proof_only.html.twig', |
55
|
|
|
]; |
56
|
|
|
$buttonList['add-group'] = [ |
57
|
|
|
'template' => '@VideoGamesRecordsCore/Admin/Object/Game/btn.add_group.html.twig', |
58
|
|
|
]; |
59
|
|
|
} |
60
|
|
|
return $buttonList; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param array<mixed> $sortValues |
65
|
|
|
* @return void |
66
|
|
|
*/ |
67
|
|
|
protected function configureDefaultSortValues(array &$sortValues): void |
68
|
|
|
{ |
69
|
|
|
$sortValues['_page'] = 1; |
70
|
|
|
$sortValues['_sort_order'] = 'DESC'; |
71
|
|
|
$sortValues['_sort_by'] = 'id'; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return string[] |
76
|
|
|
*/ |
77
|
|
|
protected function configureExportFields(): array |
78
|
|
|
{ |
79
|
|
|
return ['id', 'libGameEn', 'libGameFr', 'serie', 'status', 'picture', 'platforms']; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param FormMapper $form |
85
|
|
|
*/ |
86
|
|
|
protected function configureFormFields(FormMapper $form): void |
87
|
|
|
{ |
88
|
|
|
$form |
89
|
|
|
->add('serie', ModelAutocompleteType::class, [ |
90
|
|
|
'property' => 'libSerie', |
91
|
|
|
'label' => 'label.serie', |
92
|
|
|
'required' => false, |
93
|
|
|
]) |
94
|
|
|
->add('libGameEn', TextType::class, [ |
95
|
|
|
'label' => 'label.name.en', |
96
|
|
|
'required' => true, |
97
|
|
|
]) |
98
|
|
|
->add('libGameFr', TextType::class, [ |
99
|
|
|
'label' => 'label.name.fr', |
100
|
|
|
'required' => false, |
101
|
|
|
]) |
102
|
|
|
->add('rules', null, ['required' => false, 'expanded' => false, 'label' => 'label.rules']) |
103
|
|
|
->add('badge', ModelListType::class, [ |
104
|
|
|
'btn_add' => true, |
105
|
|
|
'btn_list' => true, |
106
|
|
|
'btn_edit' => false, |
107
|
|
|
'btn_delete' => false, |
108
|
|
|
'btn_catalogue' => true, |
109
|
|
|
'label' => 'label.badge', |
110
|
|
|
]) |
111
|
|
|
->add('forum', ModelListType::class, [ |
112
|
|
|
'btn_add' => true, |
113
|
|
|
'btn_list' => true, |
114
|
|
|
'btn_edit' => false, |
115
|
|
|
'btn_delete' => false, |
116
|
|
|
'btn_catalogue' => true, |
117
|
|
|
'label' => 'label.forum', |
118
|
|
|
]) |
119
|
|
|
->add('picture', TextType::class, [ |
120
|
|
|
'label' => 'label.picture', |
121
|
|
|
'required' => false, |
122
|
|
|
]) |
123
|
|
|
->add('downloadUrl', TextType::class, [ |
124
|
|
|
'label' => 'label.downloadUrl', |
125
|
|
|
'required' => false, |
126
|
|
|
]) |
127
|
|
|
->add( |
128
|
|
|
'status', |
129
|
|
|
ChoiceType::class, |
130
|
|
|
[ |
131
|
|
|
'label' => 'label.status', |
132
|
|
|
'choices' => GameStatus::getStatusChoices(), |
133
|
|
|
] |
134
|
|
|
) |
135
|
|
|
->add('publishedAt', DateType::class, [ |
136
|
|
|
'label' => 'label.publishedAt', |
137
|
|
|
'required' => false, |
138
|
|
|
'years' => range(2004, date('Y')) |
139
|
|
|
]) |
140
|
|
|
->add('isRank', CheckboxType::class, [ |
141
|
|
|
'label' => 'label.boolRanking', |
142
|
|
|
'required' => false, |
143
|
|
|
]) |
144
|
|
|
->add( |
145
|
|
|
'platforms', |
146
|
|
|
null, |
147
|
|
|
[ |
148
|
|
|
'label' => 'label.platforms', |
149
|
|
|
'required' => false, |
150
|
|
|
'expanded' => false, |
151
|
|
|
'query_builder' => |
152
|
|
|
function ($er) { |
153
|
|
|
$qb = $er->createQueryBuilder('p'); |
154
|
|
|
$qb->orderBy('p.libPlatform', 'ASC'); |
155
|
|
|
return $qb; |
156
|
|
|
} |
157
|
|
|
] |
158
|
|
|
) |
159
|
|
|
->end() |
160
|
|
|
->with('label.groups') |
161
|
|
|
->add( |
162
|
|
|
'groups', |
163
|
|
|
CollectionType::class, |
164
|
|
|
array( |
165
|
|
|
'label' => 'label.groups', |
166
|
|
|
'by_reference' => false, |
167
|
|
|
'type_options' => array( |
168
|
|
|
// Prevents the "Delete" option from being displayed |
169
|
|
|
'delete' => true, |
170
|
|
|
'delete_options' => array( |
171
|
|
|
// You may otherwise choose to put the field but hide it |
172
|
|
|
'type' => CheckboxType::class, |
173
|
|
|
// In that case, you need to fill in the options as well |
174
|
|
|
'type_options' => array( |
175
|
|
|
'mapped' => false, |
176
|
|
|
'required' => false, |
177
|
|
|
) |
178
|
|
|
) |
179
|
|
|
), |
180
|
|
|
), |
181
|
|
|
array( |
182
|
|
|
'edit' => 'inline', |
183
|
|
|
'inline' => 'table', |
184
|
|
|
) |
185
|
|
|
) |
186
|
|
|
->end(); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* @param DatagridMapper $filter |
191
|
|
|
*/ |
192
|
|
|
protected function configureDatagridFilters(DatagridMapper $filter): void |
193
|
|
|
{ |
194
|
|
|
$filter |
195
|
|
|
->add('id', null, ['label' => 'label.id']) |
196
|
|
|
->add('serie', ModelFilter::class, [ |
197
|
|
|
'field_type' => ModelAutocompleteType::class, |
198
|
|
|
'field_options' => ['property' => 'libSerie'], |
199
|
|
|
'label' => 'label.serie' |
200
|
|
|
]) |
201
|
|
|
->add('libGameEn', null, ['label' => 'label.name.en']) |
202
|
|
|
->add('libGameFr', null, ['label' => 'label.name.fr']) |
203
|
|
|
->add('nbChart', null, ['label' => 'label.nbChart']) |
204
|
|
|
->add( |
205
|
|
|
'platforms', |
206
|
|
|
null, |
207
|
|
|
[ |
208
|
|
|
'label' => 'label.platforms', |
209
|
|
|
'field_options' => [ |
210
|
|
|
'multiple' => true, |
211
|
|
|
] |
212
|
|
|
] |
213
|
|
|
) |
214
|
|
|
->add('status', ChoiceFilter::class, [ |
215
|
|
|
'label' => 'label.status', |
216
|
|
|
'field_type' => ChoiceType::class, |
217
|
|
|
'field_options' => [ |
218
|
|
|
'choices' => GameStatus::getStatusChoices(), |
219
|
|
|
'multiple' => false, |
220
|
|
|
] |
221
|
|
|
]) |
222
|
|
|
->add('isRank', null, ['label' => 'label.boolRanking']); |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* @param ListMapper $list |
227
|
|
|
*/ |
228
|
|
|
protected function configureListFields(ListMapper $list): void |
229
|
|
|
{ |
230
|
|
|
$btns = [ |
231
|
|
|
'maj' => [ |
232
|
|
|
'template' => '@VideoGamesRecordsCore/Admin/object_maj_link.html.twig' |
233
|
|
|
], |
234
|
|
|
'history' => [ |
235
|
|
|
'template' => '@VideoGamesRecordsCore/Admin/Object/Game/link.history.html.twig' |
236
|
|
|
], |
237
|
|
|
]; |
238
|
|
|
if ($this->hasAccess('create')) { |
239
|
|
|
if ($this->getSecurity()->isGranted(self::ROLE_SUPER_ADMIN)) { |
240
|
|
|
$btns['copy'] = [ |
241
|
|
|
'template' => '@VideoGamesRecordsCore/Admin/Object/Game/link.copy.html.twig' |
242
|
|
|
]; |
243
|
|
|
} |
244
|
|
|
$btns['add_group'] = [ |
245
|
|
|
'template' => '@VideoGamesRecordsCore/Admin/Object/Game/link.add_group.html.twig' |
246
|
|
|
]; |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
$list |
250
|
|
|
->addIdentifier('id', null, ['label' => 'label.id']) |
251
|
|
|
->add('libGameEn', null, ['label' => 'label.game.en', 'editable' => true]) |
252
|
|
|
->add('libGameFr', null, ['label' => 'label.game.fr', 'editable' => true]) |
253
|
|
|
->add('platforms', null, ['label' => 'label.platforms']) |
254
|
|
|
->add( |
255
|
|
|
'picture', |
256
|
|
|
null, |
257
|
|
|
[ |
258
|
|
|
'label' => 'label.picture', |
259
|
|
|
'editable' => true |
260
|
|
|
] |
261
|
|
|
) |
262
|
|
|
->add( |
263
|
|
|
'badge.picture', |
264
|
|
|
null, |
265
|
|
|
[ |
266
|
|
|
'label' => 'label.badge', |
267
|
|
|
'editable' => true |
268
|
|
|
] |
269
|
|
|
) |
270
|
|
|
->add( |
271
|
|
|
'status', |
272
|
|
|
'choice', |
273
|
|
|
[ |
274
|
|
|
'label' => 'label.status', |
275
|
|
|
'editable' => true, |
276
|
|
|
'choices' => GameStatus::getReverseStatusChoices(), |
277
|
|
|
] |
278
|
|
|
) |
279
|
|
|
->add('_action', 'actions', [ |
280
|
|
|
'actions' => array_merge( |
281
|
|
|
[ |
282
|
|
|
'show' => [], |
283
|
|
|
'edit' => [], |
284
|
|
|
'groups' => [ |
285
|
|
|
'template' => '@VideoGamesRecordsCore/Admin/Object/Game/link.groups.html.twig' |
286
|
|
|
] |
287
|
|
|
], |
288
|
|
|
$btns |
289
|
|
|
) |
290
|
|
|
]); |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
/** |
294
|
|
|
* @param ShowMapper $show |
295
|
|
|
*/ |
296
|
|
|
protected function configureShowFields(ShowMapper $show): void |
297
|
|
|
{ |
298
|
|
|
$show |
299
|
|
|
->add('id', null, ['label' => 'label.id']) |
300
|
|
|
->add('libGameEn', null, ['label' => 'label.name.en']) |
301
|
|
|
->add('libGameFr', null, ['label' => 'label.name.fr']) |
302
|
|
|
->add('platforms', null, ['label' => 'label.platforms']) |
303
|
|
|
->add('nbChart', null, ['label' => 'label.nbChart']) |
304
|
|
|
->add('nbVideo', null, ['label' => 'label.nbVideo']) |
305
|
|
|
->add('downloadUrl', null, ['label' => 'label.downloadUrl']) |
306
|
|
|
->add('picture', null, ['label' => 'label.picture']) |
307
|
|
|
->add('badge', null, ['label' => 'label.badge']) |
308
|
|
|
->add('status', null, ['label' => 'label.status']) |
309
|
|
|
->add('forum', null, ['label' => 'label.forum']) |
310
|
|
|
->add('groups', null, ['label' => 'label.groups']); |
311
|
|
|
} |
312
|
|
|
} |
313
|
|
|
|