2013-07-23 05:21:54 +00:00
|
|
|
<?php
|
2021-11-24 07:29:43 +00:00
|
|
|
// This file is part of the htmlcert module for Moodle - http://moodle.org/
|
2013-07-23 05:21:54 +00:00
|
|
|
//
|
|
|
|
// 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/>.
|
|
|
|
|
|
|
|
/**
|
2021-11-24 07:29:43 +00:00
|
|
|
* Define all the restore steps that will be used by the restore_htmlcert_activity_task.
|
2013-07-23 05:21:54 +00:00
|
|
|
*
|
2021-11-24 07:29:43 +00:00
|
|
|
* @package mod_htmlcert
|
|
|
|
* @copyright 2013 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
2013-07-23 05:21:54 +00:00
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
|
|
|
|
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
|
|
|
|
|
|
|
/**
|
2021-11-24 07:29:43 +00:00
|
|
|
* Define the complete htmlcert structure for restore, with file and id annotations.
|
2017-02-16 12:12:19 +00:00
|
|
|
*
|
2021-11-24 07:29:43 +00:00
|
|
|
* @package mod_htmlcert
|
|
|
|
* @copyright 2013 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
|
2017-02-16 12:12:19 +00:00
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
2013-07-23 05:21:54 +00:00
|
|
|
*/
|
2021-11-24 07:29:43 +00:00
|
|
|
class restore_htmlcert_activity_structure_step extends restore_activity_structure_step {
|
2013-07-23 05:21:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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();
|
|
|
|
|
2021-11-24 07:29:43 +00:00
|
|
|
// The htmlcert instance.
|
|
|
|
$paths[] = new restore_path_element('htmlcert', '/activity/htmlcert');
|
2013-07-23 05:21:54 +00:00
|
|
|
|
2016-04-05 07:52:43 +00:00
|
|
|
// The templates.
|
2021-11-24 07:29:43 +00:00
|
|
|
$paths[] = new restore_path_element('htmlcert_template', '/activity/htmlcert/template');
|
2013-07-23 05:21:54 +00:00
|
|
|
|
|
|
|
// Check if we want the issues as well.
|
|
|
|
if ($this->get_setting_value('userinfo')) {
|
2021-11-24 07:29:43 +00:00
|
|
|
$paths[] = new restore_path_element('htmlcert_issue', '/activity/htmlcert/issues/issue');
|
2013-07-23 05:21:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return the paths wrapped into standard activity structure.
|
|
|
|
return $this->prepare_activity_structure($paths);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-24 07:29:43 +00:00
|
|
|
* Handles restoring the htmlcert activity.
|
2013-07-23 05:21:54 +00:00
|
|
|
*
|
2021-11-24 07:29:43 +00:00
|
|
|
* @param stdClass $data the htmlcert data
|
2013-07-23 05:21:54 +00:00
|
|
|
*/
|
2021-11-24 07:29:43 +00:00
|
|
|
protected function process_htmlcert($data) {
|
2013-07-23 05:21:54 +00:00
|
|
|
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);
|
|
|
|
|
2021-11-24 07:29:43 +00:00
|
|
|
// Insert the htmlcert record.
|
|
|
|
$newitemid = $DB->insert_record('htmlcert', $data);
|
2013-07-23 05:21:54 +00:00
|
|
|
|
|
|
|
// Immediately after inserting record call this.
|
|
|
|
$this->apply_activity_instance($newitemid);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-24 07:29:43 +00:00
|
|
|
* Handles restoring a htmlcert templage.
|
2013-07-23 05:21:54 +00:00
|
|
|
*
|
2021-11-24 07:29:43 +00:00
|
|
|
* @param stdClass $data the htmlcert data
|
2016-04-05 07:52:43 +00:00
|
|
|
*/
|
2021-11-24 07:29:43 +00:00
|
|
|
protected function process_htmlcert_template($data) {
|
2016-04-05 07:52:43 +00:00
|
|
|
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);
|
|
|
|
|
2021-11-24 07:29:43 +00:00
|
|
|
$newitemid = $DB->insert_record('htmlcert_templates', $data);
|
|
|
|
$this->set_mapping('htmlcert_template', $oldid, $newitemid);
|
2013-07-23 05:21:54 +00:00
|
|
|
|
2021-11-24 07:29:43 +00:00
|
|
|
// 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);
|
2013-07-23 05:21:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-11-24 07:29:43 +00:00
|
|
|
* Handles restoring a htmlcert issue.
|
2013-07-23 05:21:54 +00:00
|
|
|
*
|
2021-11-24 07:29:43 +00:00
|
|
|
* @param stdClass $data the htmlcert data
|
2013-07-23 05:21:54 +00:00
|
|
|
*/
|
2021-11-24 07:29:43 +00:00
|
|
|
protected function process_htmlcert_issue($data) {
|
2013-07-23 05:21:54 +00:00
|
|
|
global $DB;
|
|
|
|
|
|
|
|
$data = (object) $data;
|
|
|
|
$oldid = $data->id;
|
|
|
|
|
2021-11-24 07:29:43 +00:00
|
|
|
$data->htmlcertid = $this->get_new_parentid('htmlcert');
|
2013-07-23 05:21:54 +00:00
|
|
|
$data->timecreated = $this->apply_date_offset($data->timecreated);
|
2021-08-06 02:31:04 +00:00
|
|
|
$data->userid = $this->get_mappingid('user', $data->userid);
|
2013-07-23 05:21:54 +00:00
|
|
|
|
2021-11-24 07:29:43 +00:00
|
|
|
$newitemid = $DB->insert_record('htmlcert_issues', $data);
|
|
|
|
$this->set_mapping('htmlcert_issue', $oldid, $newitemid);
|
2013-07-23 05:21:54 +00:00
|
|
|
}
|
2017-04-27 13:54:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called immediately after all the other restore functions.
|
|
|
|
*/
|
|
|
|
protected function after_execute() {
|
|
|
|
parent::after_execute();
|
|
|
|
|
|
|
|
// Add the files.
|
2021-11-24 07:29:43 +00:00
|
|
|
$this->add_related_files('mod_htmlcert', 'intro', null);
|
2017-04-27 13:54:10 +00:00
|
|
|
|
|
|
|
// Note - we can't use get_old_contextid() as it refers to the module context.
|
2021-11-24 07:29:43 +00:00
|
|
|
$this->add_related_files('mod_htmlcert', 'image', null, $this->get_task()->get_info()->original_course_contextid);
|
2017-04-27 13:54:10 +00:00
|
|
|
}
|
2013-07-23 05:21:54 +00:00
|
|
|
}
|