moodle-mod_htmlcert/backup/moodle2/backup_customcert_stepslib.php

83 lines
3.4 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 backup steps that will be used by the backup_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 backup, 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 backup_htmlcert_activity_structure_step extends backup_activity_structure_step {
/**
* Define the structure of the backup file.
*
* @return backup_nested_element
*/
protected function define_structure() {
// The instance.
$htmlcert = new backup_nested_element('htmlcert', array('id'), array(
'templateid', 'name', 'intro', 'introformat', 'requiredtime', 'verifyany', 'emailstudents',
'emailteachers', 'emailothers', 'protection', 'timecreated', 'timemodified'));
// The template.
$template = new backup_nested_element('template', array('id'), array(
'name', 'contextid', 'timecreated', 'timemodified'));
// The issues.
$issues = new backup_nested_element('issues');
$issue = new backup_nested_element('issue', array('id'), array(
'htmlcertid', 'userid', 'timecreated', 'emailed', 'code'));
// Build the tree.
$htmlcert->add_child($issues);
$issues->add_child($issue);
$htmlcert->add_child($template);
// Define sources.
$htmlcert->set_source_table('htmlcert', array('id' => backup::VAR_ACTIVITYID));
// Define template source.
$template->set_source_table('htmlcert_templates', array('contextid' => backup::VAR_CONTEXTID));
// If we are including user info then save the issues.
if ($this->get_setting_value('userinfo')) {
$issue->set_source_table('htmlcert_issues', array('htmlcertid' => backup::VAR_ACTIVITYID));
}
// Annotate the user id's where required.
$issue->annotate_ids('user', 'userid');
// Define file annotations.
$htmlcert->annotate_files('mod_htmlcert', 'intro', null);
$htmlcert->annotate_files('mod_htmlcert', 'image', null, context_course::instance($this->get_courseid())->id);
// Return the root element (htmlcert), wrapped into standard activity structure.
return $this->prepare_activity_structure($htmlcert);
}
}