// Define filename setting
$filename = new backup_filename_setting('filename', base_setting::IS_FILENAME, 'backup.zip');
- $filename->set_ui(get_string('filename', 'backup'), 'backup.zip');
+ $filename->set_ui(get_string('filename', 'backup'), '', array('size'=>50));
$this->add_setting($filename);
// Define users setting (keeping it on hand to define dependencies)
}
return $items;
}
+ /**
+ * Gets the format for the backup
+ * @return int
+ */
+ public function get_backup_format() {
+ return $this->controller->get_format();
+ }
+ /**
+ * Gets the type of the backup
+ * @return int
+ */
+ public function get_backup_type() {
+ return $this->controller->get_type();
+ }
+ /**
+ * Gets the ID used in creating the controller. Relates to course/section/cm
+ * @return int
+ */
+ public function get_controller_id() {
+ return $this->controller->get_id();
+ }
+ /**
+ * Gets the value for the requested setting
+ *
+ * @param string $name
+ * @return mixed
+ */
+ public function get_setting_value($name, $default = false) {
+ try {
+ return $this->controller->get_plan()->get_setting($name)->get_value();
+ } catch (Exception $e) {
+ debugging('Failed to find the setting: '.$name, DEBUG_DEVELOPER);
+ return $default;
+ }
+ }
}
/**
* @return array
*/
public function apply_options(array $properties) {
+ if (!empty($this->options['size'])) {
+ $properties['attributes']['size'] = $this->options['size'];
+ }
return $properties;
}
/**
if ($setting->get_name() != 'filename') {
$form->add_fixed_setting($setting);
} else {
+ $value = $setting->get_value();
+ if (empty($value)) {
+ $format = $this->ui->get_backup_format();
+ $type = $this->ui->get_backup_type();
+ $id = $this->ui->get_controller_id();
+ $users = $this->ui->get_setting_value('users');
+ $anonymised = $this->ui->get_setting_value('anonymize');
+ $setting->set_value(backup_plan_dbops::get_default_backup_filename($format, $type, $id, $users, $anonymised));
+ }
$form->add_setting($setting, $task);
}
}