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,83 @@
<?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/>.
/**
* Description of book backup task
*
* @package mod_book
* @copyright 2010-2011 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
require_once($CFG->dirroot.'/mod/book/backup/moodle2/backup_book_stepslib.php'); // Because it exists (must)
require_once($CFG->dirroot.'/mod/book/backup/moodle2/backup_book_settingslib.php'); // Because it exists (optional)
class backup_book_activity_task extends backup_activity_task {
/**
* Define (add) particular settings this activity can have
*
* @return void
*/
protected function define_my_settings() {
// No particular settings for this activity
}
/**
* Define (add) particular steps this activity can have
*
* @return void
*/
protected function define_my_steps() {
// book only has one structure step
$this->add_step(new backup_book_activity_structure_step('book_structure', 'book.xml'));
}
/**
* Code the transformations to perform in the activity in
* order to get transportable (encoded) links
*
* @param string $content
* @return string encoded content
*/
public static function encode_content_links($content) {
global $CFG;
$base = preg_quote($CFG->wwwroot, "/");
// Link to the list of books
$search = "/($base\/mod\/book\/index.php\?id=)([0-9]+)/";
$content = preg_replace($search, '$@BOOKINDEX*$2@$', $content);
// Link to book view by moduleid
$search = "/($base\/mod\/book\/view.php\?id=)([0-9]+)(&|&amp;)chapterid=([0-9]+)/";
$content = preg_replace($search, '$@BOOKVIEWBYIDCH*$2*$4@$', $content);
$search = "/($base\/mod\/book\/view.php\?id=)([0-9]+)/";
$content = preg_replace($search, '$@BOOKVIEWBYID*$2@$', $content);
// Link to book view by bookid
$search = "/($base\/mod\/book\/view.php\?b=)([0-9]+)(&|&amp;)chapterid=([0-9]+)/";
$content = preg_replace($search, '$@BOOKVIEWBYBCH*$2*$4@$', $content);
$search = "/($base\/mod\/book\/view.php\?b=)([0-9]+)/";
$content = preg_replace($search, '$@BOOKVIEWBYB*$2@$', $content);
return $content;
}
}
@@ -0,0 +1,29 @@
<?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/>.
/**
* Description of book backup settings
*
* @package mod_book
* @copyright 2010 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
// This activity has not particular settings but the inherited from the generic
// backup_activity_task so here there isn't any class definition, like the ones
// existing in /backup/moodle2/backup_settingslib.php (activities section)
@@ -0,0 +1,76 @@
<?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/>.
/**
* Define all the backup steps that will be used by the backup_book_activity_task
*
* @package mod_book
* @copyright 2010 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
/**
* Structure step to backup one book activity
*/
class backup_book_activity_structure_step extends backup_activity_structure_step {
protected function define_structure() {
// Define each element separated.
$book = new backup_nested_element('book', array('id'), array(
'name', 'intro', 'introformat', 'numbering', 'navstyle',
'customtitles', 'timecreated', 'timemodified'));
$chapters = new backup_nested_element('chapters');
$chapter = new backup_nested_element('chapter', array('id'), array(
'pagenum', 'subchapter', 'title', 'content', 'contentformat',
'hidden', 'timemcreated', 'timemodified', 'importsrc'));
$tags = new backup_nested_element('chaptertags');
$tag = new backup_nested_element('tag', array('id'), array('itemid', 'rawname'));
$book->add_child($chapters);
$chapters->add_child($chapter);
// Define sources
$book->set_source_table('book', array('id' => backup::VAR_ACTIVITYID));
$chapter->set_source_table('book_chapters', array('bookid' => backup::VAR_PARENTID));
// Define file annotations
$book->annotate_files('mod_book', 'intro', null); // This file area hasn't itemid
$chapter->annotate_files('mod_book', 'chapter', 'id');
$book->add_child($tags);
$tags->add_child($tag);
// All these source definitions only happen if we are including user info.
if (core_tag_tag::is_enabled('mod_book', 'book_chapters')) {
$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('book_chapters'),
backup_helper::is_sqlparam('mod_book'),
backup::VAR_CONTEXTID));
}
// Return the root element (book), wrapped into standard activity structure
return $this->prepare_activity_structure($book);
}
}
@@ -0,0 +1,141 @@
<?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/>.
/**
* Description of book restore task
*
* @package mod_book
* @copyright 2010 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/mod/book/backup/moodle2/restore_book_stepslib.php'); // Because it exists (must)
class restore_book_activity_task extends restore_activity_task {
/**
* Define (add) particular settings this activity can have
*
* @return void
*/
protected function define_my_settings() {
// No particular settings for this activity
}
/**
* Define (add) particular steps this activity can have
*
* @return void
*/
protected function define_my_steps() {
// Choice only has one structure step
$this->add_step(new restore_book_activity_structure_step('book_structure', 'book.xml'));
}
/**
* Define the contents in the activity that must be
* processed by the link decoder
*
* @return array
*/
public static function define_decode_contents() {
$contents = array();
$contents[] = new restore_decode_content('book', array('intro'), 'book');
$contents[] = new restore_decode_content('book_chapters', array('content'), 'book_chapter');
return $contents;
}
/**
* Define the decoding rules for links belonging
* to the activity to be executed by the link decoder
*
* @return array
*/
public static function define_decode_rules() {
$rules = array();
// List of books in course
$rules[] = new restore_decode_rule('BOOKINDEX', '/mod/book/index.php?id=$1', 'course');
// book by cm->id
$rules[] = new restore_decode_rule('BOOKVIEWBYID', '/mod/book/view.php?id=$1', 'course_module');
$rules[] = new restore_decode_rule('BOOKVIEWBYIDCH', '/mod/book/view.php?id=$1&amp;chapterid=$2', array('course_module', 'book_chapter'));
// book by book->id
$rules[] = new restore_decode_rule('BOOKVIEWBYB', '/mod/book/view.php?b=$1', 'book');
$rules[] = new restore_decode_rule('BOOKVIEWBYBCH', '/mod/book/view.php?b=$1&amp;chapterid=$2', array('book', 'book_chapter'));
// Convert old book links MDL-33362 & MDL-35007
$rules[] = new restore_decode_rule('BOOKSTART', '/mod/book/view.php?id=$1', 'course_module');
$rules[] = new restore_decode_rule('BOOKCHAPTER', '/mod/book/view.php?id=$1&amp;chapterid=$2', array('course_module', 'book_chapter'));
return $rules;
}
/**
* Define the restore log rules that will be applied
* by the {@link restore_logs_processor} when restoring
* book logs. It must return one array
* of {@link restore_log_rule} objects
*
* @return array
*/
public static function define_restore_log_rules() {
$rules = array();
$rules[] = new restore_log_rule('book', 'add', 'view.php?id={course_module}', '{book}');
$rules[] = new restore_log_rule('book', 'update', 'view.php?id={course_module}&chapterid={book_chapter}', '{book}');
$rules[] = new restore_log_rule('book', 'update', 'view.php?id={course_module}', '{book}');
$rules[] = new restore_log_rule('book', 'view', 'view.php?id={course_module}&chapterid={book_chapter}', '{book}');
$rules[] = new restore_log_rule('book', 'view', 'view.php?id={course_module}', '{book}');
$rules[] = new restore_log_rule('book', 'print', 'tool/print/index.php?id={course_module}&chapterid={book_chapter}', '{book}');
$rules[] = new restore_log_rule('book', 'print', 'tool/print/index.php?id={course_module}', '{book}');
$rules[] = new restore_log_rule('book', 'exportimscp', 'tool/exportimscp/index.php?id={course_module}', '{book}');
// To convert old 'generateimscp' log entries
$rules[] = new restore_log_rule('book', 'generateimscp', 'tool/generateimscp/index.php?id={course_module}', '{book}',
'book', 'exportimscp', 'tool/exportimscp/index.php?id={course_module}', '{book}');
$rules[] = new restore_log_rule('book', 'print chapter', 'tool/print/index.php?id={course_module}&chapterid={book_chapter}', '{book_chapter}');
$rules[] = new restore_log_rule('book', 'update chapter', 'view.php?id={course_module}&chapterid={book_chapter}', '{book_chapter}');
$rules[] = new restore_log_rule('book', 'add chapter', 'view.php?id={course_module}&chapterid={book_chapter}', '{book_chapter}');
$rules[] = new restore_log_rule('book', 'view chapter', 'view.php?id={course_module}&chapterid={book_chapter}', '{book_chapter}');
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)
*
* @return array
*/
public static function define_restore_log_rules_for_course() {
$rules = array();
$rules[] = new restore_log_rule('book', 'view all', 'index.php?id={course}', null);
return $rules;
}
}
@@ -0,0 +1,102 @@
<?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/>.
/**
* Define all the restore steps that will be used by the restore_book_activity_task
*
* @package mod_book
* @copyright 2010 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
/**
* Structure step to restore one book activity
*/
class restore_book_activity_structure_step extends restore_activity_structure_step {
protected function define_structure() {
$paths = array();
$paths[] = new restore_path_element('book', '/activity/book');
$paths[] = new restore_path_element('book_chapter', '/activity/book/chapters/chapter');
$paths[] = new restore_path_element('book_chapter_tag', '/activity/book/chaptertags/tag');
// Return the paths wrapped into standard activity structure
return $this->prepare_activity_structure($paths);
}
/**
* Process book tag information
* @param array $data information
*/
protected function process_book($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.
$newitemid = $DB->insert_record('book', $data);
$this->apply_activity_instance($newitemid);
}
/**
* Process chapter tag information
* @param array $data information
*/
protected function process_book_chapter($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->course = $this->get_courseid();
$data->bookid = $this->get_new_parentid('book');
$newitemid = $DB->insert_record('book_chapters', $data);
$this->set_mapping('book_chapter', $oldid, $newitemid, true);
}
protected function process_book_chapter_tag($data) {
$data = (object)$data;
if (!core_tag_tag::is_enabled('mod_book', 'book_chapters')) { // Tags disabled in server, nothing to process.
return;
}
$tag = $data->rawname;
if (!$itemid = $this->get_mappingid('book_chapter', $data->itemid)) {
return;
}
$context = context_module::instance($this->task->get_moduleid());
core_tag_tag::add_item_tag('mod_book', 'book_chapters', $itemid, $context, $tag);
}
protected function after_execute() {
global $DB;
// Add book related files
$this->add_related_files('mod_book', 'intro', null);
$this->add_related_files('mod_book', 'chapter', 'book_chapter');
}
}