Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
99.42% |
170 / 171 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
CollectivityType | |
99.42% |
170 / 171 |
|
66.67% |
2 / 3 |
8 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
buildForm | |
99.38% |
161 / 162 |
|
0.00% |
0 / 1 |
6 | |||
configureOptions | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | /** |
4 | * This file is part of the MADIS - RGPD Management application. |
5 | * |
6 | * @copyright Copyright (c) 2018-2019 Soluris - Solutions Numériques Territoriales Innovantes |
7 | * |
8 | * This program is free software: you can redistribute it and/or modify |
9 | * it under the terms of the GNU Affero General Public License as published by |
10 | * the Free Software Foundation, either version 3 of the License, or |
11 | * (at your option) any later version. |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU Affero General Public License for more details. |
17 | * |
18 | * You should have received a copy of the GNU Affero General Public License |
19 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
20 | */ |
21 | |
22 | declare(strict_types=1); |
23 | |
24 | namespace App\Domain\User\Form\Type; |
25 | |
26 | use App\Domain\User\Model\Collectivity; |
27 | use App\Domain\User\Model\ReviewData; |
28 | use App\Domain\User\Model\User; |
29 | use FOS\CKEditorBundle\Form\Type\CKEditorType; |
30 | use Knp\DictionaryBundle\Form\Type\DictionaryType; |
31 | use Symfony\Component\Form\AbstractType; |
32 | use Symfony\Component\Form\Extension\Core\Type\CheckboxType; |
33 | use Symfony\Component\Form\Extension\Core\Type\ChoiceType; |
34 | use Symfony\Component\Form\Extension\Core\Type\CollectionType; |
35 | use Symfony\Component\Form\Extension\Core\Type\HiddenType; |
36 | use Symfony\Component\Form\Extension\Core\Type\NumberType; |
37 | use Symfony\Component\Form\Extension\Core\Type\TextareaType; |
38 | use Symfony\Component\Form\Extension\Core\Type\TextType; |
39 | use Symfony\Component\Form\Extension\Core\Type\UrlType; |
40 | use Symfony\Component\Form\FormBuilderInterface; |
41 | use Symfony\Component\OptionsResolver\OptionsResolver; |
42 | use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; |
43 | use Symfony\Component\Security\Core\Security; |
44 | |
45 | class CollectivityType extends AbstractType |
46 | { |
47 | /** |
48 | * @var AuthorizationCheckerInterface |
49 | */ |
50 | private $authorizationChecker; |
51 | |
52 | /** |
53 | * @var Security |
54 | */ |
55 | private $security; |
56 | |
57 | /** |
58 | * CollectivityType constructor. |
59 | */ |
60 | public function __construct(Security $security, AuthorizationCheckerInterface $authorizationChecker) |
61 | { |
62 | $this->authorizationChecker = $authorizationChecker; |
63 | $this->security = $security; |
64 | } |
65 | |
66 | /** |
67 | * Build type form. |
68 | */ |
69 | public function buildForm(FormBuilderInterface $builder, array $options) |
70 | { |
71 | /** @var User $user */ |
72 | $user = $this->security->getUser(); |
73 | // Add collectivity general information only for admins |
74 | if ($this->authorizationChecker->isGranted('ROLE_ADMIN')) { |
75 | $builder |
76 | ->add('name', TextType::class, [ |
77 | 'label' => 'user.organization.label.name', |
78 | 'required' => true, |
79 | 'attr' => [ |
80 | 'maxlength' => 255, |
81 | ], |
82 | 'purify_html' => true, |
83 | ]) |
84 | ->add('shortName', TextType::class, [ |
85 | 'label' => 'user.organization.label.short_name', |
86 | 'required' => true, |
87 | 'attr' => [ |
88 | 'maxlength' => 20, |
89 | ], |
90 | 'purify_html' => true, |
91 | ]) |
92 | ->add('type', DictionaryType::class, [ |
93 | 'label' => 'user.organization.label.type', |
94 | 'required' => true, |
95 | 'name' => 'user_collectivity_type', |
96 | 'multiple' => false, |
97 | 'expanded' => true, |
98 | ]) |
99 | ->add('siren', TextType::class, [ |
100 | 'label' => 'user.organization.label.siren', |
101 | 'required' => true, |
102 | 'attr' => [ |
103 | 'maxlength' => 14, |
104 | 'pattern' => '\d{9,14}', |
105 | 'title' => 'Le SIREN doit contenir uniquement des chiffres, avec une longueur de 9 à 14 caractères.', |
106 | ], |
107 | ]) |
108 | ->add('active', ChoiceType::class, [ |
109 | 'label' => 'user.organization.label.active', |
110 | 'required' => true, |
111 | 'choices' => [ |
112 | 'global.label.active' => true, |
113 | 'global.label.inactive' => false, |
114 | ], |
115 | 'multiple' => false, |
116 | 'expanded' => true, |
117 | ]) |
118 | ->add('hasModuleConformiteTraitement', CheckboxType::class, [ |
119 | 'label' => 'user.organization.label.has_module_conformite_traitement', |
120 | 'required' => false, |
121 | ]) |
122 | ->add('hasModuleConformiteOrganisation', CheckboxType::class, [ |
123 | 'label' => 'user.organization.label.has_module_conformite_organisation', |
124 | 'required' => false, |
125 | ]) |
126 | ->add('hasModuleTools', CheckboxType::class, [ |
127 | 'label' => 'user.organization.label.has_module_tools', |
128 | 'required' => false, |
129 | ]) |
130 | ->add('informationsComplementaires', TextareaType::class, [ |
131 | 'label' => 'user.organization.label.other_information', |
132 | 'required' => false, |
133 | 'purify_html' => true, |
134 | ]) |
135 | ->add('finessGeo', TextType::class, [ |
136 | 'label' => 'user.organization.label.finess_geo', |
137 | 'required' => false, |
138 | 'attr' => [ |
139 | 'maxlength' => 255, |
140 | ], |
141 | 'purify_html' => true, |
142 | ]) |
143 | ->add('services', CollectionType::class, [ |
144 | 'label' => false, |
145 | 'entry_type' => ServiceType::class, |
146 | 'allow_add' => true, |
147 | 'allow_delete' => true, |
148 | 'by_reference' => false, |
149 | ]) |
150 | ->add('isServicesEnabled', CheckboxType::class, [ |
151 | 'label' => 'user.organization.label.has_module_services', |
152 | 'required' => false, |
153 | ]) |
154 | ; |
155 | } |
156 | $emptyReview = new ReviewData(); |
157 | if (isset($options['data'])) { |
158 | $emptyReview->setCollectivity($options['data']); |
159 | } |
160 | |
161 | // Now add standard information |
162 | $builder |
163 | ->add('population', NumberType::class, [ |
164 | 'label' => 'user.organization.label.population', |
165 | 'required' => false, |
166 | ]) |
167 | ->add('nbrAgents', NumberType::class, [ |
168 | 'label' => 'user.organization.label.nbr_agents', |
169 | 'required' => false, |
170 | ]) |
171 | ->add('address', AddressType::class, [ |
172 | 'label' => false, |
173 | 'required' => true, |
174 | ]) |
175 | ->add('reviewData', ReviewDataType::class, [ |
176 | 'label' => false, |
177 | 'required' => true, |
178 | 'empty_data' => $emptyReview, |
179 | 'data' => isset($options['data']) && $options['data']->getReviewData() ? $options['data']->getReviewData() : $emptyReview, |
180 | ]) |
181 | ->add('legalManager', ContactType::class, [ |
182 | 'label' => 'user.collectivity.form.legal_manager', |
183 | 'required' => true, |
184 | 'validation_groups' => ['default', 'collectivity_legal_manager'], |
185 | ]) |
186 | ->add('referent', ContactType::class, [ |
187 | 'label' => 'user.collectivity.form.referent', |
188 | 'required' => true, |
189 | 'validation_groups' => ['default', 'collectivity_referent'], |
190 | ]) |
191 | ->add('nbrCnil', NumberType::class, [ |
192 | 'label' => 'user.organization.label.nbr_cnil', |
193 | 'required' => false, |
194 | ]) |
195 | ->add('differentDpo', CheckboxType::class, [ |
196 | 'label' => 'user.organization.label.different_dpo', |
197 | 'required' => false, |
198 | ]) |
199 | ->add('dpo', ContactType::class, [ |
200 | 'label' => 'user.collectivity.form.dpo', |
201 | 'required' => false, |
202 | 'validation_groups' => ['default', 'collectivity_dpo'], |
203 | ]) |
204 | ->add('differentItManager', CheckboxType::class, [ |
205 | 'label' => 'user.organization.label.different_it_manager', |
206 | 'required' => false, |
207 | ]) |
208 | ->add('itManager', ContactType::class, [ |
209 | 'label' => 'user.collectivity.form.it_manager', |
210 | 'required' => false, |
211 | ]) |
212 | ->add('reportingBlockManagementCommitment', CKEditorType::class, [ |
213 | 'label' => 'user.organization.label.management_commitment', |
214 | 'required' => false, |
215 | ]) |
216 | ->add('reportingBlockContinuousImprovement', CKEditorType::class, [ |
217 | 'label' => 'user.organization.label.continuous_improvement', |
218 | 'required' => false, |
219 | ]) |
220 | ->add('comiteIlContacts', CollectionType::class, [ |
221 | 'label' => false, |
222 | 'entry_type' => ComiteIlContactType::class, |
223 | 'allow_add' => true, |
224 | 'allow_delete' => true, |
225 | 'by_reference' => false, |
226 | ]) |
227 | ->add('website', UrlType::class, [ |
228 | 'label' => 'user.organization.label.website', |
229 | 'required' => false, |
230 | 'attr' => [ |
231 | 'placeholder' => 'user.organization.placeholder.website', |
232 | ], |
233 | ]) |
234 | ->add('updatedBy', HiddenType::class, [ |
235 | 'required' => false, |
236 | 'data' => $user ? $user->getFirstName() . ' ' . strtoupper($user->getLastName()) : '', |
237 | ]) |
238 | ; |
239 | } |
240 | |
241 | /** |
242 | * Provide type options. |
243 | */ |
244 | public function configureOptions(OptionsResolver $resolver) |
245 | { |
246 | $resolver |
247 | ->setDefaults([ |
248 | 'data_class' => Collectivity::class, |
249 | 'validation_groups' => [ |
250 | 'default', |
251 | ], |
252 | ]); |
253 | } |
254 | } |