Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/backup/util/ui/backup_ui.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 
00035 class backup_ui extends base_ui {
00039     const STAGE_INITIAL = 1;
00040     const STAGE_SCHEMA = 2;
00041     const STAGE_CONFIRMATION = 4;
00042     const STAGE_FINAL = 8;
00043     const STAGE_COMPLETE = 16;
00044 
00049     protected static $skipcurrentstage = false;
00050 
00058     protected function initialise_stage($stage = null, array $params=null) {
00059         if ($stage == null) {
00060             $stage = optional_param('stage', self::STAGE_INITIAL, PARAM_INT);
00061         }
00062         if (self::$skipcurrentstage) {
00063             $stage *= 2;
00064         }
00065         switch ($stage) {
00066             case backup_ui::STAGE_INITIAL:
00067                 $stage = new backup_ui_stage_initial($this, $params);
00068                 break;
00069             case backup_ui::STAGE_SCHEMA:
00070                 $stage = new backup_ui_stage_schema($this, $params);
00071                 break;
00072             case backup_ui::STAGE_CONFIRMATION:
00073                 $stage = new backup_ui_stage_confirmation($this, $params);
00074                 break;
00075             case backup_ui::STAGE_FINAL:
00076                 $stage = new backup_ui_stage_final($this, $params);
00077                 break;
00078             default:
00079                 $stage = false;
00080                 break;
00081         }
00082         return $stage;
00083     }
00088     public function get_uniqueid() {
00089         return $this->get_backupid();
00090     }
00095     public function get_backupid() {
00096         return $this->controller->get_backupid();
00097     }
00102     public function execute() {
00103         if ($this->progress >= self::PROGRESS_EXECUTED) {
00104             throw new backup_ui_exception('backupuialreadyexecuted');
00105         }
00106         if ($this->stage->get_stage() < self::STAGE_FINAL) {
00107             throw new backup_ui_exception('backupuifinalisedbeforeexecute');
00108         }
00109         $this->progress = self::PROGRESS_EXECUTED;
00110         $this->controller->finish_ui();
00111         $this->controller->execute_plan();
00112         $this->stage = new backup_ui_stage_complete($this, $this->stage->get_params(), $this->controller->get_results());
00113         return true;
00114     }
00119     final public static function load_controller($backupid=false) {
00120         // Get the backup id optional param
00121         if ($backupid) {
00122             try {
00123                 // Try to load the controller with it.
00124                 // If it fails at this point it is likely because this is the first load
00125                 $controller = backup_controller::load_controller($backupid);
00126                 return $controller;
00127             } catch (Exception $e) {
00128                 return false;
00129             }
00130         }
00131         return $backupid;
00132     }
00133 
00138     public function get_progress_bar() {
00139         global $PAGE;
00140 
00141         $stage = self::STAGE_COMPLETE;
00142         $currentstage = $this->stage->get_stage();
00143         $items = array();
00144         while ($stage > 0) {
00145             $classes = array('backup_stage');
00146             if (floor($stage/2) == $currentstage) {
00147                 $classes[] = 'backup_stage_next';
00148             } else if ($stage == $currentstage) {
00149                 $classes[] = 'backup_stage_current';
00150             } else if ($stage < $currentstage) {
00151                 $classes[] = 'backup_stage_complete';
00152             }
00153             $item = array('text' => strlen(decbin($stage)).'. '.get_string('currentstage'.$stage, 'backup'),'class' => join(' ', $classes));
00154             if ($stage < $currentstage && $currentstage < self::STAGE_COMPLETE && (!self::$skipcurrentstage || ($stage*2) != $currentstage)) {
00155                 $params = $this->stage->get_params();
00156                 if (empty($params)) {
00157                     $params = array();
00158                 }
00159                 $params = array_merge($params, array('backup'=>$this->get_backupid(), 'stage'=>$stage));
00160                 $item['link'] = new moodle_url($PAGE->url, $params);
00161             }
00162             array_unshift($items, $item);
00163             $stage = floor($stage/2);
00164         }
00165         return $items;
00166     }
00171     public function get_name() {
00172         return 'backup';
00173     }
00178     public function get_first_stage_id() {
00179         return self::STAGE_INITIAL;
00180     }
00185     public static function skip_current_stage($setting=true) {
00186         self::$skipcurrentstage = $setting;
00187     }
00188 }
00189 
00193 class backup_ui_exception extends base_ui_exception {}
 All Data Structures Namespaces Files Functions Variables Enumerations