|
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 backup_course_task extends backup_task { 00032 00033 protected $courseid; 00034 protected $contextid; 00035 00039 public function __construct($name, $courseid, $plan = null) { 00040 00041 $this->courseid = $courseid; 00042 $this->contextid = get_context_instance(CONTEXT_COURSE, $this->courseid)->id; 00043 00044 parent::__construct($name, $plan); 00045 } 00046 00047 public function get_contextid() { 00048 return $this->contextid; 00049 } 00050 00054 public function get_taskbasepath() { 00055 00056 return $this->get_basepath() . '/course'; 00057 } 00058 00062 public function build() { 00063 00064 // Add some extra settings that related processors are going to need 00065 $this->add_setting(new backup_activity_generic_setting(backup::VAR_COURSEID, base_setting::IS_INTEGER, $this->get_courseid())); 00066 $this->add_setting(new backup_activity_generic_setting(backup::VAR_CONTEXTID, base_setting::IS_INTEGER, $this->contextid)); 00067 00068 // Create the course directory 00069 $this->add_step(new create_taskbasepath_directory('create_course_directory')); 00070 00071 // Create the course.xml file with course & category information 00072 // annotating some bits, tags and module restrictions 00073 $this->add_step(new backup_course_structure_step('course_info', 'course.xml')); 00074 00075 // Generate the enrolment file (conditionally, prevent it in any IMPORT/HUB operation) 00076 if ($this->plan->get_mode() != backup::MODE_IMPORT && $this->plan->get_mode() != backup::MODE_HUB) { 00077 $this->add_step(new backup_enrolments_structure_step('course_enrolments', 'enrolments.xml')); 00078 } 00079 00080 // Annotate all the groups and groupings belonging to the course 00081 $this->add_step(new backup_annotate_course_groups_and_groupings('annotate_course_groups')); 00082 00083 // Annotate the groups used in already annotated groupings (note this may be 00084 // unnecessary now that we are annotating all the course groups and groupings in the 00085 // step above. But we keep it working in case we decide, someday, to introduce one 00086 // setting to transform the step above into an optional one. This is here to support 00087 // course->defaultgroupingid 00088 $this->add_step(new backup_annotate_groups_from_groupings('annotate_groups_from_groupings')); 00089 00090 // Annotate the question_categories belonging to the course context 00091 $this->add_step(new backup_calculate_question_categories('course_question_categories')); 00092 00093 // Generate the roles file (optionally role assignments and always role overrides) 00094 $this->add_step(new backup_roles_structure_step('course_roles', 'roles.xml')); 00095 00096 // Generate the filter file (conditionally) 00097 if ($this->get_setting_value('filters')) { 00098 $this->add_step(new backup_filters_structure_step('course_filters', 'filters.xml')); 00099 } 00100 00101 // Generate the comments file (conditionally) 00102 if ($this->get_setting_value('comments')) { 00103 $this->add_step(new backup_comments_structure_step('course_comments', 'comments.xml')); 00104 } 00105 00106 // Generate the logs file (conditionally) 00107 if ($this->get_setting_value('logs')) { 00108 $this->add_step(new backup_course_logs_structure_step('course_logs', 'logs.xml')); 00109 } 00110 00111 // Generate the inforef file (must be after ALL steps gathering annotations of ANY type) 00112 $this->add_step(new backup_inforef_structure_step('course', 'inforef.xml')); 00113 00114 // Migrate the already exported inforef entries to final ones 00115 $this->add_step(new move_inforef_annotations_to_final('migrate_inforef')); 00116 00117 // At the end, mark it as built 00118 $this->built = true; 00119 } 00120 00125 static public function encode_content_links($content) { 00126 global $CFG; 00127 00128 $base = preg_quote($CFG->wwwroot, '/'); 00129 00130 // Link to the course main page (it also covers "&topic=xx" and "&week=xx" 00131 // because they don't become transformed (section number) in backup/restore 00132 $search = '/(' . $base . '\/course\/view.php\?id\=)([0-9]+)/'; 00133 $content= preg_replace($search, '$@COURSEVIEWBYID*$2@$', $content); 00134 00135 return $content; 00136 } 00137 00138 // Protected API starts here 00139 00143 protected function define_settings() { 00144 00145 // Nothing to add, sections doesn't have common settings (for now) 00146 00147 } 00148 }