backup MDL-22142 P13 - File name is now given default value and correctly sized
authorSam Hemelryk <sam@moodle.com>
Mon, 3 May 2010 05:03:24 +0000 (05:03 +0000)
committerSam Hemelryk <sam@moodle.com>
Mon, 3 May 2010 05:03:24 +0000 (05:03 +0000)
backup/moodle2/backup_root_task.class.php
backup/util/ui/backup_ui.class.php
backup/util/ui/backup_ui_setting.class.php
backup/util/ui/backup_ui_stage.class.php

index 3ddafa2..d8bff83 100644 (file)
@@ -49,7 +49,7 @@ class backup_root_task extends backup_task {
 
         // 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)
index 875cca4..b1ac533 100644 (file)
@@ -345,6 +345,41 @@ class backup_ui {
         }
         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;
+        }
+    }
 }
 
 /**
index 8271a0b..dac4cce 100644 (file)
@@ -152,6 +152,9 @@ abstract class backup_setting_ui extends base_setting_ui {
      * @return array
      */
     public function apply_options(array $properties) {
+        if (!empty($this->options['size'])) {
+            $properties['attributes']['size'] = $this->options['size'];
+        }
         return $properties;
     }
     /**
index 2fae15f..d3f9972 100644 (file)
@@ -427,6 +427,15 @@ class backup_ui_stage_confirmation extends backup_ui_stage {
                 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);
                 }
             }