[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/mod/glossary/backup/moodle2/ -> restore_glossary_stepslib.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   * @package mod_glossary
  20   * @subpackage backup-moodle2
  21   * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  /**
  26   * Define all the restore steps that will be used by the restore_glossary_activity_task
  27   */
  28  
  29  /**
  30   * Structure step to restore one glossary activity
  31   */
  32  class restore_glossary_activity_structure_step extends restore_activity_structure_step {
  33  
  34      protected function define_structure() {
  35  
  36          $paths = array();
  37          $userinfo = $this->get_setting_value('userinfo');
  38  
  39          $paths[] = new restore_path_element('glossary', '/activity/glossary');
  40          $paths[] = new restore_path_element('glossary_category', '/activity/glossary/categories/category');
  41          if ($userinfo) {
  42              $paths[] = new restore_path_element('glossary_entry', '/activity/glossary/entries/entry');
  43              $paths[] = new restore_path_element('glossary_alias', '/activity/glossary/entries/entry/aliases/alias');
  44              $paths[] = new restore_path_element('glossary_rating', '/activity/glossary/entries/entry/ratings/rating');
  45              $paths[] = new restore_path_element('glossary_category_entry',
  46                                                  '/activity/glossary/categories/category/category_entries/category_entry');
  47          }
  48  
  49          // Return the paths wrapped into standard activity structure
  50          return $this->prepare_activity_structure($paths);
  51      }
  52  
  53      protected function process_glossary($data) {
  54          global $DB;
  55  
  56          $data = (object)$data;
  57          $oldid = $data->id;
  58          $data->course = $this->get_courseid();
  59  
  60          $data->assesstimestart = $this->apply_date_offset($data->assesstimestart);
  61          $data->assesstimefinish = $this->apply_date_offset($data->assesstimefinish);
  62          if ($data->scale < 0) { // scale found, get mapping
  63              $data->scale = -($this->get_mappingid('scale', abs($data->scale)));
  64          }
  65          $formats = get_list_of_plugins('mod/glossary/formats'); // Check format
  66          if (!in_array($data->displayformat, $formats)) {
  67              $data->displayformat = 'dictionary';
  68          }
  69          if (!empty($data->mainglossary) and $data->mainglossary == 1 and
  70              $DB->record_exists('glossary', array('mainglossary' => 1, 'course' => $this->get_courseid()))) {
  71              // Only allow one main glossary in the course
  72              $data->mainglossary = 0;
  73          }
  74  
  75          // insert the glossary record
  76          $newitemid = $DB->insert_record('glossary', $data);
  77          $this->apply_activity_instance($newitemid);
  78      }
  79  
  80      protected function process_glossary_entry($data) {
  81          global $DB;
  82  
  83          $data = (object)$data;
  84          $oldid = $data->id;
  85  
  86          $data->glossaryid = $this->get_new_parentid('glossary');
  87          $data->userid = $this->get_mappingid('user', $data->userid);
  88          $data->sourceglossaryid = $this->get_mappingid('glossary', $data->sourceglossaryid);
  89  
  90          $data->timecreated = $this->apply_date_offset($data->timecreated);
  91          $data->timemodified = $this->apply_date_offset($data->timemodified);
  92  
  93          // insert the entry record
  94          $newitemid = $DB->insert_record('glossary_entries', $data);
  95          $this->set_mapping('glossary_entry', $oldid, $newitemid, true); // childs and files by itemname
  96      }
  97  
  98      protected function process_glossary_alias($data) {
  99          global $DB;
 100  
 101          $data = (object)$data;
 102          $oldid = $data->id;
 103  
 104          $data->entryid = $this->get_new_parentid('glossary_entry');
 105          $data->alias =  $data->alias_text;
 106          $newitemid = $DB->insert_record('glossary_alias', $data);
 107      }
 108  
 109      protected function process_glossary_rating($data) {
 110          global $DB;
 111  
 112          $data = (object)$data;
 113  
 114          // Cannot use ratings API, cause, it's missing the ability to specify times (modified/created)
 115          $data->contextid = $this->task->get_contextid();
 116          $data->itemid    = $this->get_new_parentid('glossary_entry');
 117          if ($data->scaleid < 0) { // scale found, get mapping
 118              $data->scaleid = -($this->get_mappingid('scale', abs($data->scaleid)));
 119          }
 120          $data->rating = $data->value;
 121          $data->userid = $this->get_mappingid('user', $data->userid);
 122          $data->timecreated = $this->apply_date_offset($data->timecreated);
 123          $data->timemodified = $this->apply_date_offset($data->timemodified);
 124  
 125          // Make sure that we have both component and ratingarea set. These were added in 2.1.
 126          // Prior to that all ratings were for entries so we know what to set them too.
 127          if (empty($data->component)) {
 128              $data->component = 'mod_glossary';
 129          }
 130          if (empty($data->ratingarea)) {
 131              $data->ratingarea = 'entry';
 132          }
 133  
 134          $newitemid = $DB->insert_record('rating', $data);
 135      }
 136  
 137      protected function process_glossary_category($data) {
 138          global $DB;
 139  
 140          $data = (object)$data;
 141          $oldid = $data->id;
 142  
 143          $data->glossaryid = $this->get_new_parentid('glossary');
 144          $newitemid = $DB->insert_record('glossary_categories', $data);
 145          $this->set_mapping('glossary_category', $oldid, $newitemid);
 146      }
 147  
 148      protected function process_glossary_category_entry($data) {
 149          global $DB;
 150  
 151          $data = (object)$data;
 152          $oldid = $data->id;
 153  
 154          $data->categoryid = $this->get_new_parentid('glossary_category');
 155          $data->entryid    = $this->get_mappingid('glossary_entry', $data->entryid);
 156          $newitemid = $DB->insert_record('glossary_entries_categories', $data);
 157      }
 158  
 159      protected function after_execute() {
 160          // Add glossary related files, no need to match by itemname (just internally handled context)
 161          $this->add_related_files('mod_glossary', 'intro', null);
 162          // Add entries related files, matching by itemname (glossary_entry)
 163          $this->add_related_files('mod_glossary', 'entry', 'glossary_entry');
 164          $this->add_related_files('mod_glossary', 'attachment', 'glossary_entry');
 165      }
 166  }


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