Skip to content

Commit

Permalink
Merge branch 'MDL-25388_restore_activities_target' of git://github.co…
Browse files Browse the repository at this point in the history
…m/stronk7/moodle
  • Loading branch information
skodak committed Mar 7, 2011
2 parents 2c10c5f + 165b7bd commit 25ca24d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
18 changes: 13 additions & 5 deletions backup/util/ui/renderer.php
Expand Up @@ -181,7 +181,7 @@ public function course_selector(moodle_url $nextstageurl, $details, restore_cate
$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;
Expand All @@ -194,7 +194,7 @@ public function course_selector(moodle_url $nextstageurl, $details, restore_cate
$html .= html_writer::end_tag('form');
}

if (!empty($currentcourse)) {
if ($details->type == backup::TYPE_1COURSE && !empty($currentcourse)) {
// Current course
$hasrestoreoption = true;
$html .= $form;
Expand All @@ -214,9 +214,17 @@ public function course_selector(moodle_url $nextstageurl, $details, restore_cate
$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');
Expand Down
8 changes: 7 additions & 1 deletion backup/util/ui/restore_ui_components.php
Expand Up @@ -132,6 +132,7 @@ final public function set_url(moodle_url $url) {
*/
final public function invalidate_results() {
$this->results = null;
$this->totalcount = null;
}
/**
* Adds a required capability which all results will be checked against
Expand Down Expand Up @@ -217,6 +218,7 @@ class restore_course_search extends restore_search_base {
static $VAR_SEARCH = 'search';

protected $currentcourseid = null;
protected $includecurrentcourse;

/**
* @param array $config
Expand All @@ -226,6 +228,7 @@ public function __construct(array $config=array(), $currentcouseid = null) {
parent::__construct($config);
$this->require_capability('moodle/restore:restorecourse');
$this->currentcourseid = $currentcouseid;
$this->includecurrentcourse = false;
}
/**
*
Expand All @@ -246,7 +249,7 @@ protected function get_searchsql() {
$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;
}
Expand All @@ -260,6 +263,9 @@ protected function format_results() {}
public function get_varsearch() {
return self::$VAR_SEARCH;
}
public function set_include_currentcourse() {
$this->includecurrentcourse = true;
}
}

/**
Expand Down

0 comments on commit 25ca24d

Please sign in to comment.