|
Moodle
2.2.1
http://www.collinsharper.com
|
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 class import_ui extends backup_ui { 00038 public function get_progress_bar() { 00039 global $PAGE; 00040 $stage = self::STAGE_COMPLETE; 00041 $currentstage = $this->stage->get_stage(); 00042 $items = array(); 00043 while ($stage > 0) { 00044 $classes = array('backup_stage'); 00045 if (floor($stage/2) == $currentstage) { 00046 $classes[] = 'backup_stage_next'; 00047 } else if ($stage == $currentstage) { 00048 $classes[] = 'backup_stage_current'; 00049 } else if ($stage < $currentstage) { 00050 $classes[] = 'backup_stage_complete'; 00051 } 00052 $item = array('text' => strlen(decbin($stage*2)).'. '.get_string('importcurrentstage'.$stage, 'backup'),'class' => join(' ', $classes)); 00053 if ($stage < $currentstage && $currentstage < self::STAGE_COMPLETE && (!self::$skipcurrentstage || $stage*2 != $currentstage)) { 00054 $item['link'] = new moodle_url($PAGE->url, $this->stage->get_params() + array('backup'=>$this->get_backupid(), 'stage'=>$stage)); 00055 } 00056 array_unshift($items, $item); 00057 $stage = floor($stage/2); 00058 } 00059 $selectorlink = new moodle_url($PAGE->url, $this->stage->get_params()); 00060 $selectorlink->remove_params('importid'); 00061 array_unshift($items, array( 00062 'text' => '1. '.get_string('importcurrentstage0', 'backup'), 00063 'class' => join(' ', $classes), 00064 'link' => $selectorlink)); 00065 return $items; 00066 } 00067 00075 protected function initialise_stage($stage = null, array $params=null) { 00076 if ($stage == null) { 00077 $stage = optional_param('stage', self::STAGE_INITIAL, PARAM_INT); 00078 } 00079 if (self::$skipcurrentstage) { 00080 $stage *= 2; 00081 } 00082 switch ($stage) { 00083 case backup_ui::STAGE_INITIAL: 00084 $stage = new import_ui_stage_inital($this, $params); 00085 break; 00086 case backup_ui::STAGE_SCHEMA: 00087 $stage = new import_ui_stage_schema($this, $params); 00088 break; 00089 case backup_ui::STAGE_CONFIRMATION: 00090 $stage = new import_ui_stage_confirmation($this, $params); 00091 break; 00092 case backup_ui::STAGE_FINAL: 00093 $stage = new import_ui_stage_final($this, $params); 00094 break; 00095 default: 00096 $stage = false; 00097 break; 00098 } 00099 return $stage; 00100 } 00101 } 00102 00106 class import_ui_stage_inital extends backup_ui_stage_initial {} 00107 00111 class import_ui_stage_schema extends backup_ui_stage_schema {} 00112 00119 class import_ui_stage_confirmation extends backup_ui_stage_confirmation { 00120 00125 protected function initialise_stage_form() { 00126 $form = parent::initialise_stage_form(); 00127 $form->remove_element('filenamesetting'); 00128 return $form; 00129 } 00130 00137 public function display() { 00138 $form = $this->initialise_stage_form(); 00139 $form->require_definition_after_data(); 00140 if ($e = $form->get_element('submitbutton')) { 00141 $e->setLabel(get_string('import'.$this->get_ui()->get_name().'stage'.$this->get_stage().'action', 'backup')); 00142 } else { 00143 $elements = $form->get_element('buttonar')->getElements(); 00144 foreach ($elements as &$element) { 00145 if ($element->getName()=='submitbutton') { 00146 $element->setValue(get_string('import'.$this->get_ui()->get_name().'stage'.$this->get_stage().'action', 'backup')); 00147 } 00148 } 00149 } 00150 $form->display(); 00151 } 00152 } 00156 class import_ui_stage_final extends backup_ui_stage_final {} 00157 00161 class import_course_search extends restore_course_search { 00167 protected function setup_restrictions() { 00168 $this->require_capability('moodle/backup:backuptargetimport'); 00169 } 00170 }