[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/mod/chat/backup/moodle2/ -> restore_chat_stepslib.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   * @package    mod_chat
  19   * @subpackage backup-moodle2
  20   * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
  21   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  22   */
  23  
  24  /**
  25   * Define all the restore steps that will be used by the restore_chat_activity_task
  26   */
  27  
  28  /**
  29   * Structure step to restore one chat activity
  30   */
  31  class restore_chat_activity_structure_step extends restore_activity_structure_step {
  32  
  33      protected function define_structure() {
  34  
  35          $paths = array();
  36          $userinfo = $this->get_setting_value('userinfo');
  37  
  38          $paths[] = new restore_path_element('chat', '/activity/chat');
  39          if ($userinfo) {
  40              $paths[] = new restore_path_element('chat_message', '/activity/chat/messages/message');
  41          }
  42  
  43          // Return the paths wrapped into standard activity structure.
  44          return $this->prepare_activity_structure($paths);
  45      }
  46  
  47      protected function process_chat($data) {
  48          global $DB;
  49  
  50          $data = (object)$data;
  51          $oldid = $data->id;
  52          $data->course = $this->get_courseid();
  53  
  54          $data->chattime = $this->apply_date_offset($data->chattime);
  55          $data->timemodified = $this->apply_date_offset($data->timemodified);
  56  
  57          // Insert the chat record.
  58          $newitemid = $DB->insert_record('chat', $data);
  59          // Immediately after inserting "activity" record, call this.
  60          $this->apply_activity_instance($newitemid);
  61      }
  62  
  63      protected function process_chat_message($data) {
  64          global $DB;
  65  
  66          $data = (object)$data;
  67          $oldid = $data->id;
  68          $data->chatid = $this->get_new_parentid('chat');
  69          $data->userid = $this->get_mappingid('user', $data->userid);
  70          $data->groupid = $this->get_mappingid('group', $data->groupid);
  71          $data->message = $data->message_text;
  72          $data->timestamp = $this->apply_date_offset($data->timestamp);
  73  
  74          $newitemid = $DB->insert_record('chat_messages', $data);
  75          $this->set_mapping('chat_message', $oldid, $newitemid); // Because of decode.
  76      }
  77  
  78      protected function after_execute() {
  79          // Add chat related files, no need to match by itemname (just internally handled context).
  80          $this->add_related_files('mod_chat', 'intro', null);
  81      }
  82  }


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