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\CheckboxType; |
46
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; |
47
|
|
|
use Symfony\Component\Form\Extension\Core\Type\CollectionType; |
48
|
|
|
use Symfony\Component\Form\Extension\Core\Type\LanguageType; |
49
|
|
|
use Symfony\Component\Form\Extension\Core\Type\PasswordType; |
50
|
|
|
use Symfony\Component\Form\Extension\Core\Type\RepeatedType; |
51
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ResetType; |
52
|
|
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType; |
53
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType; |
54
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TimezoneType; |
55
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
56
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
57
|
|
|
use Symfony\Component\Security\Core\Security; |
58
|
|
|
use Symfony\Component\Validator\Constraints\Length; |
59
|
|
|
use Symfony\Contracts\Translation\TranslatorInterface; |
60
|
|
|
|
61
|
|
|
class UserAdminForm extends AbstractType |
62
|
|
|
{ |
63
|
|
|
|
64
|
|
|
protected $security; |
65
|
|
|
protected $trans; |
66
|
|
|
|
67
|
|
|
public function __construct(Security $security, TranslatorInterface $trans) |
68
|
|
|
{ |
69
|
|
|
$this->security = $security; |
70
|
|
|
$this->trans = $trans; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function configureOptions(OptionsResolver $resolver) |
74
|
|
|
{ |
75
|
|
|
parent::configureOptions($resolver); // TODO: Change the autogenerated stub |
76
|
|
|
$resolver->setRequired('attachment_class'); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options) |
80
|
|
|
{ |
81
|
|
|
/** @var StructuralDBElement $entity */ |
82
|
|
|
$entity = $options['data']; |
83
|
|
|
$is_new = $entity->getID() === null; |
84
|
|
|
|
85
|
|
|
$builder |
86
|
|
|
->add('name', TextType::class, [ |
87
|
|
|
'empty_data' => '', |
88
|
|
|
'label' => $this->trans->trans('user.username.label'), |
89
|
|
|
'attr' => ['placeholder' => $this->trans->trans('user.username.placeholder')], |
90
|
|
|
'disabled' => !$this->security->isGranted('edit_username', $entity), |
91
|
|
|
]) |
92
|
|
|
|
93
|
|
|
->add('group', StructuralEntityType::class, [ |
94
|
|
|
'class' => Group::class, |
95
|
|
|
'required' => false, |
96
|
|
|
'label' => $this->trans->trans('group.label'), |
97
|
|
|
'disable_not_selectable' => true, |
98
|
|
|
'disabled' => !$this->security->isGranted('change_group', $entity), ]) |
99
|
|
|
|
100
|
|
|
->add('first_name', TextType::class, [ |
101
|
|
|
'empty_data' => '', |
102
|
|
|
'label' => $this->trans->trans('user.firstName.label'), |
103
|
|
|
'attr' => ['placeholder' => $this->trans->trans('user.firstName.placeholder')], 'required' => false, |
104
|
|
|
'disabled' => !$this->security->isGranted('edit_infos', $entity), |
105
|
|
|
]) |
106
|
|
|
|
107
|
|
|
->add('last_name', TextType::class, [ |
108
|
|
|
'empty_data' => '', |
109
|
|
|
'label' => $this->trans->trans('user.lastName.label'), |
110
|
|
|
'attr' => ['placeholder' => $this->trans->trans('user.lastName.placeholder')], |
111
|
|
|
'required' => false, |
112
|
|
|
'disabled' => !$this->security->isGranted('edit_infos', $entity), |
113
|
|
|
]) |
114
|
|
|
|
115
|
|
|
->add('email', TextType::class, [ |
116
|
|
|
'empty_data' => '', |
117
|
|
|
'label' => $this->trans->trans('user.email.label'), |
118
|
|
|
'attr' => ['placeholder' => $this->trans->trans('user.email.placeholder')], |
119
|
|
|
'required' => false, |
120
|
|
|
'disabled' => !$this->security->isGranted('edit_infos', $entity), ]) |
121
|
|
|
|
122
|
|
|
|
123
|
|
|
->add('department', TextType::class, [ |
124
|
|
|
'empty_data' => '', |
125
|
|
|
'label' => $this->trans->trans('user.department.label'), |
126
|
|
|
'attr' => ['placeholder' => $this->trans->trans('user.department.placeholder')], |
127
|
|
|
'required' => false, |
128
|
|
|
'disabled' => !$this->security->isGranted('edit_infos', $entity), |
129
|
|
|
]) |
130
|
|
|
|
131
|
|
|
//Config section |
132
|
|
|
->add('language', LanguageType::class, [ |
133
|
|
|
'required' => false, |
134
|
|
|
'attr' => ['class' => 'selectpicker', 'data-live-search' => true], |
135
|
|
|
'placeholder' => $this->trans->trans('user_settings.language.placeholder'), |
136
|
|
|
'label' => $this->trans->trans('user.language_select'), |
137
|
|
|
'preferred_choices' => ['en', 'de'], |
138
|
|
|
'disabled' => !$this->security->isGranted('change_user_settings', $entity) |
139
|
|
|
]) |
140
|
|
|
->add('timezone', TimezoneType::class, [ |
141
|
|
|
'required' => false, |
142
|
|
|
'attr' => ['class' => 'selectpicker', 'data-live-search' => true], |
143
|
|
|
'placeholder' => $this->trans->trans('user_settings.timezone.placeholder'), |
144
|
|
|
'label' => $this->trans->trans('user.timezone.label'), |
145
|
|
|
'preferred_choices' => ['Europe/Berlin'], |
146
|
|
|
'disabled' => !$this->security->isGranted('change_user_settings', $entity) |
147
|
|
|
]) |
148
|
|
|
->add('theme', ChoiceType::class, [ |
149
|
|
|
'required' => false, |
150
|
|
|
'placeholder' => $this->trans->trans('user_settings.theme.placeholder'), |
151
|
|
|
'label' => $this->trans->trans('user.theme.label'), |
152
|
|
|
'disabled' => !$this->security->isGranted('change_user_settings', $entity) |
153
|
|
|
]) |
154
|
|
|
->add('currency', CurrencyEntityType::class, [ |
155
|
|
|
'required' => false, |
156
|
|
|
'label' => $this->trans->trans('user.currency.label'), |
157
|
|
|
'disabled' => !$this->security->isGranted('change_user_settings', $entity) |
158
|
|
|
]) |
159
|
|
|
|
160
|
|
|
->add('new_password', RepeatedType::class, [ |
161
|
|
|
'type' => PasswordType::class, |
162
|
|
|
'first_options' => ['label' => $this->trans->trans('user.settings.pw_new.label')], |
163
|
|
|
'second_options' => ['label' => $this->trans->trans('user.settings.pw_confirm.label')], |
164
|
|
|
'invalid_message' => 'password_must_match', |
165
|
|
|
'required' => false, |
166
|
|
|
'mapped' => false, |
167
|
|
|
'constraints' => [new Length([ |
168
|
|
|
'min' => 6, |
169
|
|
|
'max' => 128, |
170
|
|
|
])] |
171
|
|
|
]) |
172
|
|
|
|
173
|
|
|
->add('need_pw_change', CheckboxType::class, [ |
174
|
|
|
'required' => false, |
175
|
|
|
'label_attr' => ['class' => 'checkbox-custom'], |
176
|
|
|
'label' => $this->trans->trans('user.edit.needs_pw_change') |
177
|
|
|
]) |
178
|
|
|
|
179
|
|
|
//Permission section |
180
|
|
|
->add('permissions', PermissionsType::class, [ |
181
|
|
|
'mapped' => false, |
182
|
|
|
'data' => $builder->getData(), |
183
|
|
|
'disabled' => !$this->security->isGranted('edit_permissions', $entity) |
184
|
|
|
]) |
185
|
|
|
; |
186
|
|
|
/*->add('comment', CKEditorType::class, ['required' => false, |
187
|
|
|
'label' => 'comment.label', 'attr' => ['rows' => 4], 'help' => 'bbcode.hint', |
188
|
|
|
'disabled' => !$this->security->isGranted($is_new ? 'create' : 'edit', $entity)]); */ |
189
|
|
|
|
190
|
|
|
$this->additionalFormElements($builder, $options, $entity); |
191
|
|
|
|
192
|
|
|
//Attachment section |
193
|
|
|
$builder->add('attachments', CollectionType::class, [ |
194
|
|
|
'entry_type' => AttachmentFormType::class, |
195
|
|
|
'allow_add' => true, |
196
|
|
|
'allow_delete' => true, |
197
|
|
|
'label' => false, |
198
|
|
|
'entry_options' => [ |
199
|
|
|
'data_class' => $options['attachment_class'], |
200
|
|
|
], |
201
|
|
|
'by_reference' => false |
202
|
|
|
]); |
203
|
|
|
|
204
|
|
|
//Buttons |
205
|
|
|
$builder->add('save', SubmitType::class, [ |
206
|
|
|
'label' => $is_new ? $this->trans->trans('user.create') : $this->trans->trans('user.edit.save'), |
|
|
|
|
207
|
|
|
'attr' => ['class' => $is_new ? 'btn-success' : ''] |
|
|
|
|
208
|
|
|
]) |
209
|
|
|
->add('reset', ResetType::class, [ |
210
|
|
|
'label' => $this->trans->trans('entity.edit.reset') |
211
|
|
|
]); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
protected function additionalFormElements(FormBuilderInterface $builder, array $options, NamedDBElement $entity) |
|
|
|
|
215
|
|
|
{ |
216
|
|
|
//Empty for Base |
217
|
|
|
} |
218
|
|
|
} |