Passed
Push — master ( 62083f...ad8d4a )
by Julito
10:31
created

ExtraFieldFixtures   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 185
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 124
dl 0
loc 185
rs 10
c 1
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
B load() 0 183 5
1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CoreBundle\DataFixtures;
8
9
use Chamilo\CoreBundle\Entity\ExtraField;
10
use Chamilo\CoreBundle\Entity\ExtraFieldOptions;
11
use Doctrine\Bundle\FixturesBundle\Fixture;
12
use Doctrine\Persistence\ObjectManager;
13
14
class ExtraFieldFixtures extends Fixture
15
{
16
    public function load(ObjectManager $manager): void
17
    {
18
        $list = [
19
            [
20
                'variable' => 'legal_accept',
21
                'display_text' => 'Legal',
22
                'extra_field_type' => ExtraField::USER_FIELD_TYPE,
23
                'field_type' => \ExtraField::FIELD_TYPE_TEXT,
24
            ],
25
            [
26
                'variable' => 'already_logged_in',
27
                'display_text' => 'Already logged in',
28
                'extra_field_type' => ExtraField::USER_FIELD_TYPE,
29
                'field_type' => \ExtraField::FIELD_TYPE_TEXT,
30
            ],
31
            [
32
                'variable' => 'update_type',
33
                'display_text' => 'Update script type',
34
                'extra_field_type' => ExtraField::USER_FIELD_TYPE,
35
                'field_type' => \ExtraField::FIELD_TYPE_TEXT,
36
            ],
37
            [
38
                'variable' => 'tags',
39
                'display_text' => 'tags',
40
                'extra_field_type' => ExtraField::USER_FIELD_TYPE,
41
                'field_type' => \ExtraField::FIELD_TYPE_TAG,
42
            ],
43
            [
44
                'variable' => 'rssfeeds',
45
                'display_text' => 'RSS',
46
                'extra_field_type' => ExtraField::USER_FIELD_TYPE,
47
                'field_type' => \ExtraField::FIELD_TYPE_TEXT,
48
            ],
49
            [
50
                'variable' => 'dashboard',
51
                'display_text' => 'Dashboard',
52
                'extra_field_type' => ExtraField::USER_FIELD_TYPE,
53
                'field_type' => \ExtraField::FIELD_TYPE_TEXT,
54
            ],
55
            /*[
56
                'variable' => 'timezone',
57
                'display_text' => 'Timezone',
58
                'extra_field_type' => ExtraField::USER_FIELD_TYPE,
59
                'field_type' => \ExtraField::FIELD_TYPE_TEXT,
60
            ],*/
61
            [
62
                'variable' => 'user_chat_status',
63
                'display_text' => 'User chat status',
64
                'extra_field_type' => ExtraField::USER_FIELD_TYPE,
65
                'field_type' => \ExtraField::FIELD_TYPE_TEXT,
66
            ],
67
            [
68
                'variable' => 'google_calendar_url',
69
                'display_text' => 'Google Calendar URL',
70
                'extra_field_type' => ExtraField::USER_FIELD_TYPE,
71
                'field_type' => \ExtraField::FIELD_TYPE_TEXT,
72
            ],
73
            [
74
                'variable' => 'captcha_blocked_until_date',
75
                'display_text' => 'Account locked until',
76
                'extra_field_type' => ExtraField::USER_FIELD_TYPE,
77
                'field_type' => \ExtraField::FIELD_TYPE_TEXT,
78
            ],
79
            [
80
                'variable' => 'special_course',
81
                'display_text' => 'Special course',
82
                'extra_field_type' => ExtraField::COURSE_FIELD_TYPE,
83
                'field_type' => \ExtraField::FIELD_TYPE_CHECKBOX,
84
                'visible_to_self' => true,
85
                'changeable' => true,
86
            ],
87
            [
88
                'variable' => 'tags',
89
                'display_text' => 'Tags',
90
                'extra_field_type' => ExtraField::COURSE_FIELD_TYPE,
91
                'field_type' => \ExtraField::FIELD_TYPE_TAG,
92
                'visible_to_self' => true,
93
                'changeable' => true,
94
            ],
95
            [
96
                'variable' => 'video_url',
97
                'display_text' => 'VideoUrl',
98
                'extra_field_type' => ExtraField::COURSE_FIELD_TYPE,
99
                'field_type' => \ExtraField::FIELD_TYPE_VIDEO_URL,
100
                'visible_to_self' => true,
101
                'changeable' => true,
102
            ],
103
            [
104
                'variable' => 'image',
105
                'display_text' => 'Image',
106
                'extra_field_type' => ExtraField::SESSION_FIELD_TYPE,
107
                'field_type' => \ExtraField::FIELD_TYPE_FILE_IMAGE,
108
                'visible_to_self' => true,
109
                'changeable' => true,
110
            ],
111
112
            [
113
                'variable' => 'mail_notify_invitation',
114
                'display_text' => 'MailNotifyInvitation',
115
                'extra_field_type' => ExtraField::USER_FIELD_TYPE,
116
                'field_type' => \ExtraField::FIELD_TYPE_SELECT,
117
                'visible_to_self' => true,
118
                'default_value' => 1,
119
                'add_options' => true,
120
            ],
121
            [
122
                'variable' => 'mail_notify_message',
123
                'display_text' => 'MailNotifyMessage',
124
                'extra_field_type' => ExtraField::USER_FIELD_TYPE,
125
                'field_type' => \ExtraField::FIELD_TYPE_SELECT,
126
                'visible_to_self' => true,
127
                'default_value' => 1,
128
                'add_options' => true,
129
            ],
130
            [
131
                'variable' => 'mail_notify_group_message',
132
                'display_text' => 'MailNotifyGroupMessage',
133
                'extra_field_type' => ExtraField::USER_FIELD_TYPE,
134
                'field_type' => \ExtraField::FIELD_TYPE_SELECT,
135
                'visible_to_self' => true,
136
                'default_value' => 1,
137
                'add_options' => true,
138
            ],
139
            [
140
                'variable' => 'skype',
141
                'display_text' => 'Skype',
142
                'extra_field_type' => ExtraField::USER_FIELD_TYPE,
143
                'field_type' => \ExtraField::FIELD_TYPE_TEXT,
144
                'visible_to_self' => true,
145
                'changeable' => true,
146
            ],
147
            [
148
                'variable' => 'linkedin_url',
149
                'display_text' => 'LinkedInUrl',
150
                'extra_field_type' => ExtraField::USER_FIELD_TYPE,
151
                'field_type' => \ExtraField::FIELD_TYPE_TEXT,
152
                'visible_to_self' => true,
153
                'changeable' => true,
154
            ],
155
            [
156
                'variable' => 'tags',
157
                'display_text' => 'Tags',
158
                'extra_field_type' => ExtraField::SKILL_FIELD_TYPE,
159
                'field_type' => \ExtraField::FIELD_TYPE_TAG,
160
                'visible_to_self' => true,
161
                'changeable' => true,
162
            ],
163
        ];
164
165
        $options = [
166
            'At once',
167
            'Daily',
168
            'No',
169
        ];
170
171
        foreach ($list as $data) {
172
            $extraField = (new ExtraField())
173
                ->setVariable($data['variable'])
174
                ->setDisplayText($data['display_text'])
175
                ->setExtraFieldType($data['extra_field_type'])
176
                ->setFieldType($data['field_type'])
177
                ->setChangeable($data['changeable'] ?? false)
178
                ->setVisibleToSelf($data['visible_to_self'] ?? false)
179
            ;
180
181
            if (isset($data['default_value'])) {
182
                $extraField->setDefaultValue((string) $data['default_value']);
183
            }
184
185
            if (isset($data['add_options'])) {
186
                foreach ($options as $key => $text) {
187
                    $extraFieldOption = (new ExtraFieldOptions())
188
                        ->setField($extraField)
189
                        ->setDisplayText($text)
190
                        ->setOptionOrder($key + 1)
191
                    ;
192
                    $manager->persist($extraFieldOption);
193
                }
194
            }
195
            $manager->persist($extraField);
196
        }
197
198
        $manager->flush();
199
    }
200
}
201