3 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
19 * This file contains extension of the backup classes that override some methods
20 * and functionality in order to customise the backup UI for the purposes of
24 * @copyright 2010 Sam Hemelryk
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31 class import_ui
extends backup_ui
{
33 * Customises the backup progress bar
35 * @global moodle_page $PAGE
38 public function get_progress_bar() {
40 $stage = self
::STAGE_COMPLETE
;
41 $currentstage = $this->stage
->get_stage();
44 $classes = array('backup_stage');
45 if (floor($stage/2) == $currentstage) {
46 $classes[] = 'backup_stage_next';
47 } else if ($stage == $currentstage) {
48 $classes[] = 'backup_stage_current';
49 } else if ($stage < $currentstage) {
50 $classes[] = 'backup_stage_complete';
52 $item = array('text' => strlen(decbin($stage*2)).'. '.get_string('importcurrentstage'.$stage, 'backup'),'class' => join(' ', $classes));
53 if ($stage < $currentstage && $currentstage < self
::STAGE_COMPLETE
&& (!self
::$skipcurrentstage ||
$stage*2 != $currentstage)) {
54 $item['link'] = new moodle_url($PAGE->url
, $this->stage
->get_params() +
array('backup'=>$this->get_backupid(), 'stage'=>$stage));
56 array_unshift($items, $item);
57 $stage = floor($stage/2);
59 $selectorlink = new moodle_url($PAGE->url
, $this->stage
->get_params());
60 $selectorlink->remove_params('importid');
61 array_unshift($items, array(
62 'text' => '1. '.get_string('importcurrentstage0', 'backup'),
63 'class' => join(' ', $classes),
64 'link' => $selectorlink));
69 * Intialises what ever stage is requested. If none are requested we check
70 * params for 'stage' and default to initial
72 * @param int|null $stage The desired stage to intialise or null for the default
73 * @return backup_ui_stage_initial|backup_ui_stage_schema|backup_ui_stage_confirmation|backup_ui_stage_final
75 protected function initialise_stage($stage = null, array $params=null) {
77 $stage = optional_param('stage', self
::STAGE_INITIAL
, PARAM_INT
);
79 if (self
::$skipcurrentstage) {
83 case backup_ui
::STAGE_INITIAL
:
84 $stage = new import_ui_stage_inital($this, $params);
86 case backup_ui
::STAGE_SCHEMA
:
87 $stage = new import_ui_stage_schema($this, $params);
89 case backup_ui
::STAGE_CONFIRMATION
:
90 $stage = new import_ui_stage_confirmation($this, $params);
92 case backup_ui
::STAGE_FINAL
:
93 $stage = new import_ui_stage_final($this, $params);
104 * Extends the initial stage
106 class import_ui_stage_inital
extends backup_ui_stage_initial
{}
109 * Extends the schema stage
111 class import_ui_stage_schema
extends backup_ui_stage_schema
{}
114 * Extends the confirmation stage.
116 * This overides the initialise stage form to remove the filenamesetting heading
117 * as it is always hidden.
119 class import_ui_stage_confirmation
extends backup_ui_stage_confirmation
{
122 * Initialises the stages moodleform
125 protected function initialise_stage_form() {
126 $form = parent
::initialise_stage_form();
127 $form->remove_element('filenamesetting');
134 * This function is overriden so that we can manipulate the strings on the
137 public function display() {
138 $form = $this->initialise_stage_form();
139 $form->require_definition_after_data();
140 if ($e = $form->get_element('submitbutton')) {
141 $e->setLabel(get_string('import'.$this->get_ui()->get_name().'stage'.$this->get_stage().'action', 'backup'));
143 $elements = $form->get_element('buttonar')->getElements();
144 foreach ($elements as &$element) {
145 if ($element->getName()=='submitbutton') {
146 $element->setValue(get_string('import'.$this->get_ui()->get_name().'stage'.$this->get_stage().'action', 'backup'));
154 * Overrides the final stage.
156 class import_ui_stage_final
extends backup_ui_stage_final
{}
159 * Extends the restore course search to search for import courses.
161 class import_course_search
extends restore_course_search
{
163 * Sets up any access restrictions for the courses to be displayed in the search.
165 * This will typically call $this->require_capability().
167 protected function setup_restrictions() {
168 $this->require_capability('moodle/backup:backuptargetimport');