|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace VideoGamesRecords\CoreBundle\Admin; |
|
4
|
|
|
|
|
5
|
|
|
use Sonata\AdminBundle\Admin\AbstractAdmin; |
|
6
|
|
|
use Sonata\AdminBundle\Datagrid\DatagridMapper; |
|
7
|
|
|
use Sonata\AdminBundle\Datagrid\ListMapper; |
|
8
|
|
|
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface; |
|
9
|
|
|
use Sonata\AdminBundle\Form\FormMapper; |
|
10
|
|
|
use Sonata\AdminBundle\Form\Type\ModelAutocompleteType; |
|
11
|
|
|
use Sonata\AdminBundle\Form\Type\ModelListType; |
|
12
|
|
|
use Sonata\AdminBundle\Route\RouteCollection; |
|
13
|
|
|
use Sonata\AdminBundle\Route\RouteCollectionInterface; |
|
14
|
|
|
use Sonata\AdminBundle\Show\ShowMapper; |
|
15
|
|
|
use Sonata\DoctrineORMAdminBundle\Filter\ModelFilter; |
|
16
|
|
|
use Sonata\Form\Type\CollectionType; |
|
17
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType; |
|
18
|
|
|
use Symfony\Component\Intl\Locale; |
|
19
|
|
|
|
|
20
|
|
|
class PlayerChartAdmin extends AbstractAdmin |
|
21
|
|
|
{ |
|
22
|
|
|
protected $baseRouteName = 'vgrcorebundle_admin_player_chart'; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @return string |
|
26
|
|
|
*/ |
|
27
|
|
|
private function getLibGame(): string |
|
28
|
|
|
{ |
|
29
|
|
|
$locale = Locale::getDefault(); |
|
30
|
|
|
return ($locale == 'fr') ? 'libGameFr' : 'libGameEn'; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @return string |
|
35
|
|
|
*/ |
|
36
|
|
|
private function getLibGroup(): string |
|
37
|
|
|
{ |
|
38
|
|
|
$locale = Locale::getDefault(); |
|
39
|
|
|
return ($locale == 'fr') ? 'libGroupFr' : 'libGroupEn'; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param RouteCollection $collection |
|
44
|
|
|
*/ |
|
45
|
|
|
protected function configureRoutes(RouteCollectionInterface $collection): void |
|
46
|
|
|
{ |
|
47
|
|
|
$collection |
|
48
|
|
|
->remove('create') |
|
49
|
|
|
->remove('export'); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param ProxyQueryInterface $query |
|
54
|
|
|
* @return ProxyQueryInterface |
|
55
|
|
|
*/ |
|
56
|
|
|
protected function configureQuery(ProxyQueryInterface $query): ProxyQueryInterface |
|
57
|
|
|
{ |
|
58
|
|
|
$query = parent::configureQuery($query); |
|
59
|
|
|
|
|
60
|
|
|
$rootAlias = current($query->getRootAliases()); |
|
|
|
|
|
|
61
|
|
|
$query |
|
62
|
|
|
->innerJoin($rootAlias[0] . '.chart', 'chart') |
|
|
|
|
|
|
63
|
|
|
->addSelect('chart') |
|
64
|
|
|
->innerJoin($rootAlias[0] . '.player', 'player') |
|
65
|
|
|
->addSelect('player') |
|
66
|
|
|
->innerJoin('chart.group', 'grp') |
|
67
|
|
|
->addSelect('grp') |
|
68
|
|
|
->innerJoin('grp.game', 'game') |
|
69
|
|
|
->addSelect('game'); |
|
70
|
|
|
|
|
71
|
|
|
return $query; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @param FormMapper $form |
|
77
|
|
|
*/ |
|
78
|
|
|
protected function configureFormFields(FormMapper $form): void |
|
79
|
|
|
{ |
|
80
|
|
|
$form |
|
81
|
|
|
->add('id', TextType::class, [ |
|
82
|
|
|
'label' => 'label.id', |
|
83
|
|
|
'attr' => [ |
|
84
|
|
|
'readonly' => true, |
|
85
|
|
|
] |
|
86
|
|
|
]) |
|
87
|
|
|
->add('player', ModelListType::class, [ |
|
88
|
|
|
'btn_add' => false, |
|
89
|
|
|
'btn_list' => false, |
|
90
|
|
|
'btn_edit' => false, |
|
91
|
|
|
'btn_delete' => false, |
|
92
|
|
|
'btn_catalogue' => false, |
|
93
|
|
|
'label' => 'label.player', |
|
94
|
|
|
]) |
|
95
|
|
|
->add('chart', ModelListType::class, [ |
|
96
|
|
|
'btn_add' => false, |
|
97
|
|
|
'btn_list' => true, |
|
98
|
|
|
'btn_edit' => false, |
|
99
|
|
|
'btn_delete' => false, |
|
100
|
|
|
'btn_catalogue' => true, |
|
101
|
|
|
'label' => 'label.chart', |
|
102
|
|
|
]) |
|
103
|
|
|
->add('status', null, ['label' => 'label.status']) |
|
104
|
|
|
->add('libs', CollectionType::class, array( |
|
105
|
|
|
'label' => 'label.libs', |
|
106
|
|
|
'btn_add' => true, |
|
107
|
|
|
'by_reference' => false, |
|
108
|
|
|
'type_options' => array( |
|
109
|
|
|
'delete' => false, |
|
110
|
|
|
) |
|
111
|
|
|
), array( |
|
112
|
|
|
'edit' => 'inline', |
|
113
|
|
|
'inline' => 'table', |
|
114
|
|
|
)); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* @param DatagridMapper $filter |
|
119
|
|
|
*/ |
|
120
|
|
|
protected function configureDatagridFilters(DatagridMapper $filter): void |
|
121
|
|
|
{ |
|
122
|
|
|
$filter |
|
123
|
|
|
->add('id', null, ['label' => 'label.id']) |
|
124
|
|
|
->add('status', null, ['label' => 'label.status']) |
|
125
|
|
|
->add( |
|
126
|
|
|
'player', ModelFilter::class, [ |
|
127
|
|
|
'label' => 'label.player', |
|
128
|
|
|
'field_type' => ModelAutocompleteType::class, |
|
129
|
|
|
'field_options' => ['property' => 'pseudo'], |
|
130
|
|
|
] |
|
131
|
|
|
) |
|
132
|
|
|
->add( |
|
133
|
|
|
'chart.group.game', ModelFilter::class, [ |
|
134
|
|
|
'label' => 'label.game', |
|
135
|
|
|
'field_type' => ModelAutocompleteType::class, |
|
136
|
|
|
'field_options' => ['property' => 'libGameEn'], |
|
137
|
|
|
] |
|
138
|
|
|
) |
|
139
|
|
|
->add( |
|
140
|
|
|
'chart.group', ModelFilter::class, [ |
|
141
|
|
|
'label' => 'label.group', |
|
142
|
|
|
'field_type' => ModelAutocompleteType::class, |
|
143
|
|
|
'field_options' => ['property' => 'libGroupEn'], |
|
144
|
|
|
] |
|
145
|
|
|
) |
|
146
|
|
|
->add('chart.id', null, ['label' => 'label.chart.id']) |
|
147
|
|
|
->add('chart.libChartEn', null, ['label' => 'label.name.en']) |
|
148
|
|
|
->add('chart.libChartFr', null, ['label' => 'label.name.fr']); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* @param ListMapper $list |
|
153
|
|
|
*/ |
|
154
|
|
|
protected function configureListFields(ListMapper $list): void |
|
155
|
|
|
{ |
|
156
|
|
|
$list |
|
157
|
|
|
->addIdentifier('id', null, ['label' => 'label.id']) |
|
158
|
|
|
->add('player', null, [ |
|
159
|
|
|
'associated_property' => 'pseudo', |
|
160
|
|
|
'label' => 'label.player', |
|
161
|
|
|
]) |
|
162
|
|
|
->add('chart.group.game', null, [ |
|
163
|
|
|
'associated_property' => $this->getLibGame(), |
|
164
|
|
|
'label' => 'label.game', |
|
165
|
|
|
'sortable' => true, |
|
166
|
|
|
'sort_field_mapping' => array( |
|
167
|
|
|
'fieldName' => $this->getLibGame() |
|
168
|
|
|
), |
|
169
|
|
|
'sort_parent_association_mappings' => array( |
|
170
|
|
|
array('fieldName' => 'chart'), |
|
171
|
|
|
array('fieldName' => 'group'), |
|
172
|
|
|
array('fieldName' => 'game'), |
|
173
|
|
|
) |
|
174
|
|
|
]) |
|
175
|
|
|
->add('chart.group', null, [ |
|
176
|
|
|
'associated_property' => $this->getLibGroup(), |
|
177
|
|
|
'label' => 'label.group', |
|
178
|
|
|
'sortable' => true, |
|
179
|
|
|
'sort_field_mapping' => array( |
|
180
|
|
|
'fieldName' => $this->getLibGroup() |
|
181
|
|
|
), |
|
182
|
|
|
'sort_parent_association_mappings' => array( |
|
183
|
|
|
array('fieldName' => 'chart'), |
|
184
|
|
|
array('fieldName' => 'group') |
|
185
|
|
|
) |
|
186
|
|
|
]) |
|
187
|
|
|
->add('chart', null, [ |
|
188
|
|
|
'associated_property' => 'libChartEn', |
|
189
|
|
|
'label' => 'label.chart', |
|
190
|
|
|
]) |
|
191
|
|
|
->add('status', null, ['label' => 'label.status']) |
|
192
|
|
|
->add('libs', null, ['label' => 'label.libs']) |
|
193
|
|
|
->add('_action', 'actions', [ |
|
194
|
|
|
'actions' => [ |
|
195
|
|
|
'edit' => [], |
|
196
|
|
|
'show' => [], |
|
197
|
|
|
] |
|
198
|
|
|
]); |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
/** |
|
202
|
|
|
* @param ShowMapper $show |
|
203
|
|
|
*/ |
|
204
|
|
|
protected function configureShowFields(ShowMapper $show): void |
|
205
|
|
|
{ |
|
206
|
|
|
$show |
|
207
|
|
|
->add('id', null, ['label' => 'label.id']) |
|
208
|
|
|
->add('player', null, ['label' => 'label.player']) |
|
209
|
|
|
->add('chart', null, ['label' => 'label.chart']) |
|
210
|
|
|
->add('status', null, ['label' => 'label.status']) |
|
211
|
|
|
->add('dateInvestigation', null, ['label' => 'label.dateInvestigation']) |
|
212
|
|
|
->add('proof', null, ['label' => 'label.proof']) |
|
213
|
|
|
->add('libs', null, ['label' => 'label.libs']); |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
/** |
|
217
|
|
|
* @param $object |
|
218
|
|
|
*/ |
|
219
|
|
|
public function preUpdate($object): void |
|
220
|
|
|
{ |
|
221
|
|
|
$chart = $object->getChart(); |
|
222
|
|
|
$chart->setStatusPlayer('MAJ'); |
|
223
|
|
|
$chart->setStatusTeam('MAJ'); |
|
224
|
|
|
} |
|
225
|
|
|
} |
|
226
|
|
|
|