1 | <?php |
||
2 | |||
3 | namespace Backend\Modules\FormBuilder\Installer; |
||
4 | |||
5 | use Backend\Core\Engine\Model as BackendModel; |
||
6 | use Backend\Core\Installer\ModuleInstaller; |
||
7 | use Common\ModuleExtraType; |
||
8 | |||
9 | /** |
||
10 | * Installer for the form_builder module |
||
11 | */ |
||
12 | class Installer extends ModuleInstaller |
||
13 | { |
||
14 | public function install(): void |
||
15 | { |
||
16 | $this->addModule('FormBuilder'); |
||
17 | $this->importSQL(__DIR__ . '/Data/install.sql'); |
||
18 | $this->importLocale(__DIR__ . '/Data/locale.xml'); |
||
19 | $this->configureSettings(); |
||
20 | $this->configureBackendRights(); |
||
21 | $this->configureBackendNavigation(); |
||
22 | $this->configureFrontendPages(); |
||
23 | } |
||
24 | |||
25 | private function configureSettings(): void |
||
26 | { |
||
27 | $this->setSetting($this->getModule(), 'requires_google_recaptcha', true); |
||
28 | } |
||
29 | |||
30 | private function configureBackendNavigation(): void |
||
31 | { |
||
32 | // Set navigation for "Modules" |
||
33 | $navigationModulesId = $this->setNavigation(null, 'Modules'); |
||
34 | $this->setNavigation($navigationModulesId, 'FormBuilder', 'form_builder/index', [ |
||
35 | 'form_builder/add', |
||
36 | 'form_builder/edit', |
||
37 | 'form_builder/data', |
||
38 | 'form_builder/data_details', |
||
39 | ]); |
||
40 | } |
||
41 | |||
42 | private function configureBackendRights(): void |
||
43 | { |
||
44 | $this->setModuleRights(1, $this->getModule()); |
||
45 | |||
46 | $this->setActionRights(1, $this->getModule(), 'Add'); |
||
47 | $this->setActionRights(1, $this->getModule(), 'Data'); |
||
48 | $this->setActionRights(1, $this->getModule(), 'DataDetails'); |
||
49 | $this->setActionRights(1, $this->getModule(), 'Delete'); |
||
50 | $this->setActionRights(1, $this->getModule(), 'DeleteField'); // AJAX |
||
51 | $this->setActionRights(1, $this->getModule(), 'Edit'); |
||
52 | $this->setActionRights(1, $this->getModule(), 'ExportData'); |
||
53 | $this->setActionRights(1, $this->getModule(), 'GetField'); // AJAX |
||
54 | $this->setActionRights(1, $this->getModule(), 'Index'); |
||
55 | $this->setActionRights(1, $this->getModule(), 'MassDataAction'); |
||
56 | $this->setActionRights(1, $this->getModule(), 'SaveField'); // AJAX |
||
57 | $this->setActionRights(1, $this->getModule(), 'Sequence'); // AJAX |
||
58 | } |
||
59 | |||
60 | private function configureFrontendPages(): void |
||
61 | { |
||
62 | $searchWidgetId = $this->getSearchWidgetId(); |
||
63 | |||
64 | // loop languages |
||
65 | foreach ($this->getLanguages() as $language) { |
||
66 | // create form |
||
67 | $form = []; |
||
68 | $form['language'] = $language; |
||
69 | $form['user_id'] = $this->getDefaultUserID(); |
||
70 | $form['name'] = \SpoonFilter::ucfirst($this->getLocale('Contact', 'Core', $language, 'lbl', 'Frontend')); |
||
71 | $form['method'] = 'database_email'; |
||
72 | $form['email'] = serialize([$this->getVariable('email')]); |
||
73 | $form['success_message'] = $this->getLocale('ContactMessageSent', 'Core', $language, 'msg', 'Frontend'); |
||
74 | $form['identifier'] = 'contact-' . $language; |
||
75 | $form['created_on'] = gmdate('Y-m-d H:i:s'); |
||
76 | $form['edited_on'] = gmdate('Y-m-d H:i:s'); |
||
77 | $formId = $this->getDatabase()->insert('forms', $form); |
||
78 | |||
79 | // create submit button |
||
80 | $field = []; |
||
81 | $field['form_id'] = $formId; |
||
82 | $field['type'] = 'submit'; |
||
83 | $field['settings'] = serialize( |
||
84 | [ |
||
85 | 'values' => \SpoonFilter::ucfirst($this->getLocale('Send', 'Core', $language, 'lbl', 'Frontend')), |
||
86 | ] |
||
87 | ); |
||
88 | $this->getDatabase()->insert('forms_fields', $field); |
||
89 | |||
90 | // create name field |
||
91 | $field['form_id'] = $formId; |
||
92 | $field['type'] = 'textbox'; |
||
93 | $field['settings'] = serialize( |
||
94 | [ |
||
95 | 'label' => \SpoonFilter::ucfirst($this->getLocale('Name', 'Core', $language, 'lbl', 'Frontend')), |
||
96 | ] |
||
97 | ); |
||
98 | $nameId = $this->getDatabase()->insert('forms_fields', $field); |
||
99 | |||
100 | // name validation |
||
101 | $validate = []; |
||
102 | $validate['field_id'] = $nameId; |
||
103 | $validate['type'] = 'required'; |
||
104 | $validate['error_message'] = $this->getLocale('NameIsRequired', 'Core', $language, 'err', 'Frontend'); |
||
105 | $this->getDatabase()->insert('forms_fields_validation', $validate); |
||
106 | |||
107 | // create email field |
||
108 | $field['form_id'] = $formId; |
||
109 | $field['type'] = 'textbox'; |
||
110 | $field['settings'] = serialize( |
||
111 | [ |
||
112 | 'label' => \SpoonFilter::ucfirst($this->getLocale('Email', 'Core', $language, 'lbl', 'Frontend')), |
||
113 | ] |
||
114 | ); |
||
115 | $emailId = $this->getDatabase()->insert('forms_fields', $field); |
||
116 | |||
117 | // email validation |
||
118 | $validate['field_id'] = $emailId; |
||
119 | $validate['type'] = 'email'; |
||
120 | $validate['error_message'] = $this->getLocale('EmailIsInvalid', 'Core', $language, 'err', 'Frontend'); |
||
121 | $this->getDatabase()->insert('forms_fields_validation', $validate); |
||
122 | |||
123 | // create message field |
||
124 | $field['form_id'] = $formId; |
||
125 | $field['type'] = 'textarea'; |
||
126 | $field['settings'] = serialize( |
||
127 | [ |
||
128 | 'label' => \SpoonFilter::ucfirst($this->getLocale('Message', 'Core', $language, 'lbl', 'Frontend')), |
||
129 | ] |
||
130 | ); |
||
131 | $messageId = $this->getDatabase()->insert('forms_fields', $field); |
||
132 | |||
133 | // name validation |
||
134 | $validate['field_id'] = $messageId; |
||
135 | $validate['type'] = 'required'; |
||
136 | $validate['error_message'] = $this->getLocale('MessageIsRequired', 'Core', $language, 'err', 'Frontend'); |
||
137 | $this->getDatabase()->insert('forms_fields_validation', $validate); |
||
138 | |||
139 | // insert extra |
||
140 | $extraId = $this->insertExtra( |
||
141 | 'FormBuilder', |
||
142 | ModuleExtraType::widget(), |
||
143 | 'FormBuilder', |
||
144 | 'Form', |
||
145 | [ |
||
146 | 'language' => $form['language'], |
||
147 | 'extra_label' => $form['name'], |
||
148 | 'id' => $formId, |
||
149 | ], |
||
150 | false, |
||
151 | '400' . $formId |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
152 | ); |
||
153 | |||
154 | // insert contact page |
||
155 | $this->insertPage( |
||
156 | [ |
||
157 | 'title' => \SpoonFilter::ucfirst($this->getLocale('Contact', 'Core', $language, 'lbl', 'Frontend')), |
||
158 | 'parent_id' => BackendModel::HOME_PAGE_ID, |
||
159 | 'language' => $language, |
||
160 | ], |
||
161 | null, |
||
162 | ['html' => PATH_WWW . '/src/Backend/Modules/Pages/Installer/Data/' . $language . '/contact.txt'], |
||
163 | ['extra_id' => $extraId, 'position' => 'main'], |
||
164 | ['extra_id' => $searchWidgetId, 'position' => 'top'] |
||
165 | ); |
||
166 | } |
||
167 | } |
||
168 | |||
169 | private function getSearchWidgetId(): int |
||
170 | { |
||
171 | // @todo: Replace this with a ModuleExtraRepository method when it exists. |
||
172 | return (int) $this->getDatabase()->getVar( |
||
173 | 'SELECT id |
||
174 | FROM modules_extras |
||
175 | WHERE module = ? AND type = ? AND action = ?', |
||
176 | ['Search', ModuleExtraType::widget(), 'Form'] |
||
177 | ); |
||
178 | } |
||
179 | } |
||
180 |