Passed
Push — master ( d00a81...8408e9 )
by Julito
09:46
created

CourseSettingsSchema::buildForm()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 110
Code Lines 78

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 78
nc 1
nop 1
dl 0
loc 110
rs 8.48
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
/* For licensing terms, see /license.txt */
4
5
namespace Chamilo\CoreBundle\Settings;
6
7
use Chamilo\CoreBundle\Entity\Course;
8
use Chamilo\CoreBundle\Form\DataTransformer\ResourceToIdentifierTransformer;
9
use Chamilo\CoreBundle\Form\Type\YesNoType;
10
use Chamilo\CoreBundle\Tool\AbstractTool;
11
use Chamilo\CoreBundle\ToolChain;
12
use Chamilo\SettingsBundle\Transformer\ArrayToIdentifierTransformer;
13
//use Sylius\Bundle\ResourceBundle\Form\DataTransformer\ResourceToIdentifierTransformer;
14
use Sylius\Bundle\SettingsBundle\Schema\AbstractSettingsBuilder;
15
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
16
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
17
use Symfony\Component\Form\Extension\Core\Type\UrlType;
18
use Symfony\Component\Form\FormBuilderInterface;
19
20
/**
21
 * Class CourseSettingsSchema.
22
 */
23
class CourseSettingsSchema extends AbstractSettingsSchema
24
{
25
    /**
26
     * @var ToolChain
27
     */
28
    protected $toolChain;
29
    //protected $repository;
30
31
    public function getProcessedToolChain(): array
32
    {
33
        $tools = [];
34
        /** @var AbstractTool $tool */
35
        foreach ($this->toolChain->getTools() as $tool) {
36
            $name = $tool->getName();
37
            $tools[$name] = $name;
38
        }
39
40
        return $tools;
41
    }
42
43
    public function setToolChain(ToolChain $tools): void
44
    {
45
        $this->toolChain = $tools;
46
    }
47
48
    public function buildSettings(AbstractSettingsBuilder $builder)
49
    {
50
        $tools = $this->getProcessedToolChain();
51
52
        $builder
53
            ->setDefaults(
54
                [
55
                    'homepage_view' => 'activity_big',
56
                    'show_tool_shortcuts' => 'false', // @todo check default value?
57
                    'active_tools_on_create' => $tools,
58
                    'display_coursecode_in_courselist' => 'false',
59
                    'display_teacher_in_courselist' => 'true',
60
                    'student_view_enabled' => 'true',
61
                    'go_to_course_after_login' => 'false',
62
                    'show_navigation_menu' => 'false',
63
                    'enable_tool_introduction' => 'false',
64
                    'breadcrumbs_course_homepage' => 'course_title',
65
                    'example_material_course_creation' => 'true',
66
                    'allow_course_theme' => 'true',
67
                    'allow_users_to_create_courses' => 'true',
68
                    'show_courses_descriptions_in_catalog' => 'true',
69
                    'send_email_to_admin_when_create_course' => 'false',
70
                    'allow_user_course_subscription_by_course_admin' => 'true',
71
                    'course_validation' => 'false',
72
                    'course_validation_terms_and_conditions_url' => '',
73
                    'course_hide_tools' => [],
74
                    'scorm_cumulative_session_time' => 'true',
75
                    'courses_default_creation_visibility' => '2',
76
                    //COURSE_VISIBILITY_OPEN_PLATFORM
77
                    'allow_public_certificates' => 'false',
78
                    'allow_lp_return_link' => 'true',
79
                    'course_creation_use_template' => null,
80
                    'hide_scorm_export_link' => 'false',
81
                    'hide_scorm_copy_link' => 'false',
82
                    'hide_scorm_pdf_link' => 'true',
83
                    'course_catalog_published' => 'false',
84
                    'course_images_in_courses_list' => 'true',
85
                    'teacher_can_select_course_template' => 'true',
86
                    'show_toolshortcuts' => '',
87
                    'enable_record_audio' => 'false',
88
                    'lp_show_reduced_report' => 'false',
89
                    'course_creation_splash_screen' => 'true',
90
                    'block_registered_users_access_to_open_course_contents' => 'false', // @todo
91
                ]
92
            )
93
            ->setTransformer(
94
                'active_tools_on_create',
95
                new ArrayToIdentifierTransformer()
96
            )
97
            ->setTransformer(
98
                'course_hide_tools',
99
                new ArrayToIdentifierTransformer()
100
            )
101
           /* ->setTransformer(
102
                'course_creation_use_template',
103
                new ResourceToIdentifierTransformer($this->getRepository())
104
            )*/
105
        ;
106
107
        $allowedTypes = [
108
            'homepage_view' => ['string'],
109
            'active_tools_on_create' => ['array'],
110
            'course_hide_tools' => ['array'],
111
            'display_coursecode_in_courselist' => ['string'],
112
            'display_teacher_in_courselist' => ['string'],
113
            'student_view_enabled' => ['string'],
114
        ];
115
116
        $this->setMultipleAllowedTypes($allowedTypes, $builder);
117
    }
118
119
    public function buildForm(FormBuilderInterface $builder)
120
    {
121
        $tools = $this->getProcessedToolChain();
122
123
        $builder
124
            ->add(
125
                'homepage_view',
126
                ChoiceType::class,
127
                [
128
                    'choices' => [
129
                        //'HomepageView2column' => '2column',
130
                        //'HomepageView3column' => '3column',
131
                        //'HomepageViewVerticalActivity' => 'vertical_activity',
132
                        //'HomepageViewActivity' => 'activity',
133
                        'HomepageViewActivityBig' => 'activity_big',
134
                    ],
135
                ]
136
            )
137
            ->add('show_tool_shortcuts', YesNoType::class)
138
            ->add(
139
                'active_tools_on_create',
140
                ChoiceType::class,
141
                [
142
                    'choices' => $tools,
143
                    'multiple' => true,
144
                    'expanded' => true,
145
                ]
146
            )
147
            ->add('display_coursecode_in_courselist', YesNoType::class)
148
            ->add('display_teacher_in_courselist', YesNoType::class)
149
            ->add('student_view_enabled', YesNoType::class)
150
            ->add('go_to_course_after_login', YesNoType::class)
151
            ->add(
152
                'show_navigation_menu',
153
                ChoiceType::class,
154
                [
155
                    'choices' => [
156
                        'No' => 'false',
157
                        'IconsOnly' => 'icons',
158
                        'TextOnly' => 'text',
159
                        'IconsText' => 'iconstext',
160
                    ],
161
                ]
162
            )
163
            ->add('enable_tool_introduction', YesNoType::class)
164
            ->add(
165
                'breadcrumbs_course_homepage',
166
                ChoiceType::class,
167
                [
168
                    'choices' => [
169
                        'CourseHomepage' => 'course_home',
170
                        'CourseCode' => 'course_code',
171
                        'CourseTitle' => 'course_title',
172
                        'SessionNameAndCourseTitle' => 'session_name_and_course_title',
173
                    ],
174
                ]
175
            )
176
            ->add('example_material_course_creation', YesNoType::class)
177
            ->add('allow_course_theme', YesNoType::class)
178
            ->add('allow_users_to_create_courses', YesNoType::class)
179
            ->add('show_courses_descriptions_in_catalog', YesNoType::class)
180
            ->add('send_email_to_admin_when_create_course', YesNoType::class)
181
            ->add('allow_user_course_subscription_by_course_admin', YesNoType::class)
182
            ->add('course_validation', YesNoType::class)
183
            ->add('course_validation_terms_and_conditions_url', UrlType::class)
184
            ->add(
185
                'course_hide_tools',
186
                ChoiceType::class,
187
                [
188
                    'choices' => $tools,
189
                    'multiple' => true,
190
                    'expanded' => true,
191
                ]
192
            )
193
            ->add('scorm_cumulative_session_time', YesNoType::class)
194
            ->add(
195
                'courses_default_creation_visibility',
196
                ChoiceType::class,
197
                [
198
                    'choices' => [
199
                        'Public' => '3',
200
                        'Open' => '2',
201
                        'Private' => '1',
202
                        'Closed' => '0',
203
                    ],
204
                ]
205
            )
206
            ->add('allow_public_certificates', YesNoType::class)
207
            ->add('allow_lp_return_link', YesNoType::class)
208
            ->add(
209
                'course_creation_use_template',
210
                EntityType::class,
211
                [
212
                    'class' => Course::class,
213
                    'placeholder' => 'Choose ...',
214
                    'empty_data' => null,
215
                    'data' => null,
216
                ]
217
            )
218
            ->add('hide_scorm_export_link', YesNoType::class)
219
            ->add('hide_scorm_copy_link', YesNoType::class)
220
            ->add('hide_scorm_pdf_link', YesNoType::class)
221
            ->add('course_catalog_published', YesNoType::class)
222
            ->add('course_images_in_courses_list', YesNoType::class)
223
            ->add('teacher_can_select_course_template', YesNoType::class)
224
            ->add('show_toolshortcuts', YesNoType::class)
225
            ->add('enable_record_audio', YesNoType::class)
226
            ->add('lp_show_reduced_report', YesNoType::class)
227
            ->add('course_creation_splash_screen', YesNoType::class)
228
            ->add('block_registered_users_access_to_open_course_contents', YesNoType::class)
229
        ;
230
    }
231
}
232