Passed
Pull Request — master (#7105)
by
unknown
08:42
created

DocumentSettingsSchema::buildSettings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 57
Code Lines 47

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 47
nc 1
nop 1
dl 0
loc 57
rs 9.1563
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\FormBuilderInterface;
15
16
class DocumentSettingsSchema extends AbstractSettingsSchema
17
{
18
    public function buildSettings(AbstractSettingsBuilder $builder): void
19
    {
20
        $builder
21
            ->setDefaults([
22
                'default_document_quotum' => '1000',
23
                'default_group_quotum' => '250',
24
                'permanently_remove_deleted_files' => 'false',
25
                'upload_extensions_list_type' => 'blacklist',
26
                'upload_extensions_blacklist' => '',
27
                'upload_extensions_whitelist' => 'htm;html;jpg;jpeg;gif;png;swf;avi;mpg;mpeg;mov;flv;doc;docx;xls;xlsx;ppt;pptx;odt;odp;ods;pdf;webm;oga;ogg;ogv;h264',
28
                'upload_extensions_skip' => 'true',
29
                'upload_extensions_replace_by' => 'dangerous',
30
                'permissions_for_new_directories' => '0770',
31
                'permissions_for_new_files' => '0660',
32
                'students_download_folders' => 'true',
33
                'users_copy_files' => 'true',
34
                'pdf_export_watermark_enable' => 'false',
35
                'pdf_export_watermark_by_course' => 'false',
36
                'pdf_export_watermark_text' => '',
37
                'students_export2pdf' => 'true',
38
                'show_users_folders' => 'true',
39
                'show_default_folders' => 'true',
40
                'show_documents_preview' => 'false',
41
                'tool_visible_by_default_at_creation' => [
42
                    'documents',
43
                    'learning_path',
44
                    'links',
45
                    'announcements',
46
                    'forums',
47
                    'quiz',
48
                    'gradebook',
49
                ],
50
                'documents_default_visibility_defined_in_course' => 'false',
51
                'send_notification_when_document_added' => 'false',
52
                'thematic_pdf_orientation' => 'landscape',
53
                'group_document_access' => 'false',
54
                'group_category_document_access' => 'false',
55
                'documents_hide_download_icon' => 'false',
56
                'enable_x_sendfile_headers' => 'false',
57
                'documents_custom_cloud_link_list' => '',
58
59
                'access_url_specific_files' => 'false',
60
                'video_features' => '',
61
            ])
62
            ->setTransformer(
63
                'tool_visible_by_default_at_creation',
64
                new ArrayToIdentifierTransformer()
65
            )
66
        ;
67
68
        $allowedTypes = [
69
            'tool_visible_by_default_at_creation' => ['array'],
70
            'default_document_quotum' => ['string'],
71
            'default_group_quotum' => ['string'],
72
        ];
73
74
        $this->setMultipleAllowedTypes($allowedTypes, $builder);
75
    }
76
77
    public function buildForm(FormBuilderInterface $builder): void
78
    {
79
        $builder
80
            ->add('default_document_quotum')
81
            ->add('default_group_quotum')
82
            ->add('permanently_remove_deleted_files', YesNoType::class)
83
            ->add('upload_extensions_list_type', ChoiceType::class, [
84
                'choices' => [
85
                    'Black list' => 'blacklist',
86
                    'White list' => 'whitelist',
87
                ],
88
            ])
89
            ->add('upload_extensions_blacklist', TextareaType::class, [
90
                'attr' => ['rows' => 3, 'style' => 'font-family: monospace;'],
91
            ])
92
            ->add('upload_extensions_whitelist', TextareaType::class, [
93
                'attr' => ['rows' => 3, 'style' => 'font-family: monospace;'],
94
            ])
95
            ->add('upload_extensions_skip', TextareaType::class, [
96
                'attr' => ['rows' => 3, 'style' => 'font-family: monospace;'],
97
            ])
98
            ->add('upload_extensions_replace_by', TextareaType::class, [
99
                'attr' => ['rows' => 3, 'style' => 'font-family: monospace;'],
100
            ])
101
            ->add('permissions_for_new_directories')
102
            ->add('permissions_for_new_files')
103
            ->add('students_download_folders', YesNoType::class)
104
            ->add('users_copy_files', YesNoType::class)
105
            ->add('pdf_export_watermark_enable', YesNoType::class)
106
            ->add('pdf_export_watermark_by_course', YesNoType::class)
107
            ->add('pdf_export_watermark_text', TextareaType::class, [
108
                'attr' => ['rows' => 3, 'style' => 'font-family: monospace;'],
109
            ])
110
            ->add('students_export2pdf', YesNoType::class)
111
            ->add('show_users_folders', YesNoType::class)
112
            ->add('show_default_folders', YesNoType::class)
113
            ->add('show_documents_preview', YesNoType::class)
114
            ->add('tool_visible_by_default_at_creation', ChoiceType::class, [
115
                'multiple' => true,
116
                'choices' => [
117
                    'Documents' => 'documents',
118
                    'LearningPath' => 'learning_path',
119
                    'Links' => 'links',
120
                    'Announcements' => 'announcements',
121
                    'Forums' => 'forums',
122
                    'Quiz' => 'quiz',
123
                    'Gradebook' => 'gradebook',
124
                ],
125
            ])
126
            ->add('send_notification_when_document_added', YesNoType::class)
127
            ->add('thematic_pdf_orientation', ChoiceType::class, [
128
                'choices' => [
129
                    'Portrait' => 'portrait',
130
                    'Landscape' => 'landscape',
131
                ],
132
            ])
133
            ->add('group_document_access', YesNoType::class)
134
            ->add('group_category_document_access', YesNoType::class)
135
            ->add('documents_hide_download_icon', YesNoType::class)
136
            ->add('enable_x_sendfile_headers', YesNoType::class)
137
            ->add('documents_custom_cloud_link_list', TextareaType::class, [
138
                'attr' => ['rows' => 3, 'style' => 'font-family: monospace;'],
139
            ])
140
            ->add('access_url_specific_files', YesNoType::class)
141
            ->add('video_features', TextareaType::class, [
142
                'attr' => ['rows' => 4, 'style' => 'font-family: monospace;'],
143
                'help' => 'JSON opcional. Ej: {"speed": true}',
144
            ])
145
        ;
146
147
        $this->updateFormFieldsFromSettingsInfo($builder);
148
    }
149
}
150