Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/backup/util/plan/base_step.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 
00030 abstract class base_step implements executable, loggable {
00031 
00032     protected $name;      // One simple name for identification purposes
00033     protected $task;      // Task this is part of
00034 
00038     public function __construct($name, $task = null) {
00039         if (!is_null($task) && !($task instanceof base_task)) {
00040             throw new base_step_exception('wrong_base_task_specified');
00041         }
00042         $this->name = $name;
00043         $this->task = $task;
00044         if (!is_null($task)) { // Add the step to the task if specified
00045             $task->add_step($this);
00046         }
00047     }
00048 
00049     public function get_name() {
00050         return $this->name;
00051     }
00052 
00053     public function set_task($task) {
00054         if (! $task instanceof base_task) {
00055             throw new base_step_exception('wrong_base_task_specified');
00056         }
00057         $this->task = $task;
00058     }
00059 
00063     public function destroy() {
00064         // No need to destroy anything recursively here, direct reset
00065         $this->task = null;
00066     }
00067 
00068     public function log($message, $level, $a = null, $depth = null, $display = false) {
00069         if (is_null($this->task)) {
00070             throw new base_step_exception('not_specified_base_task');
00071         }
00072         backup_helper::log($message, $level, $a, $depth, $display, $this->get_logger());
00073     }
00074 
00076 
00077     protected function get_settings() {
00078         if (is_null($this->task)) {
00079             throw new base_step_exception('not_specified_base_task');
00080         }
00081         return $this->task->get_settings();
00082     }
00083 
00084     protected function get_setting($name) {
00085         if (is_null($this->task)) {
00086             throw new base_step_exception('not_specified_base_task');
00087         }
00088         return $this->task->get_setting($name);
00089     }
00090 
00091     protected function setting_exists($name) {
00092         if (is_null($this->task)) {
00093             throw new base_step_exception('not_specified_base_task');
00094         }
00095         return $this->task->setting_exists($name);
00096     }
00097 
00098     protected function get_setting_value($name) {
00099         if (is_null($this->task)) {
00100             throw new base_step_exception('not_specified_base_task');
00101         }
00102         return $this->task->get_setting_value($name);
00103     }
00104 
00105     protected function get_courseid() {
00106         if (is_null($this->task)) {
00107             throw new base_step_exception('not_specified_base_task');
00108         }
00109         return $this->task->get_courseid();
00110     }
00111 
00112     protected function get_basepath() {
00113         return $this->task->get_basepath();
00114     }
00115 
00116     protected function get_logger() {
00117         return $this->task->get_logger();
00118     }
00119 }
00120 
00121 
00122 /*
00123  * Exception class used by all the @base_step stuff
00124  */
00125 class base_step_exception extends moodle_exception {
00126 
00127     public function __construct($errorcode, $a=NULL, $debuginfo=null) {
00128         parent::__construct($errorcode, '', '', $a, $debuginfo);
00129     }
00130 }
 All Data Structures Namespaces Files Functions Variables Enumerations