Passed
Push — master ( 019eb1...c852f2 )
by Yannick
09:06
created

PlatformSettingsSchema::getHiddenSettings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CoreBundle\Settings;
8
9
use Chamilo\CoreBundle\Form\Type\YesNoType;
10
use Chamilo\CoreBundle\Transformer\ArrayToIdentifierTransformer;
11
use Sylius\Bundle\SettingsBundle\Schema\AbstractSettingsBuilder;
12
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
13
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
14
use Symfony\Component\Form\Extension\Core\Type\TextType;
15
use Symfony\Component\Form\Extension\Core\Type\TimezoneType;
16
use Symfony\Component\Form\Extension\Core\Type\UrlType;
17
use Symfony\Component\Form\FormBuilderInterface;
18
19
class PlatformSettingsSchema extends AbstractSettingsSchema
20
{
21
    private static array $tabs = [
22
        'MenuCampusHomepage' => 'campus_homepage',
23
        'MenuMyCourses' => 'my_courses',
24
        'MenuReporting' => 'reporting',
25
        'MenuPlatformAdministration' => 'platform_administration',
26
        'MenuMyAgenda' => 'my_agenda',
27
        'MenuSocial' => 'social',
28
        'MenuVideoConference' => 'videoconference',
29
        'MenuDiagnostics' => 'diagnostics',
30
        'MenuCatalogue' => 'catalogue',
31
        'TopbarCertificate' => 'topbar_certificate',
32
        'TopbarSkills' => 'topbar_skills',
33
    ];
34
35
    public function buildSettings(AbstractSettingsBuilder $builder): void
36
    {
37
        $builder
38
            ->setDefaults(
39
                [
40
                    'institution' => 'Chamilo.org',
41
                    'institution_url' => 'http://www.chamilo.org',
42
                    'institution_address' => '',
43
                    'site_name' => 'Chamilo site',
44
                    'timezone' => 'Europe/Paris',
45
                    'gravatar_enabled' => 'false',
46
                    'gravatar_type' => 'mm',
47
                    'gamification_mode' => ' ',
48
                    'order_user_list_by_official_code' => 'false',
49
                    'cookie_warning' => 'false',
50
                    'donotlistcampus' => 'false',
51
                    'catalog_show_courses_sessions' => '0',
52
                    'course_catalog_hide_private' => 'false',
53
                    'use_custom_pages' => 'false',
54
                    'pdf_logo_header' => '',
55
                    'allow_my_files' => 'true',
56
                    'registered' => 'false',
57
                    'load_term_conditions_section' => 'login',
58
                    'server_type' => 'prod',
59
                    'show_tabs' => array_values(array_diff(self::$tabs, ['videoconference', 'diagnostics'])),
60
                    'chamilo_database_version' => '2.0.0',
61
                    'unoconv_binaries' => '/usr/bin/unoconv',
62
                    'hide_main_navigation_menu' => 'false',
63
                    'pdf_img_dpi' => '96',
64
                    'tracking_skip_generic_data' => 'false',
65
                    'hide_complete_name_in_whoisonline' => 'false',
66
                    'table_default_row' => '0',
67
                    'allow_double_validation_in_registration' => 'false',
68
                    'block_my_progress_page' => 'false',
69
                    'generate_random_login' => 'false',
70
                    'timepicker_increment' => '5',
71
                    'proxy_settings' => '',
72
                    'video_features' => '',
73
                    'table_row_list' => '',
74
                    'webservice_return_user_field' => 'oauth2_id',
75
                    'multiple_url_hide_disabled_settings' => 'false',
76
                    'login_max_attempt_before_blocking_account' => '0',
77
                    'force_renew_password_at_first_login' => 'false',
78
                    'hide_breadcrumb_if_not_allowed' => 'false',
79
                    'extldap_config' => '',
80
                    'update_student_expiration_x_date' => '',
81
                    'user_status_show_options_enabled' => 'false',
82
                    'user_status_show_option' => '',
83
                    'user_number_of_days_for_default_expiration_date_per_role' => '',
84
                    'user_edition_extra_field_to_check' => 'ExtrafieldLabel',
85
                    'user_hide_never_expire_option' => 'false',
86
                    'platform_logo_url' => 'https://chamilo.org',
87
                    'use_career_external_id_as_identifier_in_diagrams' => 'false',
88
                    'disable_webservices' => 'false',
89
                    'webservice_enable_adminonly_api' => 'false',
90
                    'allow_working_time_edition' => 'false',
91
                    'disable_user_conditions_sender_id' => '0',
92
                    'portfolio_advanced_sharing' => 'false',
93
                    'redirect_index_to_url_for_logged_users' => '',
94
                    'default_menu_entry_for_course_or_session' => 'my_courses',
95
                    'notification_event' => 'false',
96
                ]
97
            )
98
            ->setTransformer(
99
                'show_tabs',
100
                new ArrayToIdentifierTransformer()
101
            )
102
        ;
103
        $allowedTypes = [
104
            'institution' => ['string'],
105
            'institution_url' => ['string'],
106
            'site_name' => ['string'],
107
            'timezone' => ['string'],
108
            'gravatar_enabled' => ['string'],
109
            'gravatar_type' => ['string'],
110
            'show_tabs' => ['array', 'null'],
111
        ];
112
113
        $this->setMultipleAllowedTypes($allowedTypes, $builder);
114
    }
115
116
    public function buildForm(FormBuilderInterface $builder): void
117
    {
118
        $builder
119
            ->add('institution')
120
            ->add('institution_url', UrlType::class)
121
            ->add('institution_address')
122
            ->add('site_name')
123
            ->add('timezone', TimezoneType::class)
124
            ->add('gravatar_enabled', YesNoType::class)
125
            ->add(
126
                'gravatar_type',
127
                ChoiceType::class,
128
                [
129
                    'choices' => [
130
                        'mistery-man' => 'mm',
131
                        'identicon' => 'identicon',
132
                        'monsterid' => 'monsterid',
133
                        'wavatar' => 'wavatar',
134
                    ],
135
                ]
136
            )
137
            ->add('gamification_mode')
138
            ->add('order_user_list_by_official_code', YesNoType::class)
139
            ->add('cookie_warning', YesNoType::class)
140
            ->add('donotlistcampus', YesNoType::class)
141
            ->add('course_catalog_hide_private', YesNoType::class)
142
            ->add(
143
                'catalog_show_courses_sessions',
144
                ChoiceType::class,
145
                [
146
                    'choices' => [
147
                        'Hide catalogue' => '-1',
148
                        'Show only courses' => '0',
149
                        'Show only sessions' => '1',
150
                        'Show courses and sessions' => '2',
151
                    ],
152
                ]
153
            )
154
            ->add('use_custom_pages', YesNoType::class)
155
            ->add('pdf_logo_header')
156
            ->add('allow_my_files', YesNoType::class)
157
            // old settings with no category
158
            ->add('chamilo_database_version')
159
            ->add(
160
                'load_term_conditions_section',
161
                ChoiceType::class,
162
                [
163
                    'choices' => [
164
                        'Login' => 'login',
165
                        'Course' => 'course',
166
                    ],
167
                ]
168
            )
169
            ->add(
170
                'show_tabs',
171
                ChoiceType::class,
172
                [
173
                    'multiple' => true,
174
                    'choices' => self::$tabs
175
                ],
176
            )
177
            ->add(
178
                'unoconv_binaries',
179
                TextType::class
180
            )
181
            ->add('hide_main_navigation_menu', YesNoType::class)
182
            ->add('pdf_img_dpi', TextType::class)
183
            ->add('tracking_skip_generic_data', YesNoType::class)
184
            ->add('hide_complete_name_in_whoisonline', YesNoType::class)
185
            ->add('table_default_row', TextType::class)
186
            ->add('allow_double_validation_in_registration', YesNoType::class)
187
            ->add('block_my_progress_page', YesNoType::class)
188
            ->add('generate_random_login', YesNoType::class)
189
            ->add('timepicker_increment', TextType::class)
190
            ->add(
191
                'proxy_settings',
192
                TextareaType::class,
193
                [
194
                    'help_html' => true,
195
                    'help' => $this->settingArrayHelpValue('proxy_settings'),
196
                ]
197
            )
198
            ->add(
199
                'video_features',
200
                TextareaType::class,
201
                [
202
                    'help_html' => true,
203
                    'help' => $this->settingArrayHelpValue('video_features'),
204
                ]
205
            )
206
            ->add(
207
                'table_row_list',
208
                TextareaType::class,
209
                [
210
                    'help_html' => true,
211
                    'help' => $this->settingArrayHelpValue('table_row_list'),
212
                ]
213
            )
214
            ->add('webservice_return_user_field', TextType::class)
215
            ->add('multiple_url_hide_disabled_settings', YesNoType::class)
216
            ->add('login_max_attempt_before_blocking_account', TextType::class)
217
            ->add('force_renew_password_at_first_login', YesNoType::class)
218
            ->add('hide_breadcrumb_if_not_allowed', YesNoType::class)
219
            ->add(
220
                'extldap_config',
221
                TextareaType::class,
222
                [
223
                    'help_html' => true,
224
                    'help' => $this->settingArrayHelpValue('extldap_config'),
225
                ]
226
            )
227
            ->add(
228
                'update_student_expiration_x_date',
229
                TextareaType::class,
230
                [
231
                    'help_html' => true,
232
                    'help' => $this->settingArrayHelpValue('update_student_expiration_x_date'),
233
                ]
234
            )
235
            ->add('user_status_show_options_enabled', YesNoType::class)
236
            ->add(
237
                'user_status_show_option',
238
                TextareaType::class,
239
                [
240
                    'help_html' => true,
241
                    'help' => $this->settingArrayHelpValue('user_status_show_option'),
242
                ]
243
            )
244
            ->add(
245
                'user_number_of_days_for_default_expiration_date_per_role',
246
                TextareaType::class,
247
                [
248
                    'help_html' => true,
249
                    'help' => $this->settingArrayHelpValue('user_number_of_days_for_default_expiration_date_per_role'),
250
                ]
251
            )
252
            ->add('user_edition_extra_field_to_check', TextType::class)
253
            ->add('user_hide_never_expire_option', YesNoType::class)
254
            ->add('platform_logo_url', TextType::class)
255
            ->add('use_career_external_id_as_identifier_in_diagrams', YesNoType::class)
256
            ->add('disable_webservices', YesNoType::class)
257
            ->add('webservice_enable_adminonly_api', YesNoType::class)
258
            ->add('allow_working_time_edition', YesNoType::class)
259
            ->add('disable_user_conditions_sender_id', TextType::class)
260
            ->add('portfolio_advanced_sharing', TextType::class)
261
            ->add('redirect_index_to_url_for_logged_users', TextType::class)
262
            ->add(
263
                'default_menu_entry_for_course_or_session',
264
                ChoiceType::class,
265
                [
266
                    'choices' => [
267
                        'My courses' => 'my_courses',
268
                        'My sessions' => 'my_sessions',
269
                    ],
270
                ]
271
            )
272
            ->add('notification_event', YesNoType::class)
273
        ;
274
275
        $this->updateFormFieldsFromSettingsInfo($builder);
276
    }
277
278
    /**
279
     * Returns the list of internal settings that should be hidden from forms and search.
280
     */
281
    public function getHiddenSettings(): array
282
    {
283
        return [
284
            'registered',
285
        ];
286
    }
287
288
    private function settingArrayHelpValue(string $variable): string
289
    {
290
        $values = [
291
            'proxy_settings' => "<pre>
292
                [
293
                    'stream_context_create' => [
294
                        'http' => [
295
                            'proxy' => 'tcp://example.com:8080',
296
                            'request_fulluri' => true
297
                        ]
298
                    ],
299
                    'curl_setopt_array' => [
300
                        'CURLOPT_PROXY' => 'http://example.com',
301
                        'CURLOPT_PROXYPORT' => '8080'
302
                    ]
303
                ]
304
                </pre>",
305
            'video_features' => "<pre>
306
                ['features' => ['speed']]
307
                </pre>",
308
            'table_row_list' => "<pre>
309
                ['options' => [50, 100, 200, 500]]
310
                </pre>",
311
            'extldap_config' => "<pre>
312
                ['host' => '', 'port' => '']
313
                </pre>",
314
            'update_student_expiration_x_date' => "<pre>
315
                [
316
                    'days' => 0,
317
                    'months' => 0,
318
                ]
319
                </pre>",
320
            'user_status_show_option' => "<pre>
321
                [
322
                    'COURSEMANAGER' => true,
323
                    'STUDENT' => true,
324
                    'DRH' => false,
325
                    'SESSIONADMIN' => false,
326
                    'STUDENT_BOSS' => false,
327
                    'INVITEE' => false
328
                ]
329
                </pre>",
330
            'user_number_of_days_for_default_expiration_date_per_role' => "<pre>
331
                [
332
                    'COURSEMANAGER' => 365,
333
                    'STUDENT' => 31,
334
                    'DRH' => 31,
335
                    'SESSIONADMIN' => 60,
336
                    'STUDENT_BOSS' => 60,
337
                    'INVITEE' => 31
338
                ]
339
                </pre>",
340
        ];
341
342
        $returnValue = [];
343
        if (isset($values[$variable])) {
344
            $returnValue = $values[$variable];
345
        }
346
347
        return $returnValue;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $returnValue could return the type array which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
348
    }
349
}
350