first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
@@ -0,0 +1,70 @@
<?php
// This file is part of 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/>.
/**
* The task that provides all the steps to perform a complete backup is defined here.
*
* @package mod_h5pactivity
* @category backup
* @copyright 2020 Ferran Recio <ferran@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot.'/mod/h5pactivity/backup/moodle2/backup_h5pactivity_stepslib.php');
/**
* The class provides all the settings and steps to perform one complete backup of mod_h5pactivity.
*/
class backup_h5pactivity_activity_task extends backup_activity_task {
/**
* Defines particular settings for the plugin.
*/
protected function define_my_settings() {
return;
}
/**
* Defines particular steps for the backup process.
*/
protected function define_my_steps() {
$this->add_step(new backup_h5pactivity_activity_structure_step('h5pactivity_structure', 'h5pactivity.xml'));
}
/**
* Codes the transformations to perform in the activity in order to get transportable (encoded) links.
*
* @param string $content content to encode.
* @return string encoded string
*/
public static function encode_content_links($content) {
global $CFG;
$base = preg_quote($CFG->wwwroot, "/");
// Link to the list of choices.
$search = "/(".$base."\/mod\/h5pactivity\/index.php\?id\=)([0-9]+)/";
$content = preg_replace($search, '$@H5PACTIVITYINDEX*$2@$', $content);
// Link to choice view by moduleid.
$search = "/(".$base."\/mod\/h5pactivity\/view.php\?id\=)([0-9]+)/";
$content = preg_replace($search, '$@H5PACTIVITYVIEWBYID*$2@$', $content);
return $content;
}
}
@@ -0,0 +1,88 @@
<?php
// This file is part of 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/>.
/**
* Backup steps for mod_h5pactivity are defined here.
*
* @package mod_h5pactivity
* @category backup
* @copyright 2020 Ferran Recio <ferran@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Define the complete structure for backup, with file and id annotations.
*/
class backup_h5pactivity_activity_structure_step extends backup_activity_structure_step {
/**
* Defines the structure of the resulting xml file.
*
* @return backup_nested_element The structure wrapped by the common 'activity' element.
*/
protected function define_structure() {
$userinfo = $this->get_setting_value('userinfo');
// Replace with the attributes and final elements that the element will handle.
$attributes = ['id'];
$finalelements = ['name', 'timecreated', 'timemodified', 'intro',
'introformat', 'grade', 'displayoptions', 'enabletracking', 'grademethod', 'reviewmode'];
$root = new backup_nested_element('h5pactivity', $attributes, $finalelements);
$attempts = new backup_nested_element('attempts');
$attempt = new backup_nested_element('attempt', ['id'],
['h5pactivityid', 'userid', 'timecreated', 'timemodified', 'attempt', 'rawscore', 'maxscore',
'duration', 'completion', 'success', 'scaled']
);
$results = new backup_nested_element('results');
$result = new backup_nested_element('result', ['id'],
[
'attemptid', 'subcontent', 'timecreated', 'interactiontype', 'description',
'correctpattern', 'response', 'additionals', 'rawscore', 'maxscore',
'duration', 'completion', 'success'
]
);
// Build the tree.
$root->add_child($attempts);
$attempts->add_child($attempt);
$attempt->add_child($results);
$results->add_child($result);
// Define the source tables for the elements.
$root->set_source_table('h5pactivity', ['id' => backup::VAR_ACTIVITYID]);
// All the rest of elements only happen if we are including user info.
if ($userinfo) {
$attempt->set_source_table('h5pactivity_attempts', ['h5pactivityid' => backup::VAR_PARENTID], 'id ASC');
$result->set_source_table('h5pactivity_attempts_results', ['attemptid' => backup::VAR_PARENTID], 'id ASC');
}
// Define id annotations.
$attempt->annotate_ids('user', 'userid');
// Define file annotations.
$root->annotate_files('mod_h5pactivity', 'intro', null); // This file area hasn't itemid.
$root->annotate_files('mod_h5pactivity', 'package', null); // This file area hasn't itemid.
return $this->prepare_activity_structure($root);
}
}
@@ -0,0 +1,93 @@
<?php
// This file is part of 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/>.
/**
* The task that provides a complete restore of mod_h5pactivity is defined here.
*
* @package mod_h5pactivity
* @copyright 2020 Ferran Recio <ferran@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot.'/mod/h5pactivity/backup/moodle2/restore_h5pactivity_stepslib.php');
/**
* Restore task for mod_h5pactivity.
*/
class restore_h5pactivity_activity_task extends restore_activity_task {
/**
* Defines particular settings that this activity can have.
*/
protected function define_my_settings(): void {
return;
}
/**
* Defines particular steps that this activity can have.
*
* @return base_step.
*/
protected function define_my_steps(): void {
$this->add_step(new restore_h5pactivity_activity_structure_step('h5pactivity_structure', 'h5pactivity.xml'));
}
/**
* Defines the contents in the activity that must be processed by the link decoder.
*
* @return array.
*/
public static function define_decode_contents(): array {
$contents = [];
// Define the contents.
$contents[] = new restore_decode_content('h5pactivity', ['intro'], 'h5pactivity');
return $contents;
}
/**
* Defines the decoding rules for links belonging to the activity to be executed by the link decoder.
*
* @return restore_decode_rule[].
*/
public static function define_decode_rules(): array {
$rules = [];
$rules[] = new restore_decode_rule('H5PACTIVITYVIEWBYID', '/mod/h5pactivity/view.php?id=$1', 'course_module');
$rules[] = new restore_decode_rule('H5PACTIVITYINDEX', '/mod/h5pactivity/index.php?id=$1', 'course');
return $rules;
}
/**
* Defines the restore log rules that will be applied by the
* {@link restore_logs_processor} when restoring mod_h5pactivity logs. It
* must return one array of {@link restore_log_rule} objects.
*
* @return restore_log_rule[].
*/
public static function define_restore_log_rules(): array {
$rules = [];
// Define the rules.
$rules[] = new restore_log_rule('h5pactivity', 'view all', 'index.php?id={course}', null);
return $rules;
}
}
@@ -0,0 +1,104 @@
<?php
// This file is part of 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/>.
/**
* All the steps to restore mod_h5pactivity are defined here.
*
* @package mod_h5pactivity
* @copyright 2020 Ferran Recio <ferran@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Defines the structure step to restore one mod_h5pactivity activity.
*/
class restore_h5pactivity_activity_structure_step extends restore_activity_structure_step {
/**
* Defines the structure to be restored.
*
* @return restore_path_element[].
*/
protected function define_structure(): array {
$paths = [];
$userinfo = $this->get_setting_value('userinfo');
$paths[] = new restore_path_element('h5pactivity', '/activity/h5pactivity');
if ($userinfo) {
$paths[] = new restore_path_element('h5pactivity_attempt', '/activity/h5pactivity/attempts/attempt');
$paths[] = new restore_path_element('h5pactivity_attempt_result', '/activity/h5pactivity/attempts/attempt/results/result');
}
return $this->prepare_activity_structure($paths);
}
/**
* Processes the h5pactivity restore data.
*
* @param array $data Parsed element data.
*/
protected function process_h5pactivity(array $data): void {
global $DB;
$data = (object)$data;
$data->course = $this->get_courseid();
// Insert the record.
$newitemid = $DB->insert_record('h5pactivity', $data);
// Immediately after inserting "activity" record, call this.
$this->apply_activity_instance($newitemid);
}
/**
* Processes the h5pactivity_attempts restore data.
*
* @param array $data Parsed element data.
*/
protected function process_h5pactivity_attempt(array $data): void {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->h5pactivityid = $this->get_new_parentid('h5pactivity');
$data->userid = $this->get_mappingid('user', $data->userid);
$newitemid = $DB->insert_record('h5pactivity_attempts', $data);
$this->set_mapping('h5pactivity_attempt', $oldid, $newitemid);
}
/**
* Processes the h5pactivity_attempts_results restore data.
*
* @param array $data Parsed element data.
*/
protected function process_h5pactivity_attempt_result(array $data): void {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->attemptid = $this->get_new_parentid('h5pactivity_attempt');
$newitemid = $DB->insert_record('h5pactivity_attempts_results', $data);
$this->set_mapping('h5pactivity_attempt_result', $oldid, $newitemid);
}
/**
* Defines post-execution actions.
*/
protected function after_execute(): void {
// Add related files, no need to match by itemname (just internally handled context).
$this->add_related_files('mod_h5pactivity', 'intro', null);
$this->add_related_files('mod_h5pactivity', 'package', null);
}
}