Completed
Push — master ( 53f6ec...d4770b )
by Julito
17:14 queued 05:53
created

CourseSettingsSchema   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 213
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 142
c 2
b 0
f 0
dl 0
loc 213
rs 10
wmc 5

4 Methods

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