[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 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/>. 17 18 /** 19 * This file contains the backup user interface class 20 * 21 * @package moodlecore 22 * @copyright 2010 Sam Hemelryk 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 /** 27 * This is the backup user interface class 28 * 29 * The backup user interface class manages the user interface and backup for 30 * Moodle. 31 * 32 * @copyright 2010 Sam Hemelryk 33 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 34 */ 35 class backup_ui extends base_ui { 36 /** 37 * The stages of the backup user interface. 38 */ 39 const STAGE_INITIAL = 1; 40 const STAGE_SCHEMA = 2; 41 const STAGE_CONFIRMATION = 4; 42 const STAGE_FINAL = 8; 43 const STAGE_COMPLETE = 16; 44 45 /** 46 * If set to true the current stage is skipped. 47 * @var bool 48 */ 49 protected static $skipcurrentstage = false; 50 51 /** 52 * Intialises what ever stage is requested. If none are requested we check 53 * params for 'stage' and default to initial 54 * 55 * @param int|null $stage The desired stage to intialise or null for the default 56 * @return backup_ui_stage_initial|backup_ui_stage_schema|backup_ui_stage_confirmation|backup_ui_stage_final 57 */ 58 protected function initialise_stage($stage = null, array $params=null) { 59 if ($stage == null) { 60 $stage = optional_param('stage', self::STAGE_INITIAL, PARAM_INT); 61 } 62 if (self::$skipcurrentstage) { 63 $stage *= 2; 64 } 65 switch ($stage) { 66 case backup_ui::STAGE_INITIAL: 67 $stage = new backup_ui_stage_initial($this, $params); 68 break; 69 case backup_ui::STAGE_SCHEMA: 70 $stage = new backup_ui_stage_schema($this, $params); 71 break; 72 case backup_ui::STAGE_CONFIRMATION: 73 $stage = new backup_ui_stage_confirmation($this, $params); 74 break; 75 case backup_ui::STAGE_FINAL: 76 $stage = new backup_ui_stage_final($this, $params); 77 break; 78 default: 79 $stage = false; 80 break; 81 } 82 return $stage; 83 } 84 /** 85 * Returns the backup id 86 * @return string 87 */ 88 public function get_uniqueid() { 89 return $this->get_backupid(); 90 } 91 /** 92 * Gets the backup id from the controller 93 * @return string 94 */ 95 public function get_backupid() { 96 return $this->controller->get_backupid(); 97 } 98 /** 99 * Executes the backup plan 100 * @return bool 101 */ 102 public function execute() { 103 if ($this->progress >= self::PROGRESS_EXECUTED) { 104 throw new backup_ui_exception('backupuialreadyexecuted'); 105 } 106 if ($this->stage->get_stage() < self::STAGE_FINAL) { 107 throw new backup_ui_exception('backupuifinalisedbeforeexecute'); 108 } 109 $this->progress = self::PROGRESS_EXECUTED; 110 $this->controller->finish_ui(); 111 $this->controller->execute_plan(); 112 $this->stage = new backup_ui_stage_complete($this, $this->stage->get_params(), $this->controller->get_results()); 113 return true; 114 } 115 /** 116 * Loads the backup controller if we are tracking one 117 * @return backup_controller|false 118 */ 119 final public static function load_controller($backupid=false) { 120 // Get the backup id optional param 121 if ($backupid) { 122 try { 123 // Try to load the controller with it. 124 // If it fails at this point it is likely because this is the first load 125 $controller = backup_controller::load_controller($backupid); 126 return $controller; 127 } catch (Exception $e) { 128 return false; 129 } 130 } 131 return $backupid; 132 } 133 134 /** 135 * Gets an array of progress bar items that can be displayed through the backup renderer. 136 * @return array Array of items for the progress bar 137 */ 138 public function get_progress_bar() { 139 global $PAGE; 140 141 $stage = self::STAGE_COMPLETE; 142 $currentstage = $this->stage->get_stage(); 143 $items = array(); 144 while ($stage > 0) { 145 $classes = array('backup_stage'); 146 if (floor($stage/2) == $currentstage) { 147 $classes[] = 'backup_stage_next'; 148 } else if ($stage == $currentstage) { 149 $classes[] = 'backup_stage_current'; 150 } else if ($stage < $currentstage) { 151 $classes[] = 'backup_stage_complete'; 152 } 153 $item = array('text' => strlen(decbin($stage)).'. '.get_string('currentstage'.$stage, 'backup'),'class' => join(' ', $classes)); 154 if ($stage < $currentstage && $currentstage < self::STAGE_COMPLETE && (!self::$skipcurrentstage || ($stage*2) != $currentstage)) { 155 $params = $this->stage->get_params(); 156 if (empty($params)) { 157 $params = array(); 158 } 159 $params = array_merge($params, array('backup'=>$this->get_backupid(), 'stage'=>$stage)); 160 $item['link'] = new moodle_url($PAGE->url, $params); 161 } 162 array_unshift($items, $item); 163 $stage = floor($stage/2); 164 } 165 return $items; 166 } 167 /** 168 * Gets the name related to the operation of this UI 169 * @return string 170 */ 171 public function get_name() { 172 return 'backup'; 173 } 174 /** 175 * Gets the id of the first stage this UI is reponsible for 176 * @return int 177 */ 178 public function get_first_stage_id() { 179 return self::STAGE_INITIAL; 180 } 181 /** 182 * If called with default arg the current stage gets skipped. 183 * @static 184 */ 185 public static function skip_current_stage($setting=true) { 186 self::$skipcurrentstage = $setting; 187 } 188 } 189 190 /** 191 * Backup user interface exception. Modelled off the backup_exception class 192 */ 193 class backup_ui_exception extends base_ui_exception {}
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |