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
+159
View File
@@ -0,0 +1,159 @@
<?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/>.
/**
* Provides support for the conversion of moodle1 backup to the moodle2 format
*
* @package mod_glossary
* @copyright 2011 David Mudrak <david@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Glossary conversion handler
*/
class moodle1_mod_glossary_handler extends moodle1_mod_handler {
/** @var moodle1_file_manager */
protected $fileman = null;
/** @var int cmid */
protected $moduleid = null;
/**
* Declare the paths in moodle.xml we are able to convert
*
* The method returns list of {@link convert_path} instances.
* For each path returned, the corresponding conversion method must be
* defined.
*
* Note that the path /MOODLE_BACKUP/COURSE/MODULES/MOD/GLOSSARY does not
* actually exist in the file. The last element with the module name was
* appended by the moodle1_converter class.
*
* @return array of {@link convert_path} instances
*/
public function get_paths() {
return array(
new convert_path(
'glossary', '/MOODLE_BACKUP/COURSE/MODULES/MOD/GLOSSARY',
array(
'newfields' => array(
'introformat' => FORMAT_MOODLE,
'completionentries' => 0,
),
)
),
new convert_path('glossary_categories', '/MOODLE_BACKUP/COURSE/MODULES/MOD/GLOSSARY/CATEGORIES'),
new convert_path(
'glossary_category', '/MOODLE_BACKUP/COURSE/MODULES/MOD/GLOSSARY/CATEGORIES/CATEGORY',
array(
'dropfields' => array(
'glossaryid'
)
)
)
);
}
/**
* This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/GLOSSARY
* data available
*/
public function process_glossary($data) {
global $CFG;
// get the course module id and context id
$instanceid = $data['id'];
$cminfo = $this->get_cminfo($instanceid);
$this->moduleid = $cminfo['id'];
$contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid);
// replay the upgrade step 2009042006
if ($CFG->texteditors !== 'textarea') {
$data['intro'] = text_to_html($data['intro'], false, false, true);
$data['introformat'] = FORMAT_HTML;
}
// get a fresh new file manager for this instance
$this->fileman = $this->converter->get_file_manager($contextid, 'mod_glossary');
// convert course files embedded into the intro
$this->fileman->filearea = 'intro';
$this->fileman->itemid = 0;
$data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman);
// start writing glossary.xml
$this->open_xml_writer("activities/glossary_{$this->moduleid}/glossary.xml");
$this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid,
'modulename' => 'glossary', 'contextid' => $contextid));
$this->xmlwriter->begin_tag('glossary', array('id' => $instanceid));
foreach ($data as $field => $value) {
if ($field <> 'id') {
$this->xmlwriter->full_tag($field, $value);
}
}
return $data;
}
/**
* This is executed when the parser reaches the <CATEGORIES> opening element
*/
public function on_glossary_categories_start() {
$this->xmlwriter->begin_tag('categories');
}
/**
* This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/GLOSSARY/CATEGORIES/CATEGORY
* data available
*/
public function process_glossary_category($data) {
$this->write_xml('category', $data, array('/category/id'));
}
/**
* This is executed when the parser reaches the closing </CATEGORIES> element
*/
public function on_glossary_categories_end() {
$this->xmlwriter->end_tag('categories');
}
/**
* This is executed when we reach the closing </MOD> tag of our 'glossary' path
*/
public function on_glossary_end() {
// finalize glossary.xml
$this->xmlwriter->end_tag('glossary');
$this->xmlwriter->end_tag('activity');
$this->close_xml_writer();
// write inforef.xml
$this->open_xml_writer("activities/glossary_{$this->moduleid}/inforef.xml");
$this->xmlwriter->begin_tag('inforef');
$this->xmlwriter->begin_tag('fileref');
foreach ($this->fileman->get_fileids() as $fileid) {
$this->write_xml('file', array('id' => $fileid));
}
$this->xmlwriter->end_tag('fileref');
$this->xmlwriter->end_tag('inforef');
$this->close_xml_writer();
}
}
@@ -0,0 +1,74 @@
<?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/>.
/**
* Defines backup_glossary_activity_task class
*
* @package mod_glossary
* @category backup
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/mod/glossary/backup/moodle2/backup_glossary_stepslib.php');
/**
* Provides the steps to perform one complete backup of the Glossary instance
*/
class backup_glossary_activity_task extends backup_activity_task {
/**
* No specific settings for this activity
*/
protected function define_my_settings() {
}
/**
* Defines a backup step to store the instance data in the glossary.xml file
*/
protected function define_my_steps() {
$this->add_step(new backup_glossary_activity_structure_step('glossary_structure', 'glossary.xml'));
}
/**
* Encodes URLs to the index.php and view.php scripts
*
* @param string $content some HTML text that eventually contains URLs to the activity instance scripts
* @return string the content with the URLs encoded
*/
public static function encode_content_links($content) {
global $CFG;
$base = preg_quote($CFG->wwwroot,"/");
// Link to the list of glossaries
$search="/(".$base."\/mod\/glossary\/index.php\?id\=)([0-9]+)/";
$content= preg_replace($search, '$@GLOSSARYINDEX*$2@$', $content);
// Link to glossary view by moduleid
$search="/(".$base."\/mod\/glossary\/view.php\?id\=)([0-9]+)/";
$content= preg_replace($search, '$@GLOSSARYVIEWBYID*$2@$', $content);
// Link to glossary entry
$search="/(".$base."\/mod\/glossary\/showentry.php\?courseid=)([0-9]+)(&|&amp;)eid=([0-9]+)/";
$content = preg_replace($search, '$@GLOSSARYSHOWENTRY*$2*$4@$', $content);
return $content;
}
}
@@ -0,0 +1,149 @@
<?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/>.
/**
* @package mod_glossary
* @subpackage backup-moodle2
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Define all the backup steps that will be used by the backup_glossary_activity_task
*/
/**
* Define the complete glossary structure for backup, with file and id annotations
*/
class backup_glossary_activity_structure_step extends backup_activity_structure_step {
protected function define_structure() {
// To know if we are including userinfo
$userinfo = $this->get_setting_value('userinfo');
// Define each element separated
$glossary = new backup_nested_element('glossary', array('id'), array(
'name', 'intro', 'introformat', 'allowduplicatedentries', 'displayformat',
'mainglossary', 'showspecial', 'showalphabet', 'showall',
'allowcomments', 'allowprintview', 'usedynalink', 'defaultapproval',
'globalglossary', 'entbypage', 'editalways', 'rsstype',
'rssarticles', 'assessed', 'assesstimestart', 'assesstimefinish',
'scale', 'timecreated', 'timemodified', 'completionentries'));
$entries = new backup_nested_element('entries');
$entry = new backup_nested_element('entry', array('id'), array(
'userid', 'concept', 'definition', 'definitionformat',
'definitiontrust', 'attachment', 'timecreated', 'timemodified',
'teacherentry', 'sourceglossaryid', 'usedynalink', 'casesensitive',
'fullmatch', 'approved'));
$tags = new backup_nested_element('entriestags');
$tag = new backup_nested_element('tag', array('id'), array('itemid', 'rawname'));
$aliases = new backup_nested_element('aliases');
$alias = new backup_nested_element('alias', array('id'), array(
'alias_text'));
$ratings = new backup_nested_element('ratings');
$rating = new backup_nested_element('rating', array('id'), array(
'component', 'ratingarea', 'scaleid', 'value', 'userid', 'timecreated', 'timemodified'));
$categories = new backup_nested_element('categories');
$category = new backup_nested_element('category', array('id'), array(
'name', 'usedynalink'));
$categoryentries = new backup_nested_element('category_entries');
$categoryentry = new backup_nested_element('category_entry', array('id'), array(
'entryid'));
// Build the tree
$glossary->add_child($entries);
$entries->add_child($entry);
$glossary->add_child($tags);
$tags->add_child($tag);
$entry->add_child($aliases);
$aliases->add_child($alias);
$entry->add_child($ratings);
$ratings->add_child($rating);
$glossary->add_child($categories);
$categories->add_child($category);
$category->add_child($categoryentries);
$categoryentries->add_child($categoryentry);
// Define sources
$glossary->set_source_table('glossary', array('id' => backup::VAR_ACTIVITYID));
$category->set_source_table('glossary_categories', array('glossaryid' => backup::VAR_PARENTID));
// All the rest of elements only happen if we are including user info
if ($userinfo) {
$entry->set_source_table('glossary_entries', array('glossaryid' => backup::VAR_PARENTID));
$alias->set_source_table('glossary_alias', array('entryid' => backup::VAR_PARENTID));
$alias->set_source_alias('alias', 'alias_text');
$rating->set_source_table('rating', array('contextid' => backup::VAR_CONTEXTID,
'itemid' => backup::VAR_PARENTID,
'component' => backup_helper::is_sqlparam('mod_glossary'),
'ratingarea' => backup_helper::is_sqlparam('entry')));
$rating->set_source_alias('rating', 'value');
$categoryentry->set_source_table('glossary_entries_categories', array('categoryid' => backup::VAR_PARENTID));
if (core_tag_tag::is_enabled('mod_glossary', 'glossary_entries')) {
$tag->set_source_sql('SELECT t.id, ti.itemid, t.rawname
FROM {tag} t
JOIN {tag_instance} ti ON ti.tagid = t.id
WHERE ti.itemtype = ?
AND ti.component = ?
AND ti.contextid = ?', array(
backup_helper::is_sqlparam('glossary_entries'),
backup_helper::is_sqlparam('mod_glossary'),
backup::VAR_CONTEXTID));
}
}
// Define id annotations
$glossary->annotate_ids('scale', 'scale');
$entry->annotate_ids('user', 'userid');
$rating->annotate_ids('scale', 'scaleid');
$rating->annotate_ids('user', 'userid');
// Define file annotations
$glossary->annotate_files('mod_glossary', 'intro', null); // This file area hasn't itemid
$entry->annotate_files('mod_glossary', 'entry', 'id');
$entry->annotate_files('mod_glossary', 'attachment', 'id');
// Return the root element (glossary), wrapped into standard activity structure
return $this->prepare_activity_structure($glossary);
}
}
@@ -0,0 +1,121 @@
<?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/>.
/**
* @package mod_glossary
* @subpackage backup-moodle2
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/mod/glossary/backup/moodle2/restore_glossary_stepslib.php'); // Because it exists (must)
/**
* glossary restore task that provides all the settings and steps to perform one
* complete restore of the activity
*/
class restore_glossary_activity_task extends restore_activity_task {
/**
* Define (add) particular settings this activity can have
*/
protected function define_my_settings() {
// No particular settings for this activity
}
/**
* Define (add) particular steps this activity can have
*/
protected function define_my_steps() {
// Choice only has one structure step
$this->add_step(new restore_glossary_activity_structure_step('glossary_structure', 'glossary.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('glossary', array('intro'), 'glossary');
$contents[] = new restore_decode_content('glossary_entries', array('definition'), 'glossary_entry');
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('GLOSSARYVIEWBYID', '/mod/glossary/view.php?id=$1', 'course_module');
$rules[] = new restore_decode_rule('GLOSSARYINDEX', '/mod/glossary/index.php?id=$1', 'course');
$rules[] = new restore_decode_rule('GLOSSARYSHOWENTRY', '/mod/glossary/showentry.php?courseid=$1&eid=$2',
array('course', 'glossary_entry'));
return $rules;
}
/**
* Define the restore log rules that will be applied
* by the {@link restore_logs_processor} when restoring
* glossary logs. It must return one array
* of {@link restore_log_rule} objects
*/
public static function define_restore_log_rules() {
$rules = array();
$rules[] = new restore_log_rule('glossary', 'add', 'view.php?id={course_module}', '{glossary}');
$rules[] = new restore_log_rule('glossary', 'update', 'view.php?id={course_module}', '{glossary}');
$rules[] = new restore_log_rule('glossary', 'view', 'view.php?id={course_module}', '{glossary}');
$rules[] = new restore_log_rule('glossary', 'add category', 'editcategories.php?id={course_module}', '{glossary_category}');
$rules[] = new restore_log_rule('glossary', 'edit category', 'editcategories.php?id={course_module}', '{glossary_category}');
$rules[] = new restore_log_rule('glossary', 'delete category', 'editcategories.php?id={course_module}', '{glossary_category}');
$rules[] = new restore_log_rule('glossary', 'add entry', 'view.php?id={course_module}&mode=entry&hook={glossary_entry}', '{glossary_entry}');
$rules[] = new restore_log_rule('glossary', 'update entry', 'view.php?id={course_module}&mode=entry&hook={glossary_entry}', '{glossary_entry}');
$rules[] = new restore_log_rule('glossary', 'delete entry', 'view.php?id={course_module}&mode=entry&hook={glossary_entry}', '{glossary_entry}');
$rules[] = new restore_log_rule('glossary', 'approve entry', 'showentry.php?id={course_module}&eid={glossary_entry}', '{glossary_entry}');
$rules[] = new restore_log_rule('glossary', 'disapprove entry', 'showentry.php?id={course_module}&eid={glossary_entry}', '{glossary_entry}');
$rules[] = new restore_log_rule('glossary', 'view entry', 'showentry.php?eid={glossary_entry}', '{glossary_entry}');
return $rules;
}
/**
* Define the restore log rules that will be applied
* by the {@link restore_logs_processor} when restoring
* course logs. It must return one array
* of {@link restore_log_rule} objects
*
* Note this rules are applied when restoring course logs
* by the restore final task, but are defined here at
* activity level. All them are rules not linked to any module instance (cmid = 0)
*/
public static function define_restore_log_rules_for_course() {
$rules = array();
$rules[] = new restore_log_rule('glossary', 'view all', 'index.php?id={course}', null);
return $rules;
}
}
@@ -0,0 +1,184 @@
<?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/>.
/**
* @package mod_glossary
* @subpackage backup-moodle2
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Define all the restore steps that will be used by the restore_glossary_activity_task
*/
/**
* Structure step to restore one glossary activity
*/
class restore_glossary_activity_structure_step extends restore_activity_structure_step {
protected function define_structure() {
$paths = array();
$userinfo = $this->get_setting_value('userinfo');
$paths[] = new restore_path_element('glossary', '/activity/glossary');
$paths[] = new restore_path_element('glossary_category', '/activity/glossary/categories/category');
if ($userinfo) {
$paths[] = new restore_path_element('glossary_entry', '/activity/glossary/entries/entry');
$paths[] = new restore_path_element('glossary_entry_tag', '/activity/glossary/entriestags/tag');
$paths[] = new restore_path_element('glossary_alias', '/activity/glossary/entries/entry/aliases/alias');
$paths[] = new restore_path_element('glossary_rating', '/activity/glossary/entries/entry/ratings/rating');
$paths[] = new restore_path_element('glossary_category_entry',
'/activity/glossary/categories/category/category_entries/category_entry');
}
// Return the paths wrapped into standard activity structure
return $this->prepare_activity_structure($paths);
}
protected function process_glossary($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->course = $this->get_courseid();
// Any changes to the list of dates that needs to be rolled should be same during course restore and course reset.
// See MDL-9367.
$data->assesstimestart = $this->apply_date_offset($data->assesstimestart);
$data->assesstimefinish = $this->apply_date_offset($data->assesstimefinish);
if ($data->scale < 0) { // scale found, get mapping
$data->scale = -($this->get_mappingid('scale', abs($data->scale)));
}
$formats = get_list_of_plugins('mod/glossary/formats'); // Check format
if (!in_array($data->displayformat, $formats)) {
$data->displayformat = 'dictionary';
}
if (!empty($data->globalglossary) && !has_capability('mod/glossary:manageentries', context_system::instance())) {
$data->globalglossary = 0;
}
if (!empty($data->mainglossary) and $data->mainglossary == 1 and
$DB->record_exists('glossary', array('mainglossary' => 1, 'course' => $this->get_courseid()))) {
// Only allow one main glossary in the course
$data->mainglossary = 0;
}
// insert the glossary record
$newitemid = $DB->insert_record('glossary', $data);
$this->apply_activity_instance($newitemid);
}
protected function process_glossary_entry($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->glossaryid = $this->get_new_parentid('glossary');
$data->userid = $this->get_mappingid('user', $data->userid);
$data->sourceglossaryid = $this->get_mappingid('glossary', $data->sourceglossaryid);
// insert the entry record
$newitemid = $DB->insert_record('glossary_entries', $data);
$this->set_mapping('glossary_entry', $oldid, $newitemid, true); // childs and files by itemname
}
protected function process_glossary_alias($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->entryid = $this->get_new_parentid('glossary_entry');
$data->alias = $data->alias_text;
$newitemid = $DB->insert_record('glossary_alias', $data);
}
protected function process_glossary_rating($data) {
global $DB;
$data = (object)$data;
// Cannot use ratings API, cause, it's missing the ability to specify times (modified/created)
$data->contextid = $this->task->get_contextid();
$data->itemid = $this->get_new_parentid('glossary_entry');
if ($data->scaleid < 0) { // scale found, get mapping
$data->scaleid = -($this->get_mappingid('scale', abs($data->scaleid)));
}
$data->rating = $data->value;
$data->userid = $this->get_mappingid('user', $data->userid);
// Make sure that we have both component and ratingarea set. These were added in 2.1.
// Prior to that all ratings were for entries so we know what to set them too.
if (empty($data->component)) {
$data->component = 'mod_glossary';
}
if (empty($data->ratingarea)) {
$data->ratingarea = 'entry';
}
$newitemid = $DB->insert_record('rating', $data);
}
protected function process_glossary_entry_tag($data) {
$data = (object)$data;
if (!core_tag_tag::is_enabled('mod_glossary', 'glossary_entries')) { // Tags disabled in server, nothing to process.
return;
}
$tag = $data->rawname;
if (!$itemid = $this->get_mappingid('glossary_entry', $data->itemid)) {
// Some orphaned tag, we could not find the glossary entry for it - ignore.
return;
}
$context = context_module::instance($this->task->get_moduleid());
core_tag_tag::add_item_tag('mod_glossary', 'glossary_entries', $itemid, $context, $tag);
}
protected function process_glossary_category($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->glossaryid = $this->get_new_parentid('glossary');
$newitemid = $DB->insert_record('glossary_categories', $data);
$this->set_mapping('glossary_category', $oldid, $newitemid);
}
protected function process_glossary_category_entry($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->categoryid = $this->get_new_parentid('glossary_category');
$data->entryid = $this->get_mappingid('glossary_entry', $data->entryid);
$newitemid = $DB->insert_record('glossary_entries_categories', $data);
}
protected function after_execute() {
// Add glossary related files, no need to match by itemname (just internally handled context)
$this->add_related_files('mod_glossary', 'intro', null);
// Add entries related files, matching by itemname (glossary_entry)
$this->add_related_files('mod_glossary', 'entry', 'glossary_entry');
$this->add_related_files('mod_glossary', 'attachment', 'glossary_entry');
}
}