[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/backup/util/ui/ -> import_extensions.php (source)

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * This file contains extension of the backup classes that override some methods
  19   * and functionality in order to customise the backup UI for the purposes of
  20   * import.
  21   *
  22   * @package   core_backup
  23   * @copyright 2010 Sam Hemelryk
  24   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  25   */
  26  
  27  /**
  28   * Import UI class
  29   *
  30   * @package   core_backup
  31   * @copyright 2010 Sam Hemelryk
  32   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  33   */
  34  class import_ui extends backup_ui {
  35  
  36      /**
  37       * Customises the backup progress bar
  38       *
  39       * @global moodle_page $PAGE
  40       * @return array[] An array of arrays
  41       */
  42      public function get_progress_bar() {
  43          global $PAGE;
  44          $stage = self::STAGE_COMPLETE;
  45          $currentstage = $this->stage->get_stage();
  46          $items = array();
  47          while ($stage > 0) {
  48              $classes = array('backup_stage');
  49              if (floor($stage / 2) == $currentstage) {
  50                  $classes[] = 'backup_stage_next';
  51              } else if ($stage == $currentstage) {
  52                  $classes[] = 'backup_stage_current';
  53              } else if ($stage < $currentstage) {
  54                  $classes[] = 'backup_stage_complete';
  55              }
  56              $item = array(
  57                  'text' => strlen(decbin($stage * 2)).'. '.get_string('importcurrentstage'.$stage, 'backup'),
  58                  'class' => join(' ', $classes)
  59              );
  60              if ($stage < $currentstage && $currentstage < self::STAGE_COMPLETE && (!self::$skipcurrentstage || $stage * 2 != $currentstage)) {
  61                  $item['link'] = new moodle_url(
  62                      $PAGE->url,
  63                      $this->stage->get_params() + array('backup' => $this->get_backupid(), 'stage' => $stage)
  64                  );
  65              }
  66              array_unshift($items, $item);
  67              $stage = floor($stage / 2);
  68          }
  69          $selectorlink = new moodle_url($PAGE->url, $this->stage->get_params());
  70          $selectorlink->remove_params('importid');
  71          array_unshift($items, array(
  72                  'text' => '1. '.get_string('importcurrentstage0', 'backup'),
  73                  'class' => join(' ', $classes),
  74                  'link' => $selectorlink));
  75          return $items;
  76      }
  77  
  78      /**
  79       * Intialises what ever stage is requested. If none are requested we check
  80       * params for 'stage' and default to initial
  81       *
  82       * @param int|null $stage The desired stage to intialise or null for the default
  83       * @param array $params
  84       * @return backup_ui_stage_initial|backup_ui_stage_schema|backup_ui_stage_confirmation|backup_ui_stage_final
  85       */
  86      protected function initialise_stage($stage = null, array $params = null) {
  87          if ($stage == null) {
  88              $stage = optional_param('stage', self::STAGE_INITIAL, PARAM_INT);
  89          }
  90          if (self::$skipcurrentstage) {
  91              $stage *= 2;
  92          }
  93          switch ($stage) {
  94              case backup_ui::STAGE_INITIAL:
  95                  $stage = new import_ui_stage_inital($this, $params);
  96                  break;
  97              case backup_ui::STAGE_SCHEMA:
  98                  $stage = new import_ui_stage_schema($this, $params);
  99                  break;
 100              case backup_ui::STAGE_CONFIRMATION:
 101                  $stage = new import_ui_stage_confirmation($this, $params);
 102                  break;
 103              case backup_ui::STAGE_FINAL:
 104                  $stage = new import_ui_stage_final($this, $params);
 105                  break;
 106              default:
 107                  $stage = false;
 108                  break;
 109          }
 110          return $stage;
 111      }
 112  }
 113  
 114  /**
 115   * Extends the initial stage
 116   *
 117   * @package   core_backup
 118   * @copyright 2010 Sam Hemelryk
 119   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 120   */
 121  class import_ui_stage_inital extends backup_ui_stage_initial {}
 122  
 123  /**
 124   * Extends the schema stage
 125   *
 126   * @package   core_backup
 127   * @copyright 2010 Sam Hemelryk
 128   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 129   */
 130  class import_ui_stage_schema extends backup_ui_stage_schema {}
 131  
 132  /**
 133   * Extends the confirmation stage.
 134   *
 135   * This overides the initialise stage form to remove the filenamesetting heading
 136   * as it is always hidden.
 137   *
 138   * @package   core_backup
 139   * @copyright 2010 Sam Hemelryk
 140   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 141   */
 142  class import_ui_stage_confirmation extends backup_ui_stage_confirmation {
 143  
 144      /**
 145       * Initialises the stages moodleform
 146       * @return moodleform
 147       */
 148      protected function initialise_stage_form() {
 149          $form = parent::initialise_stage_form();
 150          $form->remove_element('filenamesetting');
 151          return $form;
 152      }
 153  
 154      /**
 155       * Displays the stage
 156       *
 157       * This function is overriden so that we can manipulate the strings on the
 158       * buttons.
 159       *
 160       * @param core_backup_renderer $renderer
 161       * @return string HTML code to echo
 162       */
 163      public function display(core_backup_renderer $renderer) {
 164          $form = $this->initialise_stage_form();
 165          $form->require_definition_after_data();
 166          if ($e = $form->get_element('submitbutton')) {
 167              $e->setLabel(get_string('import'.$this->get_ui()->get_name().'stage'.$this->get_stage().'action', 'backup'));
 168          } else {
 169              $elements = $form->get_element('buttonar')->getElements();
 170              foreach ($elements as &$element) {
 171                  if ($element->getName() == 'submitbutton') {
 172                      $element->setValue(
 173                          get_string('import'.$this->get_ui()->get_name().'stage'.$this->get_stage().'action', 'backup')
 174                      );
 175                  }
 176              }
 177          }
 178  
 179          // A nasty hack follows to work around the sad fact that moodle quickforms
 180          // do not allow to actually return the HTML content, just to echo it.
 181          flush();
 182          ob_start();
 183          $form->display();
 184          $output = ob_get_contents();
 185          ob_end_clean();
 186  
 187          return $output;
 188      }
 189  }
 190  /**
 191   * Overrides the final stage.
 192   *
 193   * @package   core_backup
 194   * @copyright 2010 Sam Hemelryk
 195   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 196   */
 197  class import_ui_stage_final extends backup_ui_stage_final {}
 198  
 199  /**
 200   * Extends the restore course search to search for import courses.
 201   *
 202   * @package   core_backup
 203   * @copyright 2010 Sam Hemelryk
 204   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 205   */
 206  class import_course_search extends restore_course_search {
 207      /**
 208       * Sets up any access restrictions for the courses to be displayed in the search.
 209       *
 210       * This will typically call $this->require_capability().
 211       */
 212      protected function setup_restrictions() {
 213          $this->require_capability('moodle/backup:backuptargetimport');
 214      }
 215  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1