forked from jhoopes/moodle-mod_activequiz
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from KQMATH/backup
Backup and restore added
- Loading branch information
Showing
10 changed files
with
440 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?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/>. | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
require_once($CFG->dirroot . '/mod/jazzquiz/backup/moodle2/backup_jazzquiz_stepslib.php'); | ||
|
||
/** | ||
* Backup task that provides all the settings and steps to perform one complete backup. | ||
*/ | ||
class backup_jazzquiz_activity_task extends backup_activity_task { | ||
|
||
/** | ||
* This should define settings. Not used at the moment. | ||
*/ | ||
protected function define_my_settings() { | ||
|
||
} | ||
|
||
/** | ||
* Define (add) particular steps this activity can have. | ||
*/ | ||
protected function define_my_steps() { | ||
$this->add_step(new backup_jazzquiz_activity_structure_step('jazzquiz_structure', 'jazzquiz.xml')); | ||
// TODO: This might not be necessary in future Moodle versions, if discussed subclass is added. | ||
$this->add_step(new backup_calculate_question_categories('activity_question_categories')); | ||
$this->add_step(new backup_delete_temp_questions('clean_temp_questions')); | ||
} | ||
|
||
/** | ||
* Code the transformations to perform in the activity in order to get transportable (encoded) links. | ||
* @param string $content | ||
* @return string of content with the URLs encoded | ||
*/ | ||
static public function encode_content_links($content) { | ||
global $CFG; | ||
$base = preg_quote($CFG->wwwroot,"/"); | ||
// Link to the list of JazzQuizes. | ||
$search = "/(" . $base . "\/mod\/jazzquiz\/index.php\?id\=)([0-9]+)/"; | ||
$content = preg_replace($search, '$@JAZZQUIZINDEX*$2@$', $content); | ||
// Link to JazzQuiz view by moduleid. | ||
$search = "/(" . $base . "\/mod\/jazzquiz\/view.php\?id\=)([0-9]+)/"; | ||
$content = preg_replace($search, '$@JAZZQUIZVIEWBYID*$2@$', $content); | ||
return $content; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
<?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/>. | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
/** | ||
* Define the complete choice structure for backup, with file and id annotations. | ||
*/ | ||
class backup_jazzquiz_activity_structure_step extends backup_questions_activity_structure_step { | ||
|
||
protected function define_structure() { | ||
|
||
// To know if we are including userinfo. | ||
$userinfo = $this->get_setting_value('userinfo'); | ||
|
||
// Define each element separated. | ||
$jazzquiz = new backup_nested_element('jazzquiz', ['id'], [ | ||
'name', | ||
'intro', | ||
'introformat', | ||
'timecreated', | ||
'timemodified', | ||
'defaultquestiontime', | ||
'waitforquestiontime' | ||
]); | ||
|
||
$questions = new backup_nested_element('questions'); | ||
$question = new backup_nested_element('question', ['id'], [ | ||
'questionid', | ||
'questiontime', | ||
'slot' | ||
]); | ||
|
||
$sessions = new backup_nested_element('sessions'); | ||
$session = new backup_nested_element('session', ['id'], [ | ||
'name', | ||
'sessionopen', | ||
'showfeedback', | ||
'status', | ||
'slot', | ||
'currentquestiontime', | ||
'nextstarttime', | ||
'created' | ||
]); | ||
|
||
$sessionquestions = new backup_nested_element('sessionquestions'); | ||
$sessionquestion = new backup_nested_element('sessionquestion', ['id'], [ | ||
'sessionid', | ||
'questionid', | ||
'questiontime', | ||
'slot' | ||
]); | ||
|
||
$attempts = new backup_nested_element('attempts'); | ||
$attempt = new backup_nested_element('attempt', ['id'], [ | ||
'sessionid', | ||
'userid', | ||
'questionengid', | ||
'status', | ||
'preview', | ||
'responded', | ||
'timestart', | ||
'timefinish', | ||
'timemodified' | ||
]); | ||
$this->add_question_usages($attempt, 'questionengid'); | ||
|
||
$merges = new backup_nested_element('merges'); | ||
$merge = new backup_nested_element('merge', ['id'], [ | ||
'sessionid', | ||
'slot', | ||
'ordernum', | ||
'original', | ||
'merged' | ||
]); | ||
|
||
$votes = new backup_nested_element('votes'); | ||
$vote = new backup_nested_element('vote', ['id'], [ | ||
'sessionid', | ||
'attempt', | ||
'initialcount', | ||
'finalcount', | ||
'userlist', | ||
'qtype', | ||
'slot' | ||
]); | ||
|
||
// Build the tree. | ||
$jazzquiz->add_child($questions); | ||
$jazzquiz->add_child($sessions); | ||
|
||
$questions->add_child($question); | ||
|
||
$sessions->add_child($session); | ||
$session->add_child($sessionquestions); | ||
$session->add_child($attempts); | ||
$session->add_child($merges); | ||
$session->add_child($votes); | ||
|
||
$sessionquestions->add_child($sessionquestion); | ||
$attempts->add_child($attempt); | ||
$merges->add_child($merge); | ||
$votes->add_child($vote); | ||
|
||
// Define sources. | ||
$jazzquiz->set_source_table('jazzquiz', ['id' => backup::VAR_ACTIVITYID]); | ||
$question->set_source_table('jazzquiz_questions', ['jazzquizid' => backup::VAR_PARENTID]); | ||
if ($userinfo) { | ||
$session->set_source_table('jazzquiz_sessions', ['jazzquizid' => backup::VAR_PARENTID]); | ||
$sessionquestion->set_source_table('jazzquiz_session_questions', ['sessionid' => backup::VAR_PARENTID]); | ||
$attempt->set_source_table('jazzquiz_attempts', ['sessionid' => backup::VAR_PARENTID]); | ||
$merge->set_source_table('jazzquiz_merges', ['sessionid' => backup::VAR_PARENTID]); | ||
$vote->set_source_table('jazzquiz_votes', [ | ||
'jazzquizid' => backup::VAR_ACTIVITYID, | ||
'sessionid' => backup::VAR_PARENTID | ||
]); | ||
} | ||
|
||
// Define id annotations. | ||
$attempt->annotate_ids('user', 'userid'); | ||
$question->annotate_ids('question', 'questionid'); | ||
$sessionquestion->annotate_ids('question', 'questionid'); | ||
|
||
// Define file annotations. | ||
$jazzquiz->annotate_files('mod_jazzquiz', 'intro', null); | ||
|
||
// Return the root element (choice), wrapped into standard activity structure. | ||
return $this->prepare_activity_structure($jazzquiz); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/>. | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
require_once($CFG->dirroot . '/mod/jazzquiz/backup/moodle2/restore_jazzquiz_stepslib.php'); | ||
|
||
/** | ||
* JazzQuiz restore task that provides all the settings and steps to perform one | ||
* complete restore of the activity | ||
*/ | ||
class restore_jazzquiz_activity_task extends restore_activity_task { | ||
|
||
/** | ||
* This should define settings. Not used at the moment. | ||
*/ | ||
protected function define_my_settings() { | ||
|
||
} | ||
|
||
/** | ||
* Define the structure steps. | ||
*/ | ||
protected function define_my_steps() { | ||
$this->add_step(new restore_jazzquiz_activity_structure_step('jazzquiz_structure', 'jazzquiz.xml')); | ||
} | ||
|
||
/** | ||
* @return restore_decode_content[] | ||
*/ | ||
static public function define_decode_contents() { | ||
return [ | ||
new restore_decode_content('jazzquiz', ['intro']) | ||
]; | ||
} | ||
|
||
/** | ||
* @return restore_decode_rule[] | ||
*/ | ||
static public function define_decode_rules() { | ||
return [ | ||
new restore_decode_rule('JAZZQUIZVIEWBYID', '/mod/jazzquiz/view.php?id=$1', 'course_module'), | ||
new restore_decode_rule('JAZZQUIZINDEX', '/mod/jazzquiz/index.php?id=$1', 'course') | ||
]; | ||
} | ||
|
||
/** | ||
* @return restore_log_rule[] | ||
*/ | ||
static public function define_restore_log_rules() { | ||
return []; | ||
} | ||
|
||
/** | ||
* @return restore_log_rule[] | ||
*/ | ||
static public function define_restore_log_rules_for_course() { | ||
return []; | ||
} | ||
|
||
} |
Oops, something went wrong.