Passed
Push — master ( 702f24...55adc1 )
by Yannick
09:28
created

PlatformSettingsSchema::settingArrayHelpValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 60
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 12
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 60
rs 9.8666

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
        'MenuSessionAdmin' => 'session_admin',
32
        'TopbarCertificate' => 'topbar_certificate',
33
        'TopbarSkills' => 'topbar_skills',
34
    ];
35
36
    public function buildSettings(AbstractSettingsBuilder $builder): void
37
    {
38
        $builder
39
            ->setDefaults(
40
                [
41
                    'institution' => 'Chamilo.org',
42
                    'institution_url' => 'http://www.chamilo.org',
43
                    'institution_address' => '',
44
                    'site_name' => 'Chamilo site',
45
                    'timezone' => 'Europe/Paris',
46
                    'gravatar_enabled' => 'false',
47
                    'gravatar_type' => 'mm',
48
                    'gamification_mode' => ' ',
49
                    'order_user_list_by_official_code' => 'false',
50
                    'cookie_warning' => 'false',
51
                    'donotlistcampus' => 'false',
52
                    'catalog_show_courses_sessions' => '0',
53
                    'course_catalog_hide_private' => 'false',
54
                    'use_custom_pages' => 'false',
55
                    'pdf_logo_header' => '',
56
                    'allow_my_files' => 'true',
57
                    'registered' => 'false',
58
                    'load_term_conditions_section' => 'login',
59
                    'server_type' => 'prod',
60
                    'show_tabs' => array_values(array_diff(self::$tabs, ['videoconference', 'diagnostics'])),
61
                    'chamilo_database_version' => '2.0.0',
62
                    'unoconv_binaries' => '/usr/bin/unoconv',
63
                    'hide_main_navigation_menu' => 'false',
64
                    'pdf_img_dpi' => '96',
65
                    'tracking_skip_generic_data' => 'false',
66
                    'hide_complete_name_in_whoisonline' => 'false',
67
                    'table_default_row' => '0',
68
                    'allow_double_validation_in_registration' => 'false',
69
                    'block_my_progress_page' => 'false',
70
                    'generate_random_login' => 'false',
71
                    'timepicker_increment' => '5',
72
                    'proxy_settings' => '',
73
                    'video_features' => '',
74
                    'table_row_list' => '',
75
                    'webservice_return_user_field' => 'oauth2_id',
76
                    'multiple_url_hide_disabled_settings' => 'false',
77
                    'login_max_attempt_before_blocking_account' => '0',
78
                    'force_renew_password_at_first_login' => 'false',
79
                    'hide_breadcrumb_if_not_allowed' => 'false',
80
                    'extldap_config' => '',
81
                    'update_student_expiration_x_date' => '',
82
                    'user_status_show_options_enabled' => 'false',
83
                    'user_status_show_option' => '',
84
                    'user_number_of_days_for_default_expiration_date_per_role' => '',
85
                    'user_edition_extra_field_to_check' => 'ExtrafieldLabel',
86
                    'user_hide_never_expire_option' => 'false',
87
                    'platform_logo_url' => 'https://chamilo.org',
88
                    'use_career_external_id_as_identifier_in_diagrams' => 'false',
89
                    'disable_webservices' => 'false',
90
                    'webservice_enable_adminonly_api' => 'false',
91
                    'allow_working_time_edition' => 'false',
92
                    'disable_user_conditions_sender_id' => '0',
93
                    'portfolio_advanced_sharing' => 'false',
94
                    'redirect_index_to_url_for_logged_users' => '',
95
                    'default_menu_entry_for_course_or_session' => 'my_courses',
96
                    'notification_event' => 'false',
97
                    'show_tabs_per_role' => '{}',
98
                    'session_admin_user_subscription_search_extra_field_to_search' => '',
99
                    'push_notification_settings' => '',
100
                ]
101
            )
102
            ->setTransformer(
103
                'show_tabs',
104
                new ArrayToIdentifierTransformer()
105
            );
106
107
        $allowedTypes = [
108
            'institution' => ['string'],
109
            'institution_url' => ['string'],
110
            'site_name' => ['string'],
111
            'timezone' => ['string'],
112
            'gravatar_enabled' => ['string'],
113
            'gravatar_type' => ['string'],
114
            'show_tabs' => ['array', 'null'],
115
            'show_tabs_per_role' => ['string', 'null'],
116
            'session_admin_user_subscription_search_extra_field_to_search' => ['string', 'null'],
117
        ];
118
119
        $this->setMultipleAllowedTypes($allowedTypes, $builder);
120
    }
121
122
    public function buildForm(FormBuilderInterface $builder): void
123
    {
124
        $builder
125
            ->add('institution')
126
            ->add('institution_url', UrlType::class)
127
            ->add('institution_address')
128
            ->add('site_name')
129
            ->add('timezone', TimezoneType::class)
130
            ->add('gravatar_enabled', YesNoType::class)
131
            ->add(
132
                'gravatar_type',
133
                ChoiceType::class,
134
                [
135
                    'choices' => [
136
                        'mistery-man' => 'mm',
137
                        'identicon' => 'identicon',
138
                        'monsterid' => 'monsterid',
139
                        'wavatar' => 'wavatar',
140
                    ],
141
                ]
142
            )
143
            ->add('gamification_mode')
144
            ->add('order_user_list_by_official_code', YesNoType::class)
145
            ->add('cookie_warning', YesNoType::class)
146
            ->add('donotlistcampus', YesNoType::class)
147
            ->add('course_catalog_hide_private', YesNoType::class)
148
            ->add(
149
                'catalog_show_courses_sessions',
150
                ChoiceType::class,
151
                [
152
                    'choices' => [
153
                        'Hide catalogue' => '-1',
154
                        'Show only courses' => '0',
155
                        'Show only sessions' => '1',
156
                        'Show courses and sessions' => '2',
157
                    ],
158
                ]
159
            )
160
            ->add('use_custom_pages', YesNoType::class)
161
            ->add('pdf_logo_header')
162
            ->add('allow_my_files', YesNoType::class)
163
            ->add('chamilo_database_version')
164
            ->add(
165
                'load_term_conditions_section',
166
                ChoiceType::class,
167
                [
168
                    'choices' => [
169
                        'Login' => 'login',
170
                        'Course' => 'course',
171
                    ],
172
                ]
173
            )
174
            ->add(
175
                'server_type',
176
                ChoiceType::class,
177
                [
178
                    'label' => 'Server Type',
179
                    'choices' => [
180
                        'Production' => 'prod',
181
                        'Validation' => 'validation',
182
                        'Test/Development' => 'test',
183
                    ],
184
                ]
185
            )
186
            ->add(
187
                'show_tabs',
188
                ChoiceType::class,
189
                [
190
                    'multiple' => true,
191
                    'choices' => self::$tabs,
192
                ],
193
            )
194
            ->add('show_tabs_per_role', TextareaType::class)
195
            ->add('unoconv_binaries', TextType::class)
196
            ->add('hide_main_navigation_menu', YesNoType::class)
197
            ->add('pdf_img_dpi', TextType::class)
198
            ->add('tracking_skip_generic_data', YesNoType::class)
199
            ->add('hide_complete_name_in_whoisonline', YesNoType::class)
200
            ->add('table_default_row', TextType::class)
201
            ->add('allow_double_validation_in_registration', YesNoType::class)
202
            ->add('block_my_progress_page', YesNoType::class)
203
            ->add('generate_random_login', YesNoType::class)
204
            ->add('timepicker_increment', TextType::class)
205
            ->add('proxy_settings', TextareaType::class)
206
            ->add('video_features', TextareaType::class)
207
            ->add('table_row_list', TextareaType::class)
208
            ->add('webservice_return_user_field', TextType::class)
209
            ->add('multiple_url_hide_disabled_settings', YesNoType::class)
210
            ->add('login_max_attempt_before_blocking_account', TextType::class)
211
            ->add('force_renew_password_at_first_login', YesNoType::class)
212
            ->add('hide_breadcrumb_if_not_allowed', YesNoType::class)
213
            ->add('extldap_config', TextareaType::class)
214
            ->add('update_student_expiration_x_date', TextareaType::class)
215
            ->add('user_status_show_options_enabled', YesNoType::class)
216
            ->add('user_status_show_option', TextareaType::class)
217
            ->add('user_number_of_days_for_default_expiration_date_per_role', TextareaType::class)
218
            ->add('user_edition_extra_field_to_check', TextType::class)
219
            ->add('user_hide_never_expire_option', YesNoType::class)
220
            ->add('platform_logo_url', TextType::class)
221
            ->add('use_career_external_id_as_identifier_in_diagrams', YesNoType::class)
222
            ->add('disable_webservices', YesNoType::class)
223
            ->add('webservice_enable_adminonly_api', YesNoType::class)
224
            ->add('allow_working_time_edition', YesNoType::class)
225
            ->add('disable_user_conditions_sender_id', TextType::class)
226
            ->add('portfolio_advanced_sharing', TextType::class)
227
            ->add('redirect_index_to_url_for_logged_users', TextType::class)
228
            ->add(
229
                'default_menu_entry_for_course_or_session',
230
                ChoiceType::class,
231
                [
232
                    'choices' => [
233
                        'My courses' => 'my_courses',
234
                        'My sessions' => 'my_sessions',
235
                    ],
236
                ]
237
            )
238
            ->add('notification_event', YesNoType::class)
239
            ->add(
240
                'session_admin_user_subscription_search_extra_field_to_search',
241
                TextType::class,
242
                [
243
                    'required' => false,
244
                    'empty_data' => '',
245
                    'help' => 'User extra field key to use when searching and naming sessions from /admin-dashboard/register.',
246
                ]
247
            )
248
            ->add('push_notification_settings', TextareaType::class);
249
250
        $this->updateFormFieldsFromSettingsInfo($builder);
251
    }
252
253
    public function getHiddenSettings(): array
254
    {
255
        return [
256
            'registered',
257
        ];
258
    }
259
}
260