Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-27120 More efficient use of QuickForms in backup UI

  • Loading branch information...
commit 01ab87feda2946bb6ce52bdf4084a3af0a83872a 1 parent 9e4b9a0
@ashleyholman ashleyholman authored rajeshtaneja committed
View
22 backup/util/ui/backup_ui_stage.class.php
@@ -124,6 +124,8 @@ protected function initialise_stage_form() {
// Store as a variable so we can iterate by reference
$tasks = $this->ui->get_tasks();
// Iterate all tasks by reference
+ $add_settings = array();
+ $dependencies = array();
foreach ($tasks as &$task) {
// For the initial stage we are only interested in the root settings
if ($task instanceof backup_root_task) {
@@ -134,17 +136,23 @@ protected function initialise_stage_form() {
if ($setting->get_name() == 'filename') {
continue;
}
- $form->add_setting($setting, $task);
+ $add_settings[] = array($setting, $task);
}
// Then add all dependencies
foreach ($settings as &$setting) {
if ($setting->get_name() == 'filename') {
continue;
}
- $form->add_dependencies($setting);
+ $dependencies[] = $setting;
}
}
}
+ // Add all settings at once
+ $form->add_settings($add_settings);
+ // Add dependencies
+ foreach ($dependencies as $depsetting) {
+ $form->add_dependencies($setting);
+ }
$this->stageform = $form;
}
// Return the form
@@ -226,6 +234,8 @@ protected function initialise_stage_form() {
$tasks = $this->ui->get_tasks();
$content = '';
$courseheading = false;
+ $add_settings = array();
+ $dependencies = array();
foreach ($tasks as $task) {
if (!($task instanceof backup_root_task)) {
if (!$courseheading) {
@@ -235,11 +245,11 @@ protected function initialise_stage_form() {
}
// First add each setting
foreach ($task->get_settings() as $setting) {
- $form->add_setting($setting, $task);
+ $add_settings[] = array($setting, $task);
}
// The add all the dependencies
foreach ($task->get_settings() as $setting) {
- $form->add_dependencies($setting);
+ $dependencies[] = $setting;
}
} else if ($this->ui->enforce_changed_dependencies()) {
// Only show these settings if dependencies changed them.
@@ -254,6 +264,10 @@ protected function initialise_stage_form() {
}
}
}
+ $form->add_settings($add_settings);
+ foreach($dependencies as $depsetting) {
+ $form->add_dependencies($depsetting);
+ }
$this->stageform = $form;
}
return $this->stageform;
View
34 backup/util/ui/base_moodleform.class.php
@@ -157,6 +157,38 @@ function add_setting(backup_setting $setting, base_task $task=null) {
return true;
}
/**
+ * Adds multiple backup_settings as elements to the form
+ * @param array $settingstasks Consists of array($setting, $task) elements
+ * @return bool
+ */
+ function add_settings(array $settingstasks) {
+ global $OUTPUT;
+
+ $defaults = array();
+ foreach ($settingstasks as $st) {
+ list($setting, $task) = $st;
+ // If the setting cant be changed or isn't visible then add it as a fixed setting.
+ if (!$setting->get_ui()->is_changeable() || $setting->get_visibility() != backup_setting::VISIBLE) {
+ $this->add_fixed_setting($setting, $task);
+ continue;
+ }
+
+ // First add the formatting for this setting
+ $this->add_html_formatting($setting);
+
+ // Then call the add method with the get_element_properties array
+ call_user_func_array(array($this->_form, 'addElement'), $setting->get_ui()->get_element_properties($task, $OUTPUT));
+ $defaults[$setting->get_ui_name()] = $setting->get_value();
+ if ($setting->has_help()) {
+ list($identifier, $component) = $setting->get_help();
+ $this->_form->addHelpButton($setting->get_ui_name(), $identifier, $component);
+ }
+ $this->_form->addElement('html', html_writer::end_tag('div'));
+ }
+ $this->_form->setDefaults($defaults);
+ return true;
+ }
+ /**
* Adds a heading to the form
* @param string $name
* @param string $text
@@ -317,4 +349,4 @@ public function require_definition_after_data() {
$this->definition_after_data();
}
}
-}
+}

0 comments on commit 01ab87f

Please sign in to comment.
Something went wrong with that request. Please try again.