1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Alpixel\Bundle\UserBundle\Admin; |
4
|
|
|
|
5
|
|
|
use FOS\UserBundle\Model\UserManagerInterface; |
6
|
|
|
use Sonata\AdminBundle\Admin\AbstractAdmin; |
7
|
|
|
use Sonata\AdminBundle\Admin\Admin; |
8
|
|
|
use Sonata\AdminBundle\Datagrid\DatagridMapper; |
9
|
|
|
use Sonata\AdminBundle\Datagrid\ListMapper; |
10
|
|
|
use Sonata\AdminBundle\Form\FormMapper; |
11
|
|
|
|
12
|
|
|
class AdminAdmin extends AbstractAdmin |
13
|
|
|
{ |
14
|
|
|
protected $userManager; |
15
|
|
|
|
16
|
|
|
public function createQuery($context = 'list') |
17
|
|
|
{ |
18
|
|
|
$query = parent::createQuery($context); |
19
|
|
|
|
20
|
|
|
return $query; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param DatagridMapper $datagridMapper |
25
|
|
|
*/ |
26
|
|
|
protected function configureDatagridFilters(DatagridMapper $datagridMapper) |
27
|
|
|
{ |
28
|
|
|
$datagridMapper |
29
|
|
|
->add('id', null, [ |
30
|
|
|
'label' => 'ID', |
31
|
|
|
]) |
32
|
|
|
->add('username', null, [ |
33
|
|
|
'label' => 'Nom d\'utilisateur', |
34
|
|
|
]) |
35
|
|
|
->add('firstname', null, [ |
36
|
|
|
'label' => 'Prénom', |
37
|
|
|
]) |
38
|
|
|
->add('lastname', null, [ |
39
|
|
|
'label' => 'Nom', |
40
|
|
|
]) |
41
|
|
|
->add('email', null, [ |
42
|
|
|
'label' => 'Email', |
43
|
|
|
]); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param ListMapper $listMapper |
48
|
|
|
*/ |
49
|
|
|
protected function configureListFields(ListMapper $listMapper) |
50
|
|
|
{ |
51
|
|
|
$listMapper |
52
|
|
|
->add('id', null, [ |
53
|
|
|
'label' => 'ID', |
54
|
|
|
]) |
55
|
|
|
->add('username', null, [ |
56
|
|
|
'label' => 'Nom d\'utilisateur', |
57
|
|
|
]) |
58
|
|
|
->add('firstname', null, [ |
59
|
|
|
'label' => 'Prénom', |
60
|
|
|
]) |
61
|
|
|
->add('lastname', null, [ |
62
|
|
|
'label' => 'Nom', |
63
|
|
|
]) |
64
|
|
|
->add('email', null, [ |
65
|
|
|
'label' => 'Email', |
66
|
|
|
]) |
67
|
|
|
->add('created', null, [ |
68
|
|
|
'label' => 'Date de création', |
69
|
|
|
]) |
70
|
|
|
->add('lastLogin', null, [ |
71
|
|
|
'label' => 'Dernier login', |
72
|
|
|
]) |
73
|
|
|
->add('_action', 'actions', [ |
74
|
|
|
'actions' => [ |
75
|
|
|
'edit' => [], |
76
|
|
|
], |
77
|
|
|
]); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param FormMapper $formMapper |
82
|
|
|
*/ |
83
|
|
|
protected function configureFormFields(FormMapper $formMapper) |
84
|
|
|
{ |
85
|
|
|
$container = $this->getConfigurationPool()->getContainer(); |
86
|
|
|
|
87
|
|
|
$optionsRoles = [ |
88
|
|
|
'multiple' => true, |
89
|
|
|
'label' => 'Permissions', |
90
|
|
|
]; |
91
|
|
|
|
92
|
|
|
if (\AppKernel::VERSION_ID >= 20700) { |
93
|
|
|
$optionsRoles['choices'] = array_flip($container->getParameter('alpixel_user.role_descriptions')); |
94
|
|
|
|
95
|
|
|
if (\AppKernel::VERSION_ID < 30000) { |
96
|
|
|
$optionsRoles['choices_as_values'] = true; |
97
|
|
|
} |
98
|
|
|
} else { |
99
|
|
|
$optionsRoles['choices'] = $container->getParameter('alpixel_user.role_descriptions'); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
$formMapper |
103
|
|
|
->with('Informations personnelles', [ |
104
|
|
|
'description' => '', |
105
|
|
|
'class' => 'col-md-8', |
106
|
|
|
]) |
107
|
|
|
->add('username', null, [ |
108
|
|
|
'label' => 'Nom d\'utilisateur', |
109
|
|
|
]) |
110
|
|
|
->add('email', null, [ |
111
|
|
|
'label' => 'Email', |
112
|
|
|
]) |
113
|
|
|
->add('firstname', null, [ |
114
|
|
|
'label' => 'Prénom', |
115
|
|
|
]) |
116
|
|
|
->add('lastname', null, [ |
117
|
|
|
'label' => 'Nom', |
118
|
|
|
]) |
119
|
|
|
->end() |
120
|
|
|
->with('Paramétrage', [ |
121
|
|
|
'description' => '', |
122
|
|
|
'class' => 'col-md-4', |
123
|
|
|
]) |
124
|
|
|
->add('enabled', null, [ |
125
|
|
|
'label' => 'Compte actif', |
126
|
|
|
]) |
127
|
|
|
->add('roles', 'choice', $optionsRoles) |
128
|
|
|
->add('plainPassword', 'text', [ |
129
|
|
|
'label' => 'Changer le mot de passe', |
130
|
|
|
'required' => false, |
131
|
|
|
]) |
132
|
|
|
->end(); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
public function preUpdate($user) |
136
|
|
|
{ |
137
|
|
|
$this->getUserManager()->updateUser($user); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
public function setUserManager(UserManagerInterface $userManager) |
141
|
|
|
{ |
142
|
|
|
$this->userManager = $userManager; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @return UserManagerInterface |
147
|
|
|
*/ |
148
|
|
|
public function getUserManager() |
149
|
|
|
{ |
150
|
|
|
return $this->userManager; |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
|