|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00031 class restore_course_task extends restore_task { 00032 00033 protected $info; // info related to course gathered from backup file 00034 protected $contextid; // course context id 00035 00039 public function __construct($name, $info, $plan = null) { 00040 $this->info = $info; 00041 parent::__construct($name, $plan); 00042 } 00043 00047 public function get_taskbasepath() { 00048 00049 return $this->get_basepath() . '/course'; 00050 } 00051 00052 public function get_contextid() { 00053 return $this->contextid; 00054 } 00055 00059 public function build() { 00060 00061 // Define the task contextid (the course one) 00062 $this->contextid = get_context_instance(CONTEXT_COURSE, $this->get_courseid())->id; 00063 00064 // Executed conditionally if restoring to new course or if overwrite_conf setting is enabled 00065 if ($this->get_target() == backup::TARGET_NEW_COURSE || $this->get_setting_value('overwrite_conf') == true) { 00066 $this->add_step(new restore_course_structure_step('course_info', 'course.xml')); 00067 } 00068 00069 // Restore course role assignments and overrides (internally will observe the role_assignments setting) 00070 $this->add_step(new restore_ras_and_caps_structure_step('course_ras_and_caps', 'roles.xml')); 00071 00072 // Restore course enrolments (plugins and membership). Conditionally prevented for any IMPORT/HUB operation 00073 if ($this->plan->get_mode() != backup::MODE_IMPORT && $this->plan->get_mode() != backup::MODE_HUB) { 00074 $this->add_step(new restore_enrolments_structure_step('course_enrolments', 'enrolments.xml')); 00075 } 00076 00077 // Restore course filters (conditionally) 00078 if ($this->get_setting_value('filters')) { 00079 $this->add_step(new restore_filters_structure_step('course_filters', 'filters.xml')); 00080 } 00081 00082 // Restore course comments (conditionally) 00083 if ($this->get_setting_value('comments')) { 00084 $this->add_step(new restore_comments_structure_step('course_comments', 'comments.xml')); 00085 } 00086 00087 // At the end, mark it as built 00088 $this->built = true; 00089 } 00090 00095 static public function define_decode_contents() { 00096 $contents = array(); 00097 00098 $contents[] = new restore_decode_content('course', 'summary'); 00099 00100 return $contents; 00101 } 00102 00107 static public function define_decode_rules() { 00108 $rules = array(); 00109 00110 $rules[] = new restore_decode_rule('COURSEVIEWBYID', '/course/view.php?id=$1', 'course'); 00111 00112 return $rules; 00113 00114 } 00115 00116 // Protected API starts here 00117 00121 protected function define_settings() { 00122 00123 //$name, $vtype, $value = null, $visibility = self::VISIBLE, $status = self::NOT_LOCKED 00124 $fullname = new restore_course_generic_text_setting('course_fullname', base_setting::IS_TEXT, $this->get_info()->original_course_fullname); 00125 $fullname->get_ui()->set_label(get_string('setting_course_fullname', 'backup')); 00126 $this->add_setting($fullname); 00127 00128 $shortname = new restore_course_generic_text_setting('course_shortname', base_setting::IS_TEXT, $this->get_info()->original_course_shortname); 00129 $shortname->get_ui()->set_label(get_string('setting_course_shortname', 'backup')); 00130 $this->add_setting($shortname); 00131 00132 $startdate = new restore_course_generic_text_setting('course_startdate', base_setting::IS_INTEGER, $this->get_info()->original_course_startdate); 00133 $startdate->set_ui(new backup_setting_ui_dateselector($startdate, get_string('setting_course_startdate', 'backup'))); 00134 $this->add_setting($startdate); 00135 00136 $keep_enrols = new restore_course_generic_setting('keep_roles_and_enrolments', base_setting::IS_BOOLEAN, false); 00137 $keep_enrols->set_ui(new backup_setting_ui_select($keep_enrols, $keep_enrols->get_name(), array(1=>get_string('yes'), 0=>get_string('no')))); 00138 $keep_enrols->get_ui()->set_label(get_string('setting_keep_roles_and_enrolments', 'backup')); 00139 if ($this->get_target() != backup::TARGET_CURRENT_DELETING and $this->get_target() != backup::TARGET_EXISTING_DELETING) { 00140 $keep_enrols->set_value(false); 00141 $keep_enrols->set_status(backup_setting::LOCKED_BY_CONFIG); 00142 $keep_enrols->set_visibility(backup_setting::HIDDEN); 00143 } 00144 $this->add_setting($keep_enrols); 00145 00146 $keep_groups = new restore_course_generic_setting('keep_groups_and_groupings', base_setting::IS_BOOLEAN, false); 00147 $keep_groups->set_ui(new backup_setting_ui_select($keep_groups, $keep_groups->get_name(), array(1=>get_string('yes'), 0=>get_string('no')))); 00148 $keep_groups->get_ui()->set_label(get_string('setting_keep_groups_and_groupings', 'backup')); 00149 if ($this->get_target() != backup::TARGET_CURRENT_DELETING and $this->get_target() != backup::TARGET_EXISTING_DELETING) { 00150 $keep_groups->set_value(false); 00151 $keep_groups->set_status(backup_setting::LOCKED_BY_CONFIG); 00152 $keep_groups->set_visibility(backup_setting::HIDDEN); 00153 } 00154 $this->add_setting($keep_groups); 00155 00156 // Define overwrite_conf to decide if course configuration will be restored over existing one 00157 $overwrite = new restore_course_overwrite_conf_setting('overwrite_conf', base_setting::IS_BOOLEAN, false); 00158 $overwrite->set_ui(new backup_setting_ui_select($overwrite, $overwrite->get_name(), array(1=>get_string('yes'), 0=>get_string('no')))); 00159 $overwrite->get_ui()->set_label(get_string('setting_overwriteconf', 'backup')); 00160 if ($this->get_target() == backup::TARGET_NEW_COURSE) { 00161 $overwrite->set_value(true); 00162 $overwrite->set_status(backup_setting::LOCKED_BY_CONFIG); 00163 $overwrite->set_visibility(backup_setting::HIDDEN); 00164 } 00165 $this->add_setting($overwrite); 00166 00167 } 00168 }