eccc25f08ec0d1b7b7da7ea072cc725df2e7b8ec
[moodle.git] / backup / moodle2 / restore_course_task.class.php
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
18 /**
19  * @package moodlecore
20  * @subpackage backup-moodle2
21  * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
22  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23  */
25 /**
26  * course task that provides all the properties and common steps to be performed
27  * when one course is being restored
28  *
29  * TODO: Finish phpdocs
30  */
31 class restore_course_task extends restore_task {
33     protected $info; // info related to course gathered from backup file
35     /**
36      * Constructor - instantiates one object of this class
37      */
38     public function __construct($name, $info, $plan = null) {
39         $this->info = $info;
40         parent::__construct($name, $plan);
41     }
43     /**
44      * Course tasks have their own directory to read files
45      */
46     public function get_taskbasepath() {
48         return $this->get_basepath() . '/course';
49     }
51     /**
52      * Create all the steps that will be part of this task
53      */
54     public function build() {
56         // TODO: Link all the course steps here
57         // Executed conditionally if restoring to new course or deleting or if overwrite_conf setting is enabled
58         if ($this->get_target() == backup::TARGET_NEW_COURSE || $this->get_setting_value('overwrite_conf') == true) {
59             $this->add_step(new restore_course_structure_step('course_info', 'course.xml'));
60         }
62         // At the end, mark it as built
63         $this->built = true;
64     }
66     /**
67      * Code the transformations to perform in the course in
68      * order to get encoded transformed back to working links
69      */
70     static public function decode_content_links($content) {
72         // TODO: Decode COURSEVIEWBYID
74         return $content;
75     }
77 // Protected API starts here
79     /**
80      * Define the common setting that any restore course will have
81      */
82     protected function define_settings() {
84         // Define overwrite_conf to decide if course configuration will be restored over existing one
85         $overwrite = new restore_course_overwrite_conf_setting('overwrite_conf', base_setting::IS_BOOLEAN, false);
86         $overwrite->set_ui(new backup_setting_ui_select($overwrite, $overwrite->get_name(), array(1=>get_string('yes'), 0=>get_string('no'))));
87         $this->add_setting($overwrite);
89     }
90 }