Passed
Pull Request — master (#6824)
by
unknown
08:35
created

DisplaySettingsSchema::buildForm()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 75
Code Lines 56

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 56
nc 1
nop 1
dl 0
loc 75
rs 8.9599
c 0
b 0
f 0

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\FormBuilderInterface;
16
17
class DisplaySettingsSchema extends AbstractSettingsSchema
18
{
19
    private static array $tabs = [
20
        'MenuCampusHomepage' => 'campus_homepage',
21
        'MenuMyCourses' => 'my_courses',
22
        'MenuReporting' => 'reporting',
23
        'MenuPlatformAdministration' => 'platform_administration',
24
        'MenuMyAgenda' => 'my_agenda',
25
        'MenuSocial' => 'social',
26
        'MenuVideoConference' => 'videoconference',
27
        'MenuDiagnostics' => 'diagnostics',
28
        'MenuCatalogue' => 'catalogue',
29
        'MenuSessionAdmin' => 'session_admin',
30
        'TopbarCertificate' => 'topbar_certificate',
31
        'TopbarSkills' => 'topbar_skills',
32
    ];
33
34
    public function buildSettings(AbstractSettingsBuilder $builder): void
35
    {
36
        $builder
37
            ->setDefaults(
38
                [
39
                    'enable_help_link' => 'true',
40
                    'show_administrator_data' => 'true',
41
                    'show_tutor_data' => 'true',
42
                    'show_teacher_data' => 'true',
43
                    'showonline' => 'world',
44
                    'time_limit_whosonline' => '30',
45
                    'show_email_addresses' => 'false',
46
                    'show_number_of_courses' => 'false',
47
                    'show_empty_course_categories' => 'true',
48
                    'show_back_link_on_top_of_tree' => 'false',
49
                    'display_categories_on_homepage' => 'false',
50
                    'show_closed_courses' => 'false',
51
                    'accessibility_font_resize' => 'false',
52
                    'show_admin_toolbar' => 'do_not_show',
53
                    'show_hot_courses' => 'true',
54
                    'hide_home_top_when_connected' => 'false',
55
                    'hide_logout_button' => 'false',
56
                    'icons_mode_svg' => 'false',
57
                    'hide_social_media_links' => 'false',
58
59
                    'gravatar_enabled' => 'false',
60
                    'gravatar_type' => 'mm',
61
                    'order_user_list_by_official_code' => 'false',
62
                    'pdf_logo_header' => '',
63
                    'show_tabs' => array_values(array_diff(self::$tabs, ['videoconference', 'diagnostics'])),
64
                    'show_tabs_per_role' => '{}',
65
                    'hide_main_navigation_menu' => 'false',
66
                    'hide_complete_name_in_whoisonline' => 'false',
67
                    'table_default_row' => '20',
68
                    'table_row_list' => '[10,20,50,100]',
69
                ]
70
            )
71
            ->setTransformer(
72
                'show_tabs',
73
                new ArrayToIdentifierTransformer()
74
            )
75
        ;
76
77
        $allowedTypes = [
78
            'time_limit_whosonline' => ['string'],
79
            'show_tabs' => ['array', 'null'],
80
            'show_tabs_per_role' => ['string', 'null'],
81
        ];
82
        $this->setMultipleAllowedTypes($allowedTypes, $builder);
83
    }
84
85
    public function buildForm(FormBuilderInterface $builder): void
86
    {
87
        $builder
88
            ->add('enable_help_link', YesNoType::class)
89
            ->add('show_administrator_data', YesNoType::class)
90
            ->add('show_tutor_data', YesNoType::class)
91
            ->add('show_teacher_data', YesNoType::class)
92
            ->add(
93
                'showonline',
94
                ChoiceType::class,
95
                [
96
                    'choices' => [
97
                        'Course' => 'course',
98
                        'Users' => 'users',
99
                        'World' => 'world',
100
                    ],
101
                ]
102
            )
103
            ->add('time_limit_whosonline')
104
            ->add('show_email_addresses', YesNoType::class)
105
            ->add('show_number_of_courses', YesNoType::class)
106
            ->add('show_empty_course_categories', YesNoType::class)
107
            ->add('show_back_link_on_top_of_tree', YesNoType::class)
108
            ->add('show_empty_course_categories', YesNoType::class)
109
            ->add('display_categories_on_homepage', YesNoType::class)
110
            ->add('show_closed_courses', YesNoType::class)
111
            ->add('accessibility_font_resize', YesNoType::class)
112
            ->add(
113
                'show_admin_toolbar',
114
                ChoiceType::class,
115
                [
116
                    'choices' => [
117
                        'Do not show' => 'do_not_show',
118
                        'Show to admins only' => 'show_to_admin',
119
                        'Show to admins and teachers' => 'show_to_admin_and_teachers',
120
                        'Show to all users' => 'show_to_all',
121
                    ],
122
                ]
123
            )
124
            ->add('show_hot_courses', YesNoType::class)
125
            ->add('hide_home_top_when_connected', YesNoType::class)
126
            ->add('hide_logout_button', YesNoType::class)
127
            ->add('icons_mode_svg', YesNoType::class)
128
            ->add('hide_social_media_links', YesNoType::class)
129
            ->add('gravatar_enabled', YesNoType::class)
130
            ->add(
131
                'gravatar_type',
132
                ChoiceType::class,
133
                [
134
                    'choices' => [
135
                        'mistery-man' => 'mm',
136
                        'identicon' => 'identicon',
137
                        'monsterid' => 'monsterid',
138
                        'wavatar' => 'wavatar',
139
                    ],
140
                ]
141
            )
142
            ->add('order_user_list_by_official_code', YesNoType::class)
143
            ->add('pdf_logo_header')
144
            ->add(
145
                'show_tabs',
146
                ChoiceType::class,
147
                [
148
                    'multiple' => true,
149
                    'choices' => self::$tabs,
150
                ],
151
            )
152
            ->add('show_tabs_per_role', TextareaType::class)
153
            ->add('hide_main_navigation_menu', YesNoType::class)
154
            ->add('hide_complete_name_in_whoisonline', YesNoType::class)
155
            ->add('table_default_row', TextType::class)
156
            ->add('table_row_list', TextareaType::class)
157
        ;
158
159
        $this->updateFormFieldsFromSettingsInfo($builder);
160
    }
161
}
162