Differences Between: [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403]
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 * Defines the restore_enrol_lti_plugin class. 19 * 20 * @package enrol_lti 21 * @copyright 2016 Mark Nelson <markn@moodle.com> 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 defined('MOODLE_INTERNAL') || die(); 26 27 /** 28 * Define all the restore steps. 29 * 30 * @package enrol_lti 31 * @copyright 2016 Mark Nelson <markn@moodle.com> 32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 33 */ 34 class restore_enrol_lti_plugin extends restore_enrol_plugin { 35 36 /** 37 * @var array $tools Stores the IDs of the newly created tools. 38 */ 39 protected $tools = array(); 40 41 /** 42 * Declares the enrol LTI XML paths attached to the enrol element 43 * 44 * @return array of {@link restore_path_element} 45 */ 46 protected function define_enrol_plugin_structure() { 47 48 $paths = array(); 49 $paths[] = new restore_path_element('enrol_lti_tool', $this->connectionpoint->get_path() . '/tool'); 50 $paths[] = new restore_path_element('enrol_lti_users', $this->connectionpoint->get_path() . '/tool/users/user'); 51 52 return $paths; 53 } 54 55 /** 56 * Processes LTI tools element data 57 * 58 * @param array|stdClass $data 59 */ 60 public function process_enrol_lti_tool($data) { 61 global $DB; 62 63 $data = (object) $data; 64 65 // Store the old id. 66 $oldid = $data->id; 67 68 // Change the values before we insert it. 69 $data->timecreated = time(); 70 $data->timemodified = $data->timecreated; 71 72 // Now we can insert the new record. 73 $data->id = $DB->insert_record('enrol_lti_tools', $data); 74 75 // Add the array of tools we need to process later. 76 $this->tools[$data->id] = $data; 77 78 // Set up the mapping. 79 $this->set_mapping('enrol_lti_tool', $oldid, $data->id); 80 } 81 82 /** 83 * Processes LTI users element data 84 * 85 * @param array|stdClass $data The data to insert as a comment 86 */ 87 public function process_enrol_lti_users($data) { 88 global $DB; 89 90 $data = (object) $data; 91 92 $data->userid = $this->get_mappingid('user', $data->userid); 93 $data->toolid = $this->get_mappingid('enrol_lti_tool', $data->toolid); 94 $data->timecreated = time(); 95 96 $DB->insert_record('enrol_lti_users', $data); 97 } 98 99 /** 100 * This function is executed after all the tasks in the plan have been finished. 101 * This must be done here because the activities have not been restored yet. 102 */ 103 public function after_restore_enrol() { 104 global $DB; 105 106 // Need to go through and change the values. 107 foreach ($this->tools as $tool) { 108 $updatetool = new stdClass(); 109 $updatetool->id = $tool->id; 110 $updatetool->enrolid = $this->get_mappingid('enrol', $tool->enrolid); 111 $updatetool->contextid = $this->get_mappingid('context', $tool->contextid); 112 $DB->update_record('enrol_lti_tools', $updatetool); 113 } 114 } 115 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body