Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/backup/moodle2/restore_subplugin.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 
00032 abstract class restore_subplugin {
00033 
00034     protected $subplugintype;
00035     protected $subpluginname;
00036     protected $connectionpoint;
00037     protected $step;
00038     protected $task;
00039 
00040     public function __construct($subplugintype, $subpluginname, $step) {
00041         $this->subplugintype = $subplugintype;
00042         $this->subpluginname = $subpluginname;
00043         $this->step          = $step;
00044         $this->task          = $step->get_task();
00045         $this->connectionpoint = '';
00046     }
00047 
00048     public function define_subplugin_structure($connectionpoint) {
00049         if (!$connectionpoint instanceof restore_path_element) {
00050             throw new restore_step_exception('restore_path_element_required', $connectionpoint);
00051         }
00052 
00053         $paths = array();
00054         $this->connectionpoint = $connectionpoint;
00055         $methodname = 'define_' . basename($this->connectionpoint->get_path()) . '_subplugin_structure';
00056 
00057         if (method_exists($this, $methodname)) {
00058             if ($subbluginpaths = $this->$methodname()) {
00059                 foreach ($subbluginpaths as $path) {
00060                     $path->set_processing_object($this);
00061                     $paths[] = $path;
00062                 }
00063             }
00064         }
00065         return $paths;
00066     }
00067 
00077     public function launch_after_execute_methods() {
00078         // Check if the after_execute method exists and launch it
00079         $afterexecute = 'after_execute_' . basename($this->connectionpoint->get_path());
00080         if (method_exists($this, $afterexecute)) {
00081             $this->$afterexecute();
00082         }
00083     }
00084 
00085 // Protected API starts here
00086 
00087 // restore_step/structure_step/task wrappers
00088 
00089     protected function get_restoreid() {
00090         if (is_null($this->task)) {
00091             throw new restore_step_exception('not_specified_restore_task');
00092         }
00093         return $this->task->get_restoreid();
00094     }
00095 
00105     protected function set_mapping($itemname, $oldid, $newid, $restorefiles = false, $filesctxid = null, $parentid = null) {
00106         $this->step->set_mapping($itemname, $oldid, $newid, $restorefiles, $filesctxid, $parentid);
00107     }
00108 
00112     protected function get_old_parentid($itemname) {
00113         return $this->step->get_old_parentid($itemname);
00114     }
00115 
00119     protected function get_new_parentid($itemname) {
00120         return $this->step->get_new_parentid($itemname);
00121     }
00122 
00130     protected function get_mappingid($itemname, $oldid, $ifnotfound = false) {
00131         return $this->step->get_mappingid($itemname, $oldid, $ifnotfound);
00132     }
00133 
00137     protected function get_mapping($itemname, $oldid) {
00138         return $this->step->get_mapping($itemname, $oldid);
00139     }
00140 
00144     protected function add_related_files($component, $filearea, $mappingitemname, $filesctxid = null, $olditemid = null) {
00145         $this->step->add_related_files($component, $filearea, $mappingitemname, $filesctxid, $olditemid);
00146     }
00147 
00153     protected function apply_date_offset($value) {
00154         return $this->step->apply_date_offset($value);
00155     }
00156 
00160     protected function get_setting_value($name) {
00161         if (is_null($this->task)) {
00162             throw new restore_step_exception('not_specified_restore_task');
00163         }
00164         return $this->task->get_setting_value($name);
00165     }
00166 
00167 // end of restore_step/structure_step/task wrappers
00168 
00173     protected function get_namefor($name = '') {
00174         $name = $name !== '' ? '_' . $name : '';
00175         return $this->subplugintype . '_' . $this->subpluginname . $name;
00176     }
00177 
00182     protected function get_pathfor($path = '') {
00183         $path = trim($path, '/') !== '' ? '/' . trim($path, '/') : '';
00184         return $this->connectionpoint->get_path() . '/' .
00185                'subplugin_' . $this->subplugintype . '_' .
00186                $this->subpluginname . '_' . basename($this->connectionpoint->get_path()) . $path;
00187     }
00188 }
 All Data Structures Namespaces Files Functions Variables Enumerations