MDL-25388 restore - confusing options restoring 1-activity
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Fri, 4 Mar 2011 18:45:43 +0000 (19:45 +0100)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Fri, 4 Mar 2011 18:45:43 +0000 (19:45 +0100)
backup/util/ui/renderer.php
backup/util/ui/restore_ui_components.php

index f8ab57b..e07bc0b 100644 (file)
@@ -181,7 +181,7 @@ class core_backup_renderer extends plugin_renderer_base {
         $hasrestoreoption = false;
 
         $html  = html_writer::start_tag('div', array('class'=>'backup-course-selector backup-restore'));
-        if (!empty($categories) && ($categories->get_count() > 0 || $categories->get_search())) {
+        if ($details->type == backup::TYPE_1COURSE && !empty($categories) && ($categories->get_count() > 0 || $categories->get_search())) {
             // New course
             $hasrestoreoption = true;
             $html .= $form;
@@ -194,7 +194,7 @@ class core_backup_renderer extends plugin_renderer_base {
             $html .= html_writer::end_tag('form');
         }
 
-        if (!empty($currentcourse)) {
+        if ($details->type == backup::TYPE_1COURSE && !empty($currentcourse)) {
             // Current course
             $hasrestoreoption = true;
             $html .= $form;
@@ -214,9 +214,17 @@ class core_backup_renderer extends plugin_renderer_base {
             $html .= $form;
             $html .= html_writer::start_tag('div', array('class'=>'bcs-existing-course backup-section'));
             $html .= $this->output->heading(get_string('restoretoexistingcourse', 'backup'), 2, array('class'=>'header'));
-            $html .= $this->backup_detail_input(get_string('restoretoexistingcourseadding', 'backup'), 'radio', 'target', backup::TARGET_EXISTING_ADDING, array('checked'=>'checked'));
-            $html .= $this->backup_detail_input(get_string('restoretoexistingcoursedeleting', 'backup'), 'radio', 'target', backup::TARGET_EXISTING_DELETING);
-            $html .= $this->backup_detail_pair(get_string('selectacourse', 'backup'), $this->render($courses));
+            if ($details->type == backup::TYPE_1COURSE) {
+                $html .= $this->backup_detail_input(get_string('restoretoexistingcourseadding', 'backup'), 'radio', 'target', backup::TARGET_EXISTING_ADDING, array('checked'=>'checked'));
+                $html .= $this->backup_detail_input(get_string('restoretoexistingcoursedeleting', 'backup'), 'radio', 'target', backup::TARGET_EXISTING_DELETING);
+                $html .= $this->backup_detail_pair(get_string('selectacourse', 'backup'), $this->render($courses));
+            } else {
+                // We only allow restore adding to existing for now. Enforce it here.
+                $html .= html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'target', 'value'=>backup::TARGET_EXISTING_ADDING));
+                $courses->invalidate_results(); // Clean list of courses
+                $courses->set_include_currentcourse(); // Show current course in the list
+                $html .= $this->backup_detail_pair(get_string('selectacourse', 'backup'), $this->render($courses));
+            }
             $html .= $this->backup_detail_pair('', html_writer::empty_tag('input', array('type'=>'submit', 'value'=>get_string('continue'))));
             $html .= html_writer::end_tag('div');
             $html .= html_writer::end_tag('form');
index 5243c1d..056f7a1 100644 (file)
@@ -132,6 +132,7 @@ abstract class restore_search_base implements renderable {
      */
     final public function invalidate_results() {
         $this->results = null;
+        $this->totalcount = null;
     }
     /**
      * Adds a required capability which all results will be checked against
@@ -217,6 +218,7 @@ class restore_course_search extends restore_search_base {
     static $VAR_SEARCH = 'search';
 
     protected $currentcourseid = null;
+    protected $includecurrentcourse;
 
     /**
      * @param array $config
@@ -226,6 +228,7 @@ class restore_course_search extends restore_search_base {
         parent::__construct($config);
         $this->require_capability('moodle/restore:restorecourse');
         $this->currentcourseid = $currentcouseid;
+        $this->includecurrentcourse = false;
     }
     /**
      *
@@ -246,7 +249,7 @@ class restore_course_search extends restore_search_base {
         $where      = " WHERE (".$DB->sql_like('c.fullname', ':fullnamesearch', false)." OR ".$DB->sql_like('c.shortname', ':shortnamesearch', false).") AND c.id <> :siteid";
         $orderby    = " ORDER BY c.sortorder";
 
-        if ($this->currentcourseid !== null) {
+        if ($this->currentcourseid !== null && !$this->includecurrentcourse) {
             $where .= " AND c.id <> :currentcourseid";
             $params['currentcourseid'] = $this->currentcourseid;
         }
@@ -260,6 +263,9 @@ class restore_course_search extends restore_search_base {
     public function get_varsearch() {
         return self::$VAR_SEARCH;
     }
+    public function set_include_currentcourse() {
+        $this->includecurrentcourse = true;
+    }
 }
 
 /**