Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
16.67% covered (danger)
16.67%
15 / 90
25.00% covered (danger)
25.00%
1 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
ReviewDataType
16.67% covered (danger)
16.67%
15 / 90
25.00% covered (danger)
25.00%
1 / 4
67.87
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 buildForm
0.00% covered (danger)
0.00%
0 / 65
0.00% covered (danger)
0.00%
0 / 1
56
 configureOptions
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
2
 getSections
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
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
22declare(strict_types=1);
23
24namespace App\Domain\User\Form\Type;
25
26use App\Domain\User\Model\Collectivity;
27use App\Domain\User\Model\ReviewData;
28use Symfony\Component\Form\AbstractType;
29use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
30use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
31use Symfony\Component\Form\Extension\Core\Type\FileType;
32use Symfony\Component\Form\Extension\Core\Type\HiddenType;
33use Symfony\Component\Form\Extension\Core\Type\TextType;
34use Symfony\Component\Form\FormBuilderInterface;
35use Symfony\Component\OptionsResolver\OptionsResolver;
36use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
37use Symfony\Component\Validator\Constraints\File;
38
39class ReviewDataType extends AbstractType
40{
41    /**
42     * @var AuthorizationCheckerInterface
43     */
44    private $authorizationChecker;
45
46    private string $maxSize;
47
48    /**
49     * CollectivityType constructor.
50     */
51    public function __construct(AuthorizationCheckerInterface $authorizationChecker, string $maxSize)
52    {
53        $this->maxSize              = $maxSize;
54        $this->authorizationChecker = $authorizationChecker;
55    }
56
57    /**
58     * Build type form.
59     */
60    public function buildForm(FormBuilderInterface $builder, array $options)
61    {
62        $logo = null;
63        if (isset($options['data'])) {
64            $logo = $options['data']->getLogo();
65        }
66        if ($logo) {
67            $builder->add('deleteLogo', HiddenType::class, [
68                'mapped'   => false,
69                'required' => false,
70                'attr'     => [
71                    'value' => '0',
72                ],
73            ]);
74        }
75        $builder
76            ->add('documentName', TextType::class, [
77                'label'       => 'user.organization.label.document_name',
78                'required'    => true,
79                'purify_html' => true,
80            ])
81            ->add('logo', FileType::class, [
82                'label'       => 'user.organization.label.logo',
83                'mapped'      => false,
84                'required'    => false,
85                'constraints' => [
86                    // Élément suivant commenté, car il génère un message d'erreur en plus de l'autre message
87                    // new Image(['groups' => ['default']]),
88                    new File([
89                        'maxSize'   => $this->maxSize,
90                        'groups'    => ['default'],
91                        'mimeTypes' => [
92                            'image/png', // .png
93                            'image/jpeg', // .jpg, .jpeg
94                        ],
95                        'mimeTypesMessage' => 'document_validator.document_file.thumbnail',
96                    ]),
97                ],
98                'attr' => [
99                    'accept' => 'image/*',
100                ],
101            ])
102            ->add('showCollectivityLogoFooter', CheckboxType::class, [
103                'label'    => 'user.organization.label.show_collectivity_logo',
104                'required' => false,
105            ])
106            ->add('showDPDLogoFooter', CheckboxType::class, [
107                'label'    => 'user.organization.label.show_dpd_logo',
108                'required' => false,
109            ])
110        ;
111        if ($this->authorizationChecker->isGranted('ROLE_ADMIN')) {
112            /** @var Collectivity|null $collectivity */
113            $collectivity = null;
114            //            $sections = [
115            //                ReviewData::CONTINUOUS_AMELIORATION,
116            //                ReviewData::CONTRACTOR_REGISTRY,
117            //                ReviewData::PROOF_LIST,
118            //                ReviewData::PROTECT_ACTIONS,
119            //                ReviewData::REQUEST_REGISTRY,
120            //                ReviewData::SUIVI,
121            //                ReviewData::TREATMENT_CONFORMITY,
122            //                ReviewData::AIPD,
123            //                ReviewData::COLLECTIVITY_CONFORMITY,
124            //                ReviewData::CONFORMITY_EVALUATION,
125            //                ReviewData::TREATMENT_REGISTRY,
126            //                ReviewData::USER_LIST,
127            //                ReviewData::VIOLATION_REGISTRY,
128            //                ReviewData::TOOL_REGISTRY,
129            //            ];
130            if (isset($options['data'])) {
131                $collectivity = $options['data']->getCollectivity();
132                //                $sections = $options['data']->getSections();
133            }
134            if (!$collectivity && isset($options['empty_data'])) {
135                $collectivity = $options['empty_data']->getCollectivity();
136            }
137
138            // Always show every choice: https://gitlab.adullact.net/soluris/madis/-/issues/932
139
140            $choices = self::getSections();
141
142            $builder->add('sections', ChoiceType::class, [
143                'label'    => 'user.organization.label.sections',
144                'required' => false,
145                //                'data' => $sections,
146                'choices'  => $choices,
147                'multiple' => true,
148                'expanded' => false,
149                'attr'     => [
150                    'class'            => 'selectpicker',
151                    'data-live-search' => 'true',
152                    'title'            => 'global.placeholder.multiple_select',
153                    'aria-label'       => 'Sections du bilan',
154                ],
155            ]);
156        }
157    }
158
159    /**
160     * Provide type options.
161     */
162    public function configureOptions(OptionsResolver $resolver)
163    {
164        $resolver
165            ->setDefaults([
166                'data_class'        => ReviewData::class,
167                'validation_groups' => [
168                    'default',
169                    'user',
170                ],
171            ]);
172    }
173
174    public static function getSections(): array
175    {
176        return [
177            'user.organization.label.' . ReviewData::TREATMENT_REGISTRY  => ReviewData::TREATMENT_REGISTRY,
178            'user.organization.label.' . ReviewData::CONTRACTOR_REGISTRY => ReviewData::CONTRACTOR_REGISTRY,
179
180            'user.organization.label.' . ReviewData::TOOL_REGISTRY => ReviewData::TOOL_REGISTRY,
181
182            'user.organization.label.' . ReviewData::REQUEST_REGISTRY   => ReviewData::REQUEST_REGISTRY,
183            'user.organization.label.' . ReviewData::VIOLATION_REGISTRY => ReviewData::VIOLATION_REGISTRY,
184
185            'user.organization.label.' . ReviewData::CONFORMITY_EVALUATION => ReviewData::CONFORMITY_EVALUATION,
186
187            'user.organization.label.' . ReviewData::TREATMENT_CONFORMITY => ReviewData::TREATMENT_CONFORMITY,
188
189            'user.organization.label.' . ReviewData::AIPD                    => ReviewData::AIPD,
190            'user.organization.label.' . ReviewData::COLLECTIVITY_CONFORMITY => ReviewData::COLLECTIVITY_CONFORMITY,
191
192            'user.organization.label.' . ReviewData::PROTECT_ACTIONS         => ReviewData::PROTECT_ACTIONS,
193            'user.organization.label.' . ReviewData::CONTINUOUS_AMELIORATION => ReviewData::CONTINUOUS_AMELIORATION,
194
195            'user.organization.label.' . ReviewData::PROOF_LIST => ReviewData::PROOF_LIST,
196
197            // 'user.organization.label.' . ReviewData::SUIVI                   => ReviewData::SUIVI,
198
199            'user.organization.label.' . ReviewData::USER_LIST => ReviewData::USER_LIST,
200        ];
201    }
202}