Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 46... Línea 46...
46
     * @var base_ui_stage
46
     * @var base_ui_stage
47
     */
47
     */
48
    protected $uistage = null;
48
    protected $uistage = null;
Línea 49... Línea 49...
49
 
49
 
50
    /**
50
    /**
51
     * True if we have a course div open, false otherwise
51
     * Group stack to control open and closed div groups.
52
     * @var bool
52
     * @var array
53
     */
53
     */
54
    protected $coursediv = false;
-
 
55
 
-
 
56
    /**
-
 
57
     * True if we have a section div open, false otherwise
-
 
58
     * @var bool
-
 
59
     */
-
 
60
    protected $sectiondiv = false;
-
 
61
 
-
 
62
    /**
-
 
63
     * True if we have an activity div open, false otherwise
-
 
64
     * @var bool
-
 
65
     */
-
 
Línea 66... Línea 54...
66
    protected $activitydiv = false;
54
    protected array $groupstack = [];
67
 
55
 
68
    /**
56
    /**
69
     * Creates the form
57
     * Creates the form
Línea 175... Línea 163...
175
 
163
 
176
        $this->_definition_finalized = true;
164
        $this->_definition_finalized = true;
Línea 177... Línea 165...
177
    }
165
    }
178
 
166
 
179
    /**
167
    /**
180
     * Closes any open divs
168
     * Closes any open divs.
181
     */
-
 
182
    public function close_task_divs() {
-
 
183
        if ($this->activitydiv) {
-
 
184
            $this->_form->addElement('html', html_writer::end_tag('div'));
-
 
185
            $this->activitydiv = false;
-
 
186
        }
-
 
187
        if ($this->sectiondiv) {
-
 
188
            $this->_form->addElement('html', html_writer::end_tag('div'));
-
 
189
            $this->sectiondiv = false;
169
     */
190
        }
170
    public function close_task_divs() {
191
        if ($this->coursediv) {
171
        while (!empty($this->groupstack)) {
192
            $this->_form->addElement('html', html_writer::end_tag('div'));
172
            $this->_form->addElement('html', html_writer::end_tag('div'));
193
            $this->coursediv = false;
173
            array_pop($this->groupstack);
Línea 194... Línea 174...
194
        }
174
        }
195
    }
175
    }
196
 
176
 
197
    /**
177
    /**
198
     * Adds the backup_setting as a element to the form
178
     * Adds the backup_setting as a element to the form
199
     * @param backup_setting $setting
179
     * @param backup_setting $setting
200
     * @param base_task $task
180
     * @param base_task $task
201
     * @return bool
181
     * @return bool
202
     */
182
     */
Línea 203... Línea 183...
203
    public function add_setting(backup_setting $setting, base_task $task = null) {
183
    public function add_setting(backup_setting $setting, ?base_task $task = null) {
204
        return $this->add_settings(array(array($setting, $task)));
184
        return $this->add_settings(array(array($setting, $task)));
Línea 242... Línea 222...
242
            $defaults[$setting->get_ui_name()] = $setting->get_value();
222
            $defaults[$setting->get_ui_name()] = $setting->get_value();
243
            if ($setting->has_help()) {
223
            if ($setting->has_help()) {
244
                list($identifier, $component) = $setting->get_help();
224
                list($identifier, $component) = $setting->get_help();
245
                $this->_form->addHelpButton($setting->get_ui_name(), $identifier, $component);
225
                $this->_form->addHelpButton($setting->get_ui_name(), $identifier, $component);
246
            }
226
            }
247
            $this->_form->addElement('html', html_writer::end_tag('div'));
227
            $this->pop_group();
248
        }
228
        }
249
        $this->_form->setDefaults($defaults);
229
        $this->_form->setDefaults($defaults);
250
        return true;
230
        return true;
251
    }
231
    }
Línea 263... Línea 243...
263
     * Adds HTML formatting for the given backup setting, needed to group/segment
243
     * Adds HTML formatting for the given backup setting, needed to group/segment
264
     * correctly.
244
     * correctly.
265
     * @param backup_setting $setting
245
     * @param backup_setting $setting
266
     */
246
     */
267
    protected function add_html_formatting(backup_setting $setting) {
247
    protected function add_html_formatting(backup_setting $setting) {
268
        $mform = $this->_form;
-
 
269
        $isincludesetting = (strpos($setting->get_name(), '_include') !== false);
248
        $isincludesetting = (strpos($setting->get_name(), '_include') !== false);
270
        if ($isincludesetting && $setting->get_level() != backup_setting::ROOT_LEVEL) {
249
        if ($isincludesetting && $setting->get_level() != backup_setting::ROOT_LEVEL) {
271
            switch ($setting->get_level()) {
250
            switch ($setting->get_level()) {
272
                case backup_setting::COURSE_LEVEL:
251
                case backup_setting::COURSE_LEVEL:
273
                    if ($this->activitydiv) {
-
 
274
                        $this->_form->addElement('html', html_writer::end_tag('div'));
-
 
275
                        $this->activitydiv = false;
-
 
276
                    }
-
 
277
                    if ($this->sectiondiv) {
-
 
278
                        $this->_form->addElement('html', html_writer::end_tag('div'));
-
 
279
                        $this->sectiondiv = false;
252
                    $this->pop_groups_to('course');
280
                    }
-
 
281
                    if ($this->coursediv) {
-
 
282
                        $this->_form->addElement('html', html_writer::end_tag('div'));
-
 
283
                    }
-
 
284
                    $mform->addElement('html', html_writer::start_tag('div', array('class' => 'grouped_settings course_level')));
253
                    $this->push_group_start('course', 'grouped_settings course_level');
285
                    $mform->addElement('html', html_writer::start_tag('div', array('class' => 'include_setting course_level')));
254
                    $this->push_group_start(null, 'include_setting course_level');
286
                    $this->coursediv = true;
-
 
287
                    break;
255
                    break;
288
                case backup_setting::SECTION_LEVEL:
256
                case backup_setting::SECTION_LEVEL:
289
                    if ($this->activitydiv) {
-
 
290
                        $this->_form->addElement('html', html_writer::end_tag('div'));
-
 
291
                        $this->activitydiv = false;
257
                    $this->pop_groups_to('course');
292
                    }
-
 
293
                    if ($this->sectiondiv) {
-
 
294
                        $this->_form->addElement('html', html_writer::end_tag('div'));
-
 
295
                    }
-
 
296
                    $mform->addElement('html', html_writer::start_tag('div', array('class' => 'grouped_settings section_level')));
258
                    $this->push_group_start('section', 'grouped_settings section_level');
297
                    $mform->addElement('html', html_writer::start_tag('div', array('class' => 'include_setting section_level')));
259
                    $this->push_group_start(null, 'include_setting section_level');
298
                    $this->sectiondiv = true;
-
 
299
                    break;
260
                    break;
300
                case backup_setting::ACTIVITY_LEVEL:
261
                case backup_setting::ACTIVITY_LEVEL:
301
                    if ($this->activitydiv) {
262
                    $this->pop_groups_to('section');
-
 
263
                    $this->push_group_start('activity', 'grouped_settings activity_level');
302
                        $this->_form->addElement('html', html_writer::end_tag('div'));
264
                    $this->push_group_start(null, 'include_setting activity_level');
303
                    }
265
                    break;
-
 
266
                case backup_setting::SUBSECTION_LEVEL:
-
 
267
                    $this->pop_groups_to('section');
304
                    $mform->addElement('html', html_writer::start_tag('div', array('class' => 'grouped_settings activity_level')));
268
                    $this->push_group_start('subsection', 'grouped_settings subsection_level');
305
                    $mform->addElement('html', html_writer::start_tag('div', array('class' => 'include_setting activity_level')));
269
                    $this->push_group_start(null, 'normal_setting');
-
 
270
                    break;
-
 
271
                case backup_setting::SUBACTIVITY_LEVEL:
306
                    $this->activitydiv = true;
272
                    $this->pop_groups_to('subsection');
-
 
273
                    $this->push_group_start('subactivity', 'grouped_settings activity_level');
-
 
274
                    $this->push_group_start(null, 'include_setting activity_level');
307
                    break;
275
                    break;
308
                default:
276
                default:
309
                    $mform->addElement('html', html_writer::start_tag('div', array('class' => 'normal_setting')));
277
                    $this->push_group_start(null, 'normal_setting');
310
                    break;
278
                    break;
311
            }
279
            }
312
        } else if ($setting->get_level() == backup_setting::ROOT_LEVEL) {
280
        } else if ($setting->get_level() == backup_setting::ROOT_LEVEL) {
313
            $mform->addElement('html', html_writer::start_tag('div', array('class' => 'root_setting')));
281
            $this->push_group_start('root', 'root_setting');
314
        } else {
282
        } else {
315
            $mform->addElement('html', html_writer::start_tag('div', array('class' => 'normal_setting')));
283
            $this->push_group_start(null, 'normal_setting');
316
        }
284
        }
317
    }
285
    }
Línea 318... Línea 286...
318
 
286
 
319
    /**
287
    /**
Línea 348... Línea 316...
348
            $labelicon = $settingui->get_icon();
316
            $labelicon = $settingui->get_icon();
349
            if (!empty($labelicon)) {
317
            if (!empty($labelicon)) {
350
                $label .= $OUTPUT->render($labelicon);
318
                $label .= $OUTPUT->render($labelicon);
351
            }
319
            }
352
            $this->_form->addElement('static', 'static_'.$settingui->get_name(), $label, $settingui->get_static_value().$icon);
320
            $this->_form->addElement('static', 'static_'.$settingui->get_name(), $label, $settingui->get_static_value().$icon);
353
            $this->_form->addElement('html', html_writer::end_tag('div'));
321
            $this->pop_group();
354
        }
322
        }
355
        $this->_form->addElement('hidden', $settingui->get_name(), $settingui->get_value());
323
        $this->_form->addElement('hidden', $settingui->get_name(), $settingui->get_value());
356
        $this->_form->setType($settingui->get_name(), $settingui->get_param_validation());
324
        $this->_form->setType($settingui->get_name(), $settingui->get_param_validation());
357
    }
325
    }
Línea 358... Línea 326...
358
 
326
 
-
 
327
    /**
-
 
328
     * Pushes a group start to the form.
-
 
329
     *
-
 
330
     * This method will create a new group div in the form and add it to the group stack.
-
 
331
     * The name can be used to close all stacked groups up to a certain group.
-
 
332
     *
-
 
333
     * @param string|null $name The name of the group, if any.
-
 
334
     * @param string $classes The classes to add to the div.
-
 
335
     */
-
 
336
    protected function push_group_start(?string $name, string $classes) {
-
 
337
        $mform = $this->_form;
-
 
338
        $this->groupstack[] = $name;
-
 
339
        $mform->addElement('html', html_writer::start_tag('div', ['class' => $classes]));
-
 
340
    }
-
 
341
 
-
 
342
    /**
-
 
343
     * Pops groups from the stack until the given group name is reached.
-
 
344
     *
-
 
345
     * @param string $name The name of the group to pop to.
-
 
346
     */
-
 
347
    protected function pop_groups_to(string $name) {
-
 
348
        if (empty($this->groupstack)) {
-
 
349
            return;
-
 
350
        }
-
 
351
        while (!empty($this->groupstack) && end($this->groupstack) !== $name) {
-
 
352
            $this->pop_group();
-
 
353
        }
-
 
354
    }
-
 
355
 
-
 
356
    /**
-
 
357
     * Pops a group from the stack and closes the div.
-
 
358
     *
-
 
359
     * @return string|null The name of the group that was popped, or null if the stack is empty.
-
 
360
     */
-
 
361
    protected function pop_group(): ?string {
-
 
362
        if (empty($this->groupstack)) {
-
 
363
            return null;
-
 
364
        }
-
 
365
        $mform = $this->_form;
-
 
366
        $mform->addElement('html', html_writer::end_tag('div'));
-
 
367
        return array_pop($this->groupstack);
-
 
368
    }
-
 
369
 
359
    /**
370
    /**
360
     * Adds dependencies to the form recursively
371
     * Adds dependencies to the form recursively
361
     *
372
     *
362
     * @param backup_setting $setting
373
     * @param backup_setting $setting
363
     */
374
     */
Línea 414... Línea 425...
414
 
425
 
415
        // Get list of module types on course.
426
        // Get list of module types on course.
416
        $modinfo = get_fast_modinfo($COURSE);
427
        $modinfo = get_fast_modinfo($COURSE);
417
        $modnames = array_map('strval', $modinfo->get_used_module_names(true));
428
        $modnames = array_map('strval', $modinfo->get_used_module_names(true));
418
        core_collator::asort($modnames);
429
        core_collator::asort($modnames);
419
        $PAGE->requires->yui_module('moodle-backup-backupselectall', 'M.core_backup.backupselectall',
-
 
420
                array($modnames));
430
        $PAGE->requires->js_call_amd('core_backup/schema_backup_form', 'init', [$modnames]);
421
        $PAGE->requires->strings_for_js(array('select', 'all', 'none'), 'moodle');
431
        $PAGE->requires->strings_for_js(array('select', 'all', 'none'), 'moodle');
Línea 422... Línea 432...
422
        $PAGE->requires->strings_for_js(array('showtypes', 'hidetypes'), 'backup');
432
        $PAGE->requires->strings_for_js(array('showtypes', 'hidetypes'), 'backup');
423
 
433