backup MDL-22142 P24 - Fixed locked settings with no dependencies

This commit is contained in:
Sam Hemelryk 2010-05-03 04:05:08 +00:00
parent c7d5e48f0a
commit e43ba98080
3 changed files with 66 additions and 16 deletions

View File

@ -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();

View File

@ -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

View File

@ -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';
}
}
/**