136 lines
4.8 KiB
PHP
136 lines
4.8 KiB
PHP
<?php
|
|
// This file is part of the htmlcert module for Moodle - http://moodle.org/
|
|
//
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
/**
|
|
* Define all the restore steps that will be used by the restore_htmlcert_activity_task.
|
|
*
|
|
* @package mod_htmlcert
|
|
* @copyright 2013 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
*/
|
|
|
|
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
|
|
|
/**
|
|
* Define the complete htmlcert structure for restore, with file and id annotations.
|
|
*
|
|
* @package mod_htmlcert
|
|
* @copyright 2013 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
*/
|
|
class restore_htmlcert_activity_structure_step extends restore_activity_structure_step {
|
|
|
|
/**
|
|
* Define the different items to restore.
|
|
*
|
|
* @return array the restore paths
|
|
*/
|
|
protected function define_structure() {
|
|
// The array used to store the path to the items we want to restore.
|
|
$paths = array();
|
|
|
|
// The htmlcert instance.
|
|
$paths[] = new restore_path_element('htmlcert', '/activity/htmlcert');
|
|
|
|
// The templates.
|
|
$paths[] = new restore_path_element('htmlcert_template', '/activity/htmlcert/template');
|
|
|
|
// Check if we want the issues as well.
|
|
if ($this->get_setting_value('userinfo')) {
|
|
$paths[] = new restore_path_element('htmlcert_issue', '/activity/htmlcert/issues/issue');
|
|
}
|
|
|
|
// Return the paths wrapped into standard activity structure.
|
|
return $this->prepare_activity_structure($paths);
|
|
}
|
|
|
|
/**
|
|
* Handles restoring the htmlcert activity.
|
|
*
|
|
* @param stdClass $data the htmlcert data
|
|
*/
|
|
protected function process_htmlcert($data) {
|
|
global $DB;
|
|
|
|
$data = (object) $data;
|
|
$data->course = $this->get_courseid();
|
|
$data->timecreated = $this->apply_date_offset($data->timecreated);
|
|
$data->timemodified = $this->apply_date_offset($data->timemodified);
|
|
|
|
// Insert the htmlcert record.
|
|
$newitemid = $DB->insert_record('htmlcert', $data);
|
|
|
|
// Immediately after inserting record call this.
|
|
$this->apply_activity_instance($newitemid);
|
|
}
|
|
|
|
/**
|
|
* Handles restoring a htmlcert templage.
|
|
*
|
|
* @param stdClass $data the htmlcert data
|
|
*/
|
|
protected function process_htmlcert_template($data) {
|
|
global $DB;
|
|
|
|
$data = (object) $data;
|
|
$oldid = $data->id;
|
|
|
|
$data->contextid = $this->task->get_contextid();
|
|
$data->timecreated = $this->apply_date_offset($data->timecreated);
|
|
$data->timemodified = $this->apply_date_offset($data->timemodified);
|
|
|
|
$newitemid = $DB->insert_record('htmlcert_templates', $data);
|
|
$this->set_mapping('htmlcert_template', $oldid, $newitemid);
|
|
|
|
// Update the template id for the htmlcert.
|
|
$htmlcert = new stdClass();
|
|
$htmlcert->id = $this->get_new_parentid('htmlcert');
|
|
$htmlcert->templateid = $newitemid;
|
|
$DB->update_record('htmlcert', $htmlcert);
|
|
}
|
|
|
|
/**
|
|
* Handles restoring a htmlcert issue.
|
|
*
|
|
* @param stdClass $data the htmlcert data
|
|
*/
|
|
protected function process_htmlcert_issue($data) {
|
|
global $DB;
|
|
|
|
$data = (object) $data;
|
|
$oldid = $data->id;
|
|
|
|
$data->htmlcertid = $this->get_new_parentid('htmlcert');
|
|
$data->timecreated = $this->apply_date_offset($data->timecreated);
|
|
$data->userid = $this->get_mappingid('user', $data->userid);
|
|
|
|
$newitemid = $DB->insert_record('htmlcert_issues', $data);
|
|
$this->set_mapping('htmlcert_issue', $oldid, $newitemid);
|
|
}
|
|
|
|
/**
|
|
* Called immediately after all the other restore functions.
|
|
*/
|
|
protected function after_execute() {
|
|
parent::after_execute();
|
|
|
|
// Add the files.
|
|
$this->add_related_files('mod_htmlcert', 'intro', null);
|
|
|
|
// Note - we can't use get_old_contextid() as it refers to the module context.
|
|
$this->add_related_files('mod_htmlcert', 'image', null, $this->get_task()->get_info()->original_course_contextid);
|
|
}
|
|
}
|