[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

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

   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 extension of the backup classes that override some methods
  20   * and functionality in order to customise the backup UI for the purposes of
  21   * import.
  22   *
  23   * @package   moodlecore
  24   * @copyright 2010 Sam Hemelryk
  25   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  26   */
  27  
  28  /**
  29   * Import UI class
  30   */
  31  class import_ui extends backup_ui {
  32      /**
  33       * Customises the backup progress bar
  34       *
  35       * @global moodle_page $PAGE
  36       * @return array
  37       */
  38      public function get_progress_bar() {
  39          global $PAGE;
  40          $stage = self::STAGE_COMPLETE;
  41          $currentstage = $this->stage->get_stage();
  42          $items = array();
  43          while ($stage > 0) {
  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';
  51              }
  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));
  55              }
  56              array_unshift($items, $item);
  57              $stage = floor($stage/2);
  58          }
  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));
  65          return $items;
  66      }
  67  
  68      /**
  69       * Intialises what ever stage is requested. If none are requested we check
  70       * params for 'stage' and default to initial
  71       *
  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
  74       */
  75      protected function initialise_stage($stage = null, array $params=null) {
  76          if ($stage == null) {
  77              $stage = optional_param('stage', self::STAGE_INITIAL, PARAM_INT);
  78          }
  79          if (self::$skipcurrentstage) {
  80              $stage *= 2;
  81          }
  82          switch ($stage) {
  83              case backup_ui::STAGE_INITIAL:
  84                  $stage = new import_ui_stage_inital($this, $params);
  85                  break;
  86              case backup_ui::STAGE_SCHEMA:
  87                  $stage = new import_ui_stage_schema($this, $params);
  88                  break;
  89              case backup_ui::STAGE_CONFIRMATION:
  90                  $stage = new import_ui_stage_confirmation($this, $params);
  91                  break;
  92              case backup_ui::STAGE_FINAL:
  93                  $stage = new import_ui_stage_final($this, $params);
  94                  break;
  95              default:
  96                  $stage = false;
  97                  break;
  98          }
  99          return $stage;
 100      }
 101  }
 102  
 103  /**
 104   * Extends the initial stage
 105   */
 106  class import_ui_stage_inital extends backup_ui_stage_initial {}
 107  
 108  /**
 109   * Extends the schema stage
 110   */
 111  class import_ui_stage_schema extends backup_ui_stage_schema {}
 112  
 113  /**
 114   * Extends the confirmation stage.
 115   *
 116   * This overides the initialise stage form to remove the filenamesetting heading
 117   * as it is always hidden.
 118   */
 119  class import_ui_stage_confirmation extends backup_ui_stage_confirmation {
 120  
 121      /**
 122       * Initialises the stages moodleform
 123       * @return moodleform
 124       */
 125      protected function initialise_stage_form() {
 126          $form = parent::initialise_stage_form();
 127          $form->remove_element('filenamesetting');
 128          return $form;
 129      }
 130  
 131      /**
 132       * Displays the stage
 133       *
 134       * This function is overriden so that we can manipulate the strings on the
 135       * buttons.
 136       *
 137       * @param core_backup_renderer $renderer
 138       * @return string HTML code to echo
 139       */
 140      public function display(core_backup_renderer $renderer) {
 141          $form = $this->initialise_stage_form();
 142          $form->require_definition_after_data();
 143          if ($e = $form->get_element('submitbutton')) {
 144              $e->setLabel(get_string('import'.$this->get_ui()->get_name().'stage'.$this->get_stage().'action', 'backup'));
 145          } else {
 146              $elements = $form->get_element('buttonar')->getElements();
 147              foreach ($elements as &$element) {
 148                  if ($element->getName()=='submitbutton') {
 149                      $element->setValue(get_string('import'.$this->get_ui()->get_name().'stage'.$this->get_stage().'action', 'backup'));
 150                  }
 151              }
 152          }
 153  
 154          // a nasty hack follows to work around the sad fact that moodle quickforms
 155          // do not allow to actually return the HTML content, just to echo it
 156          flush();
 157          ob_start();
 158          $form->display();
 159          $output = ob_get_contents();
 160          ob_end_clean();
 161  
 162          return $output;
 163      }
 164  }
 165  /**
 166   * Overrides the final stage.
 167   */
 168  class import_ui_stage_final extends backup_ui_stage_final {}
 169  
 170  /**
 171   * Extends the restore course search to search for import courses.
 172   */
 173  class import_course_search extends restore_course_search {
 174      /**
 175       * Sets up any access restrictions for the courses to be displayed in the search.
 176       *
 177       * This will typically call $this->require_capability().
 178       */
 179      protected function setup_restrictions() {
 180          $this->require_capability('moodle/backup:backuptargetimport');
 181      }
 182  }


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1