1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* |
4
|
|
|
* part-db version 0.1 |
5
|
|
|
* Copyright (C) 2005 Christoph Lechner |
6
|
|
|
* http://www.cl-projects.de/ |
7
|
|
|
* |
8
|
|
|
* part-db version 0.2+ |
9
|
|
|
* Copyright (C) 2009 K. Jacobs and others (see authors.php) |
10
|
|
|
* http://code.google.com/p/part-db/ |
11
|
|
|
* |
12
|
|
|
* Part-DB Version 0.4+ |
13
|
|
|
* Copyright (C) 2016 - 2019 Jan Böhmer |
14
|
|
|
* https://github.com/jbtronics |
15
|
|
|
* |
16
|
|
|
* This program is free software; you can redistribute it and/or |
17
|
|
|
* modify it under the terms of the GNU General Public License |
18
|
|
|
* as published by the Free Software Foundation; either version 2 |
19
|
|
|
* of the License, or (at your option) any later version. |
20
|
|
|
* |
21
|
|
|
* This program is distributed in the hope that it will be useful, |
22
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
23
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
24
|
|
|
* GNU General Public License for more details. |
25
|
|
|
* |
26
|
|
|
* You should have received a copy of the GNU General Public License |
27
|
|
|
* along with this program; if not, write to the Free Software |
28
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
29
|
|
|
* |
30
|
|
|
*/ |
31
|
|
|
|
32
|
|
|
namespace App\Form; |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
use App\Entity\UserSystem\Group; |
36
|
|
|
use App\Entity\Base\NamedDBElement; |
37
|
|
|
use App\Entity\Base\StructuralDBElement; |
38
|
|
|
use App\Form\Permissions\PermissionsType; |
39
|
|
|
use App\Form\Permissions\PermissionType; |
40
|
|
|
use App\Form\Type\CurrencyEntityType; |
41
|
|
|
use App\Form\Type\StructuralEntityType; |
42
|
|
|
use FOS\CKEditorBundle\Form\Type\CKEditorType; |
43
|
|
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType; |
44
|
|
|
use Symfony\Component\Form\AbstractType; |
45
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; |
46
|
|
|
use Symfony\Component\Form\Extension\Core\Type\LanguageType; |
47
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ResetType; |
48
|
|
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType; |
49
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType; |
50
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TimezoneType; |
51
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
52
|
|
|
use Symfony\Component\Security\Core\Security; |
53
|
|
|
use Symfony\Contracts\Translation\TranslatorInterface; |
54
|
|
|
|
55
|
|
|
class UserAdminForm extends AbstractType |
56
|
|
|
{ |
57
|
|
|
|
58
|
|
|
protected $security; |
59
|
|
|
protected $trans; |
60
|
|
|
|
61
|
|
|
public function __construct(Security $security, TranslatorInterface $trans) |
62
|
|
|
{ |
63
|
|
|
$this->security = $security; |
64
|
|
|
$this->trans = $trans; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options) |
69
|
|
|
{ |
70
|
|
|
/** @var StructuralDBElement $entity */ |
71
|
|
|
$entity = $options['data']; |
72
|
|
|
$is_new = $entity->getID() === null; |
73
|
|
|
|
74
|
|
|
$builder |
75
|
|
|
->add('name', TextType::class, [ |
76
|
|
|
'empty_data' => '', |
77
|
|
|
'label' => $this->trans->trans('user.username.label'), |
78
|
|
|
'attr' => ['placeholder' => $this->trans->trans('user.username.placeholder')], |
79
|
|
|
'disabled' => !$this->security->isGranted('edit_username', $entity), |
80
|
|
|
]) |
81
|
|
|
|
82
|
|
|
->add('group', StructuralEntityType::class, [ |
83
|
|
|
'class' => Group::class, |
84
|
|
|
'required' => false, |
85
|
|
|
'label' => $this->trans->trans('group.label'), |
86
|
|
|
'disable_not_selectable' => true, |
87
|
|
|
'disabled' => !$this->security->isGranted('change_group', $entity), ]) |
88
|
|
|
|
89
|
|
|
->add('first_name', TextType::class, [ |
90
|
|
|
'empty_data' => '', |
91
|
|
|
'label' => $this->trans->trans('user.firstName.label'), |
92
|
|
|
'attr' => ['placeholder' => $this->trans->trans('user.firstName.placeholder')], 'required' => false, |
93
|
|
|
'disabled' => !$this->security->isGranted('edit_infos', $entity), |
94
|
|
|
]) |
95
|
|
|
|
96
|
|
|
->add('last_name', TextType::class, [ |
97
|
|
|
'empty_data' => '', |
98
|
|
|
'label' => $this->trans->trans('user.lastName.label'), |
99
|
|
|
'attr' => ['placeholder' => $this->trans->trans('user.lastName.placeholder')], |
100
|
|
|
'required' => false, |
101
|
|
|
'disabled' => !$this->security->isGranted('edit_infos', $entity), |
102
|
|
|
]) |
103
|
|
|
|
104
|
|
|
->add('email', TextType::class, [ |
105
|
|
|
'empty_data' => '', |
106
|
|
|
'label' => $this->trans->trans('user.email.label'), |
107
|
|
|
'attr' => ['placeholder' => $this->trans->trans('user.email.placeholder')], |
108
|
|
|
'required' => false, |
109
|
|
|
'disabled' => !$this->security->isGranted('edit_infos', $entity), ]) |
110
|
|
|
|
111
|
|
|
|
112
|
|
|
->add('department', TextType::class, [ |
113
|
|
|
'empty_data' => '', |
114
|
|
|
'label' => $this->trans->trans('user.department.label'), |
115
|
|
|
'attr' => ['placeholder' => $this->trans->trans('user.department.placeholder')], |
116
|
|
|
'required' => false, |
117
|
|
|
'disabled' => !$this->security->isGranted('edit_infos', $entity), |
118
|
|
|
]) |
119
|
|
|
|
120
|
|
|
//Config section |
121
|
|
|
->add('language', LanguageType::class, [ |
122
|
|
|
'required' => false, |
123
|
|
|
'attr' => ['class' => 'selectpicker', 'data-live-search' => true], |
124
|
|
|
'placeholder' => $this->trans->trans('user_settings.language.placeholder'), |
125
|
|
|
'label' => $this->trans->trans('user.language_select'), |
126
|
|
|
'preferred_choices' => ['en', 'de'], |
127
|
|
|
'disabled' => !$this->security->isGranted('change_user_settings', $entity) |
128
|
|
|
]) |
129
|
|
|
->add('timezone', TimezoneType::class, [ |
130
|
|
|
'required' => false, |
131
|
|
|
'attr' => ['class' => 'selectpicker', 'data-live-search' => true], |
132
|
|
|
'placeholder' => $this->trans->trans('user_settings.timezone.placeholder'), |
133
|
|
|
'label' => $this->trans->trans('user.timezone.label'), |
134
|
|
|
'preferred_choices' => ['Europe/Berlin'], |
135
|
|
|
'disabled' => !$this->security->isGranted('change_user_settings', $entity) |
136
|
|
|
]) |
137
|
|
|
->add('theme', ChoiceType::class, [ |
138
|
|
|
'required' => false, |
139
|
|
|
'placeholder' => $this->trans->trans('user_settings.theme.placeholder'), |
140
|
|
|
'label' => $this->trans->trans('user.theme.label'), |
141
|
|
|
'disabled' => !$this->security->isGranted('change_user_settings', $entity) |
142
|
|
|
]) |
143
|
|
|
->add('currency', CurrencyEntityType::class, [ |
144
|
|
|
'required' => false, |
145
|
|
|
'label' => $this->trans->trans('user.currency.label'), |
146
|
|
|
'disabled' => !$this->security->isGranted('change_user_settings', $entity) |
147
|
|
|
]) |
148
|
|
|
|
149
|
|
|
//Permission section |
150
|
|
|
->add('permissions', PermissionsType::class, [ |
151
|
|
|
'mapped' => false, |
152
|
|
|
'data' => $builder->getData(), |
153
|
|
|
'disabled' => !$this->security->isGranted('edit_permissions', $entity) |
154
|
|
|
]) |
155
|
|
|
; |
156
|
|
|
/*->add('comment', CKEditorType::class, ['required' => false, |
157
|
|
|
'label' => 'comment.label', 'attr' => ['rows' => 4], 'help' => 'bbcode.hint', |
158
|
|
|
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]); */ |
159
|
|
|
|
160
|
|
|
$this->additionalFormElements($builder, $options, $entity); |
161
|
|
|
|
162
|
|
|
//Buttons |
163
|
|
|
$builder->add('save', SubmitType::class, [ |
164
|
|
|
'label' => $is_new ? $this->trans->trans('user.create') : $this->trans->trans('user.edit.save'), |
|
|
|
|
165
|
|
|
'attr' => ['class' => $is_new ? 'btn-success' : ''] |
|
|
|
|
166
|
|
|
]) |
167
|
|
|
->add('reset', ResetType::class, [ |
168
|
|
|
'label' => $this->trans->trans('entity.edit.reset') |
169
|
|
|
]); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity) |
|
|
|
|
173
|
|
|
{ |
174
|
|
|
//Empty for Base |
175
|
|
|
} |
176
|
|
|
} |