From e43ba980804969a66584dcd7ed3c994bea1fcb97 Mon Sep 17 00:00:00 2001 From: Sam Hemelryk Date: Mon, 3 May 2010 04:05:08 +0000 Subject: [PATCH] backup MDL-22142 P24 - Fixed locked settings with no dependencies --- backup/util/settings/base_setting.class.php | 62 +++++++++++++++------ backup/util/ui/backup_moodleform.class.php | 13 +++++ backup/util/ui/backup_ui_setting.class.php | 7 +++ 3 files changed, 66 insertions(+), 16 deletions(-) diff --git a/backup/util/settings/base_setting.class.php b/backup/util/settings/base_setting.class.php index fe711b1355c..375a3d4d502 100644 --- a/backup/util/settings/base_setting.class.php +++ b/backup/util/settings/base_setting.class.php @@ -188,22 +188,6 @@ abstract class base_setting { } } - /** - * Returns an array of all dependencies this setting has as well as the dependencies - * of its dependencies.... another words recursivily - * @return array - */ - public function get_all_dependencies() { - $dependencies = array_values($this->dependencies); - foreach ($this->dependencies as &$dependency) { - $childdependencies = $dependency->get_dependent_setting()->get_all_dependencies(); - foreach ($childdependencies as $name=>&$childdependency) { - $dependencies[] = $childdependency; - } - } - return $dependencies; - } - /** * Gets an array of properties for all of the dependencies that will affect * this setting. @@ -232,10 +216,41 @@ abstract class base_setting { return $dependencies; } + /** + * Checks if there are other settings that are dependent on this setting + * + * @return bool True if there are other settings that are dependent on this setting + */ + public function has_dependent_settings() { + return (count($this->dependencies)>0); + } + + /** + * Checks if this setting is dependent on any other settings + * + * @return bool True if this setting is dependent on any other settings + */ + public function has_dependencies_on_settings() { + return (count($this->dependenton)>0); + } + + /** + * Sets the user interface for this setting + * + * @param backup_setting_ui $ui + */ public function set_ui(backup_setting_ui $ui) { $this->uisetting = $ui; } + /** + * Creates and sets a user interface for this setting given appropriate arguments + * + * @param int $type + * @param string $label + * @param array $attributes + * @param array $options + */ public function make_ui($type, $label, array $attributes = null, array $options = null) { $type = $this->validate_ui_type($type); $label = $this->validate_ui_label($label); @@ -264,6 +279,11 @@ abstract class base_setting { } } + /** + * Gets the user interface for this setting + * + * @return backup_setting_ui + */ public function get_ui() { return $this->uisetting; } @@ -293,6 +313,16 @@ abstract class base_setting { $this->dependenton[$dependency->get_setting()->get_name()] = $dependency; } + /** + * Quick method to add a dependency to this setting. + * + * The dependency created is done so by inspecting this setting and the + * setting that is passed in as the dependent setting. + * + * @param base_setting $dependentsetting + * @param int $type One of setting_dependency::* + * @param array $options + */ public function add_dependency(base_setting $dependentsetting, $type=null, $options=array()) { if ($this->is_circular_reference($dependentsetting)) { $a = new stdclass(); diff --git a/backup/util/ui/backup_moodleform.class.php b/backup/util/ui/backup_moodleform.class.php index 06872ed8631..96877f0eaa5 100644 --- a/backup/util/ui/backup_moodleform.class.php +++ b/backup/util/ui/backup_moodleform.class.php @@ -110,6 +110,19 @@ abstract class backup_moodleform extends moodleform { * @return bool */ function add_setting(backup_setting $setting, backup_task $task=null) { + + // Check if the setting is locked first up + if ($setting->get_status() !== base_setting::NOT_LOCKED) { + // If it has no dependencies on other settings we can add it as a + // fixed setting instead + if (!$setting->has_dependencies_on_settings()) { + // Fixed setting it is! + return $this->add_fixed_setting($setting); + } + // Hmm possible to unlock it in the UI so disable instead. + $setting->get_ui()->disable(); + } + // First add the formatting for this setting $this->add_html_formatting($setting); // The call the add method with the get_element_properties array diff --git a/backup/util/ui/backup_ui_setting.class.php b/backup/util/ui/backup_ui_setting.class.php index b6146076398..8271a0b1f68 100644 --- a/backup/util/ui/backup_ui_setting.class.php +++ b/backup/util/ui/backup_ui_setting.class.php @@ -214,6 +214,13 @@ abstract class backup_setting_ui extends base_setting_ui { public function set_label($label) { $this->label = $label; } + /** + * Disables the UI for this element + */ + public function disable() { + $this->attributes['disabled'] = 'disabled'; + } + } /**