Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/backup/moodle2/restore_block_task.class.php
Go to the documentation of this file.
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 abstract class restore_block_task extends restore_task {
00032 
00033     protected $taskbasepath; // To store the basepath of this block
00034     protected $blockname;    // Name of the block
00035     protected $contextid;   // new (target) context of the block
00036     protected $oldcontextid;// old (original) context of the block
00037     protected $blockid;     // new (target) id of the block
00038     protected $oldblockid;  // old (original) id of the block
00039 
00043     public function __construct($name, $taskbasepath, $plan = null) {
00044         $this->taskbasepath = $taskbasepath;
00045         $this->blockname = '';
00046         $this->contextid = 0;
00047         $this->oldcontextid = 0;
00048         $this->blockid = 0;
00049         $this->oldblockid = 0;
00050         parent::__construct($name, $plan);
00051     }
00052 
00056     public function get_taskbasepath() {
00057         return $this->taskbasepath;
00058     }
00059 
00063     public function build() {
00064 
00065         // If we have decided not to backup blocks, prevent anything to be built
00066         if (!$this->get_setting_value('blocks')) {
00067             $this->built = true;
00068             return;
00069         }
00070 
00071         // If "child" of activity task and it has been excluded, nothing to do
00072         $parent = basename(dirname(dirname($this->taskbasepath)));
00073         if ($parent != 'course') {
00074             $includedsetting = $parent . '_included';
00075             if (!$this->get_setting_value($includedsetting)) {
00076                 $this->built = true;
00077                 return;
00078             }
00079         }
00080 
00081         // Process the block.xml common file (instance + positions)
00082         $this->add_step(new restore_block_instance_structure_step('block_commons', 'block.xml'));
00083 
00084         // Here we add all the common steps for any block and, in the point of interest
00085         // we call to define_my_steps() in order to get the particular ones inserted in place.
00086         $this->define_my_steps();
00087 
00088         // Restore block role assignments and overrides (internally will observe the role_assignments setting)
00089         $this->add_step(new restore_ras_and_caps_structure_step('block_ras_and_caps', 'roles.xml'));
00090 
00091         // Restore block comments (conditionally)
00092         if ($this->get_setting_value('comments')) {
00093             $this->add_step(new restore_comments_structure_step('block_comments', 'comments.xml'));
00094         }
00095 
00096         // At the end, mark it as built
00097         $this->built = true;
00098     }
00099 
00100     public function set_blockname($blockname) {
00101         $this->blockname = $blockname;
00102     }
00103 
00104     public function get_blockname() {
00105         return $this->blockname;
00106     }
00107 
00108     public function set_blockid($blockid) {
00109         $this->blockid = $blockid;
00110     }
00111 
00112     public function get_blockid() {
00113         return $this->blockid;
00114     }
00115 
00116     public function set_old_blockid($blockid) {
00117         $this->oldblockid = $blockid;
00118     }
00119 
00120     public function get_old_blockid() {
00121         return $this->oldblockid;
00122     }
00123 
00124     public function set_contextid($contextid) {
00125         $this->contextid = $contextid;
00126     }
00127 
00128     public function get_contextid() {
00129         return $this->contextid;
00130     }
00131 
00132     public function set_old_contextid($contextid) {
00133         $this->oldcontextid = $contextid;
00134     }
00135 
00136     public function get_old_contextid() {
00137         return $this->oldcontextid;
00138     }
00139 
00143     abstract public function get_fileareas();
00144 
00149     abstract public function get_configdata_encoded_attributes();
00150 
00155     static public function define_decode_contents() {
00156         throw new coding_exception('define_decode_contents() method needs to be overridden in each subclass of restore_block_task');
00157     }
00158 
00163     static public function define_decode_rules() {
00164         throw new coding_exception('define_decode_rules() method needs to be overridden in each subclass of restore_block_task');
00165     }
00166 
00167 // Protected API starts here
00168 
00172     protected function define_settings() {
00173 
00174         // Nothing to add, blocks doesn't have common settings (for now)
00175 
00176         // End of common activity settings, let's add the particular ones
00177         $this->define_my_settings();
00178     }
00179 
00183     abstract protected function define_my_settings();
00184 
00188     abstract protected function define_my_steps();
00189 }
 All Data Structures Namespaces Files Functions Variables Enumerations