This commit is contained in:
Kumi 2021-11-30 11:20:49 +01:00
parent 7a1c175441
commit 91a7a7884b
6 changed files with 299 additions and 1 deletions

View file

@ -0,0 +1,70 @@
<?php
// This file is part of the expcontent 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/>.
/**
* This file contains the backup tasks that provides all the settings and steps to perform a backup of the activity.
*
* @package mod_expcontent
* @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.');
require_once($CFG->dirroot . '/mod/expcontent/backup/moodle2/backup_expcontent_stepslib.php');
/**
* Handles creating tasks to peform in order to create the backup.
*
* @package mod_expcontent
* @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_expcontent_activity_task extends backup_activity_task {
/**
* Define particular settings this activity can have.
*/
protected function define_my_settings() {
// No particular settings for this activity.
}
/**
* Define particular steps this activity can have.
*/
protected function define_my_steps() {
// The expcontent only has one structure step.
$this->add_step(new backup_expcontent_activity_structure_step('expcontent_structure', 'expcontent.xml'));
}
/**
* Code the transformations to perform in the activity in order to get transportable (encoded) links.
*
* @param string $content
* @return mixed|string
*/
public static function encode_content_links($content) {
global $CFG;
$base = preg_quote($CFG->wwwroot, "/");
// Link to expcontent view by moduleid.
$search = "/(".$base."\/mod\/expcontent\/view.php\?id\=)([0-9]+)/";
$content = preg_replace($search, '$@EXPCONTENTVIEWBYID*$2@$', $content);
return $content;
}
}

View file

@ -0,0 +1,53 @@
<?php
// This file is part of the expcontent 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_expcontent_activity_task.
*
* @package mod_expcontent
* @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 expcontent structure for backup, with file and id annotations.
*
* @package mod_expcontent
* @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_expcontent_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.
$expcontent = new backup_nested_element('expcontent', array('id'), array(
'name', 'contentid', 'intro', 'introformat'));
// Define sources.
$expcontent->set_source_table('expcontent', array('id' => backup::VAR_ACTIVITYID));
// Return the root element (expcontent), wrapped into standard activity structure.
return $this->prepare_activity_structure($expcontent);
}
}

View file

@ -0,0 +1,101 @@
<?php
// This file is part of the expcontent 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_expcontent_activity_task.
*
* @package mod_expcontent
* @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.');
require_once($CFG->dirroot . '/mod/expcontent/backup/moodle2/restore_expcontent_stepslib.php');
/**
* The class definition for assigning tasks that provide the settings and steps to perform a restore of the activity.
*
* @package mod_expcontent
* @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_expcontent_activity_task extends restore_activity_task {
/**
* Define particular settings this activity can have.
*/
protected function define_my_settings() {
// No particular settings for this activity.
}
/**
* Define particular steps this activity can have.
*/
protected function define_my_steps() {
// The expcontent only has one structure step.
$this->add_step(new restore_expcontent_activity_structure_step('expcontent_structure', 'expcontent.xml'));
}
/**
* Define the contents in the activity that must be processed by the link decoder.
*/
public static function define_decode_contents() {
$contents = array();
$contents[] = new restore_decode_content('expcontent', array('intro'), 'expcontent');
return $contents;
}
/**
* Define the decoding rules for links belonging to the activity to be executed by the link decoder.
*/
public static function define_decode_rules() {
$rules = array();
$rules[] = new restore_decode_rule('EXPCONTENTVIEWBYID', '/mod/expcontent/view.php?id=$1', 'course_module');
return $rules;
}
/**
* Define the restore log rules that will be applied by the {@see restore_logs_processor} when restoring
* expcontent logs. It must return one array of {@see restore_log_rule} objects.
*
* @return array the restore log rules
*/
public static function define_restore_log_rules() {
$rules = array();
$rules[] = new restore_log_rule('expcontent', 'add', 'view.php?id={course_module}', '{expcontent}');
$rules[] = new restore_log_rule('expcontent', 'update', 'view.php?id={course_module}', '{expcontent}');
$rules[] = new restore_log_rule('expcontent', 'view', 'view.php?id={course_module}', '{expcontent}');
$rules[] = new restore_log_rule('expcontent', 'view report', 'view.php?id={course_module}', '{expcontent}');
return $rules;
}
/**
* This function is called after all the activities in the backup have been restored. This allows us to get
* the new course module ids, as they may have been restored after the expcontent module, meaning no id
* was available at the time.
*/
public function after_restore() {
global $DB;
}
}

View file

@ -0,0 +1,73 @@
<?php
// This file is part of the expcontent 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_expcontent_activity_task.
*
* @package mod_expcontent
* @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 expcontent structure for restore, with file and id annotations.
*
* @package mod_expcontent
* @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_expcontent_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('expcontent', '/activity/expcontent');
// 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_expcontent($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);
$data->usermodified = $USER->id;
// Insert the htmlcert record.
$newitemid = $DB->insert_record('expcontent', $data);
// Immediately after inserting record call this.
$this->apply_activity_instance($newitemid);
}
}

View file

@ -42,6 +42,7 @@ function expcontent_supports($feature) {
switch($feature) { switch($feature) {
case FEATURE_COMPLETION_TRACKS_VIEWS: return true; case FEATURE_COMPLETION_TRACKS_VIEWS: return true;
case FEATRUE_SHOW_COMPLETION: return true; case FEATRUE_SHOW_COMPLETION: return true;
case FEATURE_BACKUP_MOODLE2: return true;
default: return null; default: return null;
} }
} }

View file

@ -2,7 +2,7 @@
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
$plugin->version = "2021113000"; $plugin->version = "2021113001";
$plugin->component = 'mod_expcontent'; $plugin->component = 'mod_expcontent';
$plugin->maturity = MATURITY_ALPHA; $plugin->maturity = MATURITY_ALPHA;
$plugin->release = 'v0.0.1'; $plugin->release = 'v0.0.1';