Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
86.23% |
144 / 167 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
ContractorType | |
86.23% |
144 / 167 |
|
66.67% |
2 / 3 |
11.32 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
buildForm | |
85.26% |
133 / 156 |
|
0.00% |
0 / 1 |
9.26 | |||
configureOptions | |
100.00% |
8 / 8 |
|
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\Registry\Form\Type; |
25 | |
26 | use App\Application\Form\Type\LinkableType; |
27 | use App\Domain\Registry\Form\Type\Embeddable\AddressType; |
28 | use App\Domain\Registry\Model\Contractor; |
29 | use App\Domain\Registry\Model\Mesurement; |
30 | use App\Domain\Registry\Model\Proof; |
31 | use App\Domain\Registry\Model\Request; |
32 | use App\Domain\Registry\Model\Tool; |
33 | use App\Domain\Registry\Model\Treatment; |
34 | use App\Domain\Registry\Model\Violation; |
35 | use App\Domain\User\Form\Type\ContactType; |
36 | use App\Domain\User\Model\Service; |
37 | use App\Domain\User\Model\User; |
38 | use Doctrine\ORM\EntityRepository; |
39 | use Symfony\Bridge\Doctrine\Form\Type\EntityType; |
40 | use Symfony\Component\Form\Extension\Core\Type\CheckboxType; |
41 | use Symfony\Component\Form\Extension\Core\Type\HiddenType; |
42 | use Symfony\Component\Form\Extension\Core\Type\TextareaType; |
43 | use Symfony\Component\Form\Extension\Core\Type\TextType; |
44 | use Symfony\Component\Form\FormBuilderInterface; |
45 | use Symfony\Component\OptionsResolver\OptionsResolver; |
46 | use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; |
47 | use Symfony\Component\Security\Core\Security; |
48 | |
49 | class ContractorType extends LinkableType |
50 | { |
51 | /** |
52 | * @var Security |
53 | */ |
54 | private $security; |
55 | |
56 | /** |
57 | * @var AuthorizationCheckerInterface |
58 | */ |
59 | private $authorizationChecker; |
60 | |
61 | public function __construct(Security $security, AuthorizationCheckerInterface $authorizationChecker) |
62 | { |
63 | $this->security = $security; |
64 | $this->authorizationChecker = $authorizationChecker; |
65 | parent::__construct($security); |
66 | } |
67 | |
68 | /** |
69 | * Build type form. |
70 | */ |
71 | public function buildForm(FormBuilderInterface $builder, array $options) |
72 | { |
73 | $contractor = $options['data']; |
74 | $collectivity = null; |
75 | if ($contractor) { |
76 | $collectivity = $contractor->getCollectivity(); |
77 | } |
78 | /** @var User $user */ |
79 | $user = $this->security->getUser(); |
80 | |
81 | if (!$collectivity) { |
82 | $collectivity = $user->getCollectivity(); |
83 | } |
84 | $builder |
85 | ->add('name', TextType::class, [ |
86 | 'label' => 'registry.contractor.label.name', |
87 | 'required' => true, |
88 | 'attr' => [ |
89 | 'maxlength' => 255, |
90 | ], |
91 | 'purify_html' => true, |
92 | ]) |
93 | ; |
94 | if ($contractor->getCollectivity()->getIsServicesEnabled()) { |
95 | $builder |
96 | ->add('service', EntityType::class, [ |
97 | 'class' => Service::class, |
98 | 'label' => 'registry.label.service', |
99 | 'query_builder' => function (EntityRepository $er) use ($contractor) { |
100 | /** @var User $authenticatedUser */ |
101 | $authenticatedUser = $this->security->getUser(); |
102 | $collectivity = $contractor->getCollectivity(); |
103 | |
104 | $qb = $er->createQueryBuilder('s') |
105 | ->where('s.collectivity = :collectivity') |
106 | ->setParameter(':collectivity', $collectivity) |
107 | ; |
108 | if (!$this->authorizationChecker->isGranted('ROLE_ADMIN') && $authenticatedUser->getServices()->getValues()) { |
109 | $qb->leftJoin('s.users', 'users') |
110 | ->andWhere('users.id = :id') |
111 | ->setParameter('id', $authenticatedUser->getId()) |
112 | ; |
113 | } |
114 | $qb |
115 | ->orderBy('s.name', 'ASC'); |
116 | |
117 | return $qb; |
118 | }, |
119 | 'required' => false, |
120 | ]) |
121 | ; |
122 | } |
123 | /** @var User $user */ |
124 | $user = $this->security->getUser(); |
125 | $builder |
126 | ->add('referent', TextType::class, [ |
127 | 'label' => 'registry.contractor.label.referent', |
128 | 'required' => false, |
129 | 'attr' => [ |
130 | 'maxlength' => 255, |
131 | ], |
132 | 'purify_html' => true, |
133 | ]) |
134 | ->add('contractualClausesVerified', CheckboxType::class, [ |
135 | 'label' => 'registry.contractor.label.contractual_clauses_verified', |
136 | 'required' => false, |
137 | ]) |
138 | ->add('adoptedSecurityFeatures', CheckboxType::class, [ |
139 | 'label' => 'registry.contractor.label.adopted_security_features', |
140 | 'required' => false, |
141 | ]) |
142 | ->add('maintainsTreatmentRegister', CheckboxType::class, [ |
143 | 'label' => 'registry.contractor.label.maintains_treatment_register', |
144 | 'required' => false, |
145 | ]) |
146 | ->add('sendingDataOutsideEu', CheckboxType::class, [ |
147 | 'label' => 'registry.contractor.label.sending_data_outside_eu', |
148 | 'required' => false, |
149 | ]) |
150 | ->add('otherInformations', TextareaType::class, [ |
151 | 'label' => 'registry.contractor.label.other_informations', |
152 | 'required' => false, |
153 | 'attr' => [ |
154 | 'rows' => 4, |
155 | ], |
156 | 'purify_html' => true, |
157 | ]) |
158 | ->add('address', AddressType::class, [ |
159 | 'label' => 'registry.contractor.form.address', |
160 | 'required' => false, |
161 | 'validation_groups' => ['default', 'contractor'], |
162 | ]) |
163 | ->add('legalManager', ContactType::class, [ |
164 | 'label' => 'registry.contractor.form.legal_manager', |
165 | 'required' => false, |
166 | ]) |
167 | ->add('hasDpo', CheckboxType::class, [ |
168 | 'label' => 'registry.contractor.label.has_dpo', |
169 | 'required' => false, |
170 | ]) |
171 | ->add('dpo', ContactType::class, [ |
172 | 'label' => 'registry.contractor.form.dpo', |
173 | 'required' => false, |
174 | ]) |
175 | ->add('mesurements', |
176 | EntityType::class, |
177 | $this->getLinkedFormField( |
178 | 'global.label.linked_mesurement', |
179 | Mesurement::class, |
180 | $contractor, |
181 | 'Actions de protection', |
182 | ['status' => 'asc', 'name' => 'asc'], |
183 | ), |
184 | ) |
185 | ->add('treatments', EntityType::class, $this->getLinkedFormField( |
186 | 'global.label.linked_treatment', |
187 | Treatment::class, |
188 | $contractor, |
189 | 'Traitements', |
190 | ['active' => 'desc', 'name' => 'asc'], |
191 | ), |
192 | ) |
193 | ->add('violations', EntityType::class, $this->getLinkedFormField( |
194 | 'global.label.linked_violation', |
195 | Violation::class, |
196 | $contractor, |
197 | 'Violations', |
198 | ['deletedAt' => 'asc', 'date' => 'asc'], |
199 | ), |
200 | ) |
201 | ->add('proofs', EntityType::class, $this->getLinkedFormField( |
202 | 'global.label.linked_proof', |
203 | Proof::class, |
204 | $contractor, |
205 | 'Preuves', |
206 | ['deletedAt' => 'asc', 'name' => 'asc'], |
207 | ), |
208 | ) |
209 | ->add('requests', EntityType::class, $this->getLinkedFormField( |
210 | 'global.label.linked_request', |
211 | Request::class, |
212 | $contractor, |
213 | 'Demandes', |
214 | ['deletedAt' => 'asc', 'date' => 'asc'], |
215 | ), |
216 | ) |
217 | ->add('contractors', EntityType::class, $this->getLinkedFormField( |
218 | 'global.label.linked_contractor', |
219 | Contractor::class, |
220 | $contractor, |
221 | 'Sous-traitants', |
222 | ['name' => 'asc'], |
223 | ), |
224 | ) |
225 | ->add('updatedBy', HiddenType::class, [ |
226 | 'required' => false, |
227 | 'data' => $user ? $user->getFirstName() . ' ' . strtoupper($user->getLastName()) : '', |
228 | ]) |
229 | ; |
230 | |
231 | if ($collectivity && $collectivity->isHasModuleTools()) { |
232 | $builder->add('tools', EntityType::class, $this->getLinkedFormField( |
233 | 'global.label.linked_tool', |
234 | Tool::class, |
235 | $contractor, |
236 | 'Logiciels et supports', |
237 | 'name', |
238 | ), |
239 | ); |
240 | } |
241 | } |
242 | |
243 | /** |
244 | * Provide type options. |
245 | */ |
246 | public function configureOptions(OptionsResolver $resolver) |
247 | { |
248 | $resolver |
249 | ->setDefaults([ |
250 | 'data_class' => Contractor::class, |
251 | 'validation_groups' => [ |
252 | 'default', |
253 | 'contractor', |
254 | ], |
255 | ]); |
256 | } |
257 | } |