1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<?php
namespace App\Admin;
use App\Entity\Prestataire;
use App\Enum\GroupePrestaEnum;
use App\Form\Type\GeolocFormType;
use FOS\CKEditorBundle\Form\Type\CKEditorType;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Route\RouteCollection;
use Sonata\MediaBundle\Form\Type\MediaType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Security\Core\Security;
/**
* Administration des groupe de prestataires (amap, marche).
*
* KOHINOS : Outil de gestion de Monnaie Locale Complémentaire
*
* @author Julien Jorry <julien.jorry@gmail.com>
*/
class GroupeprestataireAdmin extends AbstractAdmin
{
protected $security;
protected $datagridValues = [
// reverse order (default = 'ASC')
'_sort_order' => 'DESC',
// name of the ordered field (default = the model's id field, if any)
'_sort_by' => 'updatedAt',
];
public function configure()
{
parent::configure();
}
public function setSecurity(Security $security)
{
$this->security = $security;
}
/**
* {@inheritdoc}
*/
public function createQuery($context = 'list')
{
$user = $this->security->getUser();
$query = parent::createQuery($context);
// if ($this->hasRequest()) {
// if (empty($this->getRequest()->getSession()->get('_groupegere'))) {
// if ($this->security->isGranted('ROLE_GESTION_GROUPE') || $this->security->isGranted('ROLE_CONTACT') || $this->security->isGranted('ROLE_TRESORIER')) {
// if (!$this->security->isGranted('ROLE_TRESORIER')) {
// $query->andWhere('false = true');
// }
// }
// } else {
// $query
// ->andWhere($query->getRootAliases()[0] . '.groupe = :groupe')
// ->setParameter('groupe', $this->getRequest()->getSession()->get('_groupegere'))
// ;
// }
// }
return $query;
}
/**
* {@inheritdoc}
*/
protected function configureFormFields(FormMapper $formMapper)
{
$user = $this->security->getUser();
$groupepresta = $this->getSubject();
$formMapper
->with('Informations', ['class' => 'col-md-7'])
->add('type', ChoiceType::class, [
'required' => true,
'choices' => GroupePrestaEnum::getAvailableTypes(),
'choice_label' => function ($choice) {
return GroupePrestaEnum::getTypeName($choice);
},
])
->add('name', TextType::class, [
'label' => "Nom de l'AMAP/Marché :",
'required' => true,
])
;
// if ($user && ($this->security->isGranted('ROLE_GESTION_GROUPE') || $this->security->isGranted('ROLE_CONTACT') || $this->security->isGranted('ROLE_TRESORIER')) && !empty($this->getRequest()->getSession()->get('_groupegere'))) {
// $prestataires = $this->getConfigurationPool()->getContainer()->get('doctrine')->getRepository(Prestataire::class)->findByGroupeLocal($this->getRequest()->getSession()->get('_groupegere'));
// } else {
$prestataires = $this->getConfigurationPool()->getContainer()->get('doctrine')->getRepository(Prestataire::class)->findDefault();
// }
if ($user && ($this->security->isGranted('ROLE_SUPER_ADMIN') || $this->security->isGranted('ROLE_ADMIN_SIEGE'))) {
$formMapper
->add('groupe', null, [
'label' => 'Groupe local',
'required' => true,
])
;
}
$formMapper
->add('horaires', CKEditorType::class, [
'label' => 'Horaires :',
'required' => false,
])
->add('content', CKEditorType::class, [
'label' => 'Description',
'required' => false,
])
->add('enabled', CheckboxType::class, [
'label' => 'Activé ?',
'required' => false,
'label_attr' => ['class' => 'checkbox-inline'],
])
->end()
->with('Adresse', ['class' => 'col-md-5'])
->add('geoloc', GeolocFormType::class, [
'label' => false,
'required' => false,
])
->end()
->with('Image', ['class' => 'col-md-5'])
->add('image', MediaType::class, [
'provider' => 'sonata.media.provider.image',
'context' => 'groupe',
'label' => 'Image',
])
->end()
->with('Prestataires', ['class' => 'col-md-5'])
->add('prestataires', CollectionType::class, [
'label' => 'Prestataires',
'entry_type' => EntityType::class,
'entry_options' => [
'class' => Prestataire::class,
'choices' => $prestataires,
// 'choice_label' => 'name',
'placeholder' => 'Choisir un prestataire',
'required' => false,
'label' => false, ],
'by_reference' => false,
'allow_add' => true,
'allow_delete' => true,
])
;
}
/**
* {@inheritdoc}
*/
protected function configureListFields(ListMapper $listMapper)
{
$user = $this->security->getUser();
unset($this->listModes['mosaic']);
if ($user && ($this->security->isGranted('ROLE_SUPER_ADMIN') || $this->security->isGranted('ROLE_ADMIN_SIEGE'))) {
$listMapper
->addIdentifier('groupe', null, [
'label' => 'Groupe local',
])
;
}
$listMapper
->addIdentifier('name', null, [
'label' => "Nom de l'AMAP / Marché",
])
->addIdentifier('type', null, [
'label' => 'Type',
])
->addIdentifier('geoloc', null, ['label' => 'Adresse'])
->addIdentifier('horaires', 'html', [
'label' => 'Horaires',
'strip' => true,
'truncate' => 50,
])
->add('getPrestatairesCount', null, [
'label' => 'Nombre de prestas',
'sortable' => false,
])
->add('enabled', null, [
'label' => 'Activé',
'editable' => true,
])
;
}
protected function configureRoutes(RouteCollection $collection)
{
parent::configureRoutes($collection);
$collection->remove('delete');
}
public function getBatchActions()
{
$actions = parent::getBatchActions();
unset($actions['delete']);
return $actions;
}
public function getDashboardActions()
{
$actions = parent::getDashboardActions();
unset($actions['list']);
return $actions;
}
}