bdaloukas
8 years ago
12 changed files with 1183 additions and 140 deletions
@ -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_game |
||||
|
* @subpackage backup-moodle2 |
||||
|
* @copyright 2007 Vasilis Daloukas |
||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
||||
|
**/ |
||||
|
|
||||
|
defined('MOODLE_INTERNAL') || die(); |
||||
|
|
||||
|
require_once($CFG->dirroot . '/mod/game/backup/moodle2/backup_game_stepslib.php'); // Because it exists (must). |
||||
|
|
||||
|
/** |
||||
|
* Defines backup_game_activity_task class |
||||
|
* |
||||
|
* game backup task that provides all the settings and steps to perform one |
||||
|
* complete backup of the activity |
||||
|
*/ |
||||
|
class backup_game_activity_task extends backup_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() { |
||||
|
// Game only has one structure step. |
||||
|
$this->add_step(new backup_game_activity_structure_step('game_structure', 'game.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 |
||||
|
*/ |
||||
|
static public function encode_content_links($content) { |
||||
|
global $CFG; |
||||
|
|
||||
|
$base = preg_quote($CFG->wwwroot, "/"); |
||||
|
|
||||
|
// Link to the list of games. |
||||
|
$search = "/(".$base."\/mod\/game\/index.php\?id\=)([0-9]+)/"; |
||||
|
$content = preg_replace($search, '$@GAMEINDEX*$2@$', $content); |
||||
|
|
||||
|
// Link to game view by moduleid. |
||||
|
$search = "/(".$base."\/mod\/game\/view.php\?id\=)([0-9]+)/"; |
||||
|
$content = preg_replace($search, '$@GAMEVIEWBYID*$2@$', $content); |
||||
|
|
||||
|
return $content; |
||||
|
} |
||||
|
} |
@ -0,0 +1,218 @@ |
|||||
|
<?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_game_activity_task |
||||
|
* |
||||
|
* @package mod_game |
||||
|
* @subpackage backup-moodle2 |
||||
|
* @author bdaloukas |
||||
|
backup_game_settingslib.php |
||||
|
*/ |
||||
|
|
||||
|
/** |
||||
|
* Define the complete game structure for backup, with file and id annotations |
||||
|
*/ |
||||
|
|
||||
|
defined('MOODLE_INTERNAL') || die(); |
||||
|
|
||||
|
class backup_game_activity_structure_step extends backup_activity_structure_step { |
||||
|
|
||||
|
/** |
||||
|
* Defines the needed structures. |
||||
|
*/ |
||||
|
protected function define_structure() { |
||||
|
|
||||
|
// To know if we are including userinfo. |
||||
|
$userinfo = $this->get_setting_value('userinfo'); |
||||
|
|
||||
|
// Define each element separated. |
||||
|
$game = new backup_nested_element('game', array('id'), array( |
||||
|
'name', 'sourcemodule', 'timeopen', 'timeclose', 'quizid', |
||||
|
'glossaryid', 'glossarycategoryid', 'questioncategoryid', 'bookid', |
||||
|
'gamekind', 'param1', 'param2', 'param3', |
||||
|
'param4', 'param5', 'param6', 'param7', 'param8', 'param9', |
||||
|
'shuffle', 'timemodified', 'toptext', 'bottomtext', |
||||
|
'grademethod', 'grade', 'decimalpoints', 'popup', |
||||
|
'review', 'attempts', 'glossaryid2', 'glossarycategoryid2', |
||||
|
'language', 'subcategories', 'maxattempts' |
||||
|
)); |
||||
|
|
||||
|
$exporthtmls = new backup_nested_element('game_export_htmls'); |
||||
|
$exporthtml = new backup_nested_element('game_export_html', array('id'), array( |
||||
|
'filename', 'title', 'checkbutton', 'printbutton', 'inputsize', 'maxpicturewidth', 'maxpictureheight')); |
||||
|
|
||||
|
$exportjavames = new backup_nested_element('game_export_javames'); |
||||
|
$exportjavame = new backup_nested_element('game_export_javame', array('id'), array( |
||||
|
'filename', 'icon', 'createdby', 'vendor', 'name', 'description', 'version', |
||||
|
'maxpicturewidth', 'maxpictureheight')); |
||||
|
|
||||
|
$grades = new backup_nested_element('game_grades'); |
||||
|
$grade = new backup_nested_element('game_grade', array('id'), array( |
||||
|
'userid', 'score', 'timemodified')); |
||||
|
|
||||
|
$repetitions = new backup_nested_element('game_repetitions'); |
||||
|
$repetition = new backup_nested_element('game_repetition', array('id'), array( |
||||
|
'userid', 'questionid', 'glossaryentryid', 'repetitions')); |
||||
|
|
||||
|
$attempts = new backup_nested_element('game_attempts'); |
||||
|
$attempt = new backup_nested_element('game_attempt', array('id'), array( |
||||
|
'userid', 'timestart', 'timefinish', 'timelastattempt', 'lastip', |
||||
|
'lastremotehost', 'preview', 'attempt', 'score', 'attempts', 'language')); |
||||
|
|
||||
|
$querys = new backup_nested_element('game_queries'); |
||||
|
$query = new backup_nested_element('game_query', array('id'), array( |
||||
|
'gamekind', 'userid', 'sourcemodule', 'questionid', 'glossaryentryid', |
||||
|
'questiontext', 'score', 'timelastattempt', 'studentanswer', 'col', 'row', |
||||
|
'horizontal', 'answertext', 'correct', 'attachment', 'answerid', 'tries')); |
||||
|
|
||||
|
$bookquizs = new backup_nested_element('game_bookquizs'); |
||||
|
$bookquiz = new backup_nested_element('game_bookquiz', array('id'), array('lastchapterid')); |
||||
|
|
||||
|
$bookquizchapters = new backup_nested_element('game_bookquiz_chapters'); |
||||
|
$bookquizchapter = new backup_nested_element('game_bookquiz_chapter', array('id'), array( 'chapterid')); |
||||
|
|
||||
|
$bookquizquestions = new backup_nested_element('game_bookquiz_questions'); |
||||
|
$bookquizquestion = new backup_nested_element('game_bookquiz_question', array('id'), array( |
||||
|
'chapterid', 'questioncategoryid')); |
||||
|
|
||||
|
$crosss = new backup_nested_element('game_crosss'); |
||||
|
$cross = new backup_nested_element('game_cross', array('id'), array( |
||||
|
'cols', 'rows', 'words', 'wordsall', 'createscore', 'createtries', |
||||
|
'createtimelimit', 'createconnectors', 'createfilleds', 'createspaces', 'triesplay')); |
||||
|
|
||||
|
$cryptexs = new backup_nested_element('game_cryptexs'); |
||||
|
$cryptex = new backup_nested_element('game_cryptex', array('id'), array('letters')); |
||||
|
|
||||
|
$hangmans = new backup_nested_element('game_hangmans'); |
||||
|
$hangman = new backup_nested_element('game_hangman', array('id'), array( |
||||
|
'queryid', 'letters', 'allletters', 'try', 'maxtries', 'finishedword', |
||||
|
'corrects', 'iscorrect')); |
||||
|
|
||||
|
$hiddenpictures = new backup_nested_element('game_hiddenpictures'); |
||||
|
$hiddenpicture = new backup_nested_element('game_hiddenpicture', array('id'), array('correct', 'wrong', 'found')); |
||||
|
|
||||
|
$millionaires = new backup_nested_element('game_millionaires'); |
||||
|
$millionaire = new backup_nested_element('game_millionaire', array('id'), array('queryid', 'state', 'level')); |
||||
|
|
||||
|
$snakes = new backup_nested_element('game_snakes'); |
||||
|
$snake = new backup_nested_element('game_snake', array('id'), array('snakesdatabaseid', 'position', 'queryid', 'dice')); |
||||
|
|
||||
|
$sudokus = new backup_nested_element('game_sudokus'); |
||||
|
$sudoku = new backup_nested_element('game_sudoku', array('id'), array('level', 'data', 'opened', 'guess')); |
||||
|
|
||||
|
// Build the tree. |
||||
|
$game->add_child( $bookquizquestions); |
||||
|
$bookquizquestions->add_child( $bookquizquestion); |
||||
|
|
||||
|
$game->add_child( $exporthtmls); |
||||
|
$exporthtmls->add_child( $exporthtml); |
||||
|
|
||||
|
$game->add_child( $exportjavames); |
||||
|
$exportjavames->add_child( $exportjavame); |
||||
|
|
||||
|
$game->add_child( $grades); |
||||
|
$grades->add_child( $grade); |
||||
|
|
||||
|
$game->add_child( $repetitions); |
||||
|
$repetitions->add_child( $repetition); |
||||
|
|
||||
|
// All these source definitions only happen if we are including user info. |
||||
|
if ($userinfo) { |
||||
|
$game->add_child( $attempts); |
||||
|
$attempts->add_child( $attempt); |
||||
|
|
||||
|
$attempts->add_child( $querys); |
||||
|
$querys->add_child( $query); |
||||
|
|
||||
|
$attempts->add_child( $bookquizs); |
||||
|
$bookquizs->add_child( $bookquiz); |
||||
|
|
||||
|
$game->add_child( $bookquizchapters); |
||||
|
$bookquizchapters->add_child($bookquizchapter); |
||||
|
|
||||
|
$attempts->add_child( $crosss); |
||||
|
$crosss->add_child( $cross); |
||||
|
|
||||
|
$attempts->add_child( $cryptexs); |
||||
|
$cryptexs->add_child( $cryptex); |
||||
|
|
||||
|
$attempts->add_child( $hangmans); |
||||
|
$hangmans->add_child( $hangman); |
||||
|
|
||||
|
$attempts->add_child( $hiddenpictures); |
||||
|
$hiddenpictures->add_child( $hiddenpicture); |
||||
|
|
||||
|
$attempts->add_child( $millionaires); |
||||
|
$millionaires->add_child( $millionaire); |
||||
|
|
||||
|
$attempts->add_child( $snakes); |
||||
|
$snakes->add_child( $snake); |
||||
|
|
||||
|
$attempts->add_child( $sudokus); |
||||
|
$sudokus->add_child( $sudoku); |
||||
|
} |
||||
|
|
||||
|
// Define sources. |
||||
|
$game->set_source_table('game', array('id' => backup::VAR_ACTIVITYID)); |
||||
|
$bookquizquestion->set_source_table('game_bookquiz_questions', array('gameid' => backup::VAR_ACTIVITYID)); |
||||
|
$exporthtml->set_source_table('game_export_html', array('id' => backup::VAR_ACTIVITYID)); |
||||
|
$exportjavame->set_source_table('game_export_javame', array('id' => backup::VAR_ACTIVITYID)); |
||||
|
|
||||
|
// All the rest of elements only happen if we are including user info. |
||||
|
if ($userinfo) { |
||||
|
$grade->set_source_table('game_grades', array('gameid' => backup::VAR_ACTIVITYID)); |
||||
|
$repetition->set_source_table('game_repetitions', array('gameid' => backup::VAR_ACTIVITYID)); |
||||
|
|
||||
|
$attempt->set_source_table('game_attempts', array( 'gameid' => backup::VAR_ACTIVITYID)); |
||||
|
$attempt->set_source_table('game_queries', array( 'attemptid' => backup::VAR_PARENTID)); |
||||
|
|
||||
|
$bookquiz->set_source_table('game_bookquiz', array( 'id' => backup::VAR_ACTIVITYID)); |
||||
|
$bookquizchapter->set_source_table('game_bookquiz_chapters', array( 'id' => backup::VAR_PARENTID)); |
||||
|
|
||||
|
$cross->set_source_table('game_cross', array( 'id' => backup::VAR_PARENTID)); |
||||
|
$cryptex->set_source_table('game_cryptex', array( 'id' => backup::VAR_PARENTID)); |
||||
|
$hangman->set_source_table('game_hangman', array( 'id' => backup::VAR_PARENTID)); |
||||
|
$hiddenpicture->set_source_table('game_hiddenpicture', array( 'id' => backup::VAR_PARENTID)); |
||||
|
$millionaire->set_source_table('game_millionaire', array( 'id' => backup::VAR_PARENTID)); |
||||
|
$snake->set_source_table('game_snakes', array( 'id' => backup::VAR_PARENTID)); |
||||
|
$sudoku->set_source_table('game_sudoku', array( 'id' => backup::VAR_PARENTID)); |
||||
|
} |
||||
|
// Define id annotations. |
||||
|
$attempt->annotate_ids('user', 'userid'); |
||||
|
$grade->annotate_ids('user', 'userid'); |
||||
|
$repetition->annotate_ids('user', 'userid'); |
||||
|
$repetition->annotate_ids('question', 'questionid'); |
||||
|
$repetition->annotate_ids('glossary_entry', 'glossaryentryid'); |
||||
|
$query->annotate_ids('user', 'userid'); |
||||
|
$query->annotate_ids('question', 'questionid'); |
||||
|
$query->annotate_ids('glossary_enrty', 'glossaryentryid'); |
||||
|
$query->annotate_ids('question_answer', 'answerid'); |
||||
|
|
||||
|
$bookquizquestion->annotate_ids('book_chapter', 'chapterid'); |
||||
|
$bookquizquestion->annotate_ids('question_category', 'questioncategoryid'); |
||||
|
$bookquizchapter->annotate_ids('book_chapter', 'chapterid'); |
||||
|
$hangman->annotate_ids('game_query', 'queryid'); |
||||
|
$millionaire->annotate_ids('game_query', 'queryid'); |
||||
|
|
||||
|
// Define file annotations. |
||||
|
$game->annotate_files('mod_game', 'snakes_file', null); // This file area hasn't itemid. |
||||
|
$game->annotate_files('mod_game', 'snakes_board', null); // This file area hasn't itemid. |
||||
|
|
||||
|
// Return the root element (game), wrapped into standard activity structure. |
||||
|
return $this->prepare_activity_structure( $game); |
||||
|
} |
||||
|
} |
@ -0,0 +1,246 @@ |
|||||
|
<?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_game |
||||
|
* @subpackage backup-moodle2 |
||||
|
* @author bdaloukas |
||||
|
*/ |
||||
|
|
||||
|
defined('MOODLE_INTERNAL') || die(); |
||||
|
require_once($CFG->dirroot . '/mod/game/backup/moodle2/restore_game_stepslib.php'); // Because it exists (must). |
||||
|
|
||||
|
/** |
||||
|
* game restore task that provides all the settings and steps to perform one |
||||
|
* complete restore of the activity |
||||
|
*/ |
||||
|
class restore_game_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() { |
||||
|
// Game only has one structure step. |
||||
|
$this->add_step(new restore_game_activity_structure_step('game_structure', 'game.xml')); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Define the contents in the activity that must be |
||||
|
* processed by the link decoder |
||||
|
*/ |
||||
|
static public function define_decode_contents() { |
||||
|
$contents = array(); |
||||
|
|
||||
|
$contents[] = new restore_decode_content('game', array('toptext'), 'game'); |
||||
|
$contents[] = new restore_decode_content('game', array('bottomtext'), 'game'); |
||||
|
|
||||
|
return $contents; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Define the decoding rules for links belonging |
||||
|
* to the activity to be executed by the link decoder |
||||
|
*/ |
||||
|
static public function define_decode_rules() { |
||||
|
$rules = array(); |
||||
|
|
||||
|
return $rules; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Define the restore log rules that will be applied |
||||
|
* by the {@link restore_logs_processor} when restoring |
||||
|
* game logs. It must return one array |
||||
|
* of {@link restore_log_rule} objects |
||||
|
*/ |
||||
|
static public function define_restore_log_rules() { |
||||
|
$rules = array(); |
||||
|
|
||||
|
$rules[] = new restore_log_rule('game', 'add', 'view.php?id={course_module}', '{game}'); |
||||
|
$rules[] = new restore_log_rule('game', 'update', 'view.php?id={course_module}', '{game}'); |
||||
|
$rules[] = new restore_log_rule('game', 'view', 'view.php?id={course_module}', '{game}'); |
||||
|
$rules[] = new restore_log_rule('game', 'choose', 'view.php?id={course_module}', '{game}'); |
||||
|
$rules[] = new restore_log_rule('game', 'choose again', 'view.php?id={course_module}', '{game}'); |
||||
|
$rules[] = new restore_log_rule('game', 'report', 'report.php?id={course_module}', '{game}'); |
||||
|
|
||||
|
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) |
||||
|
*/ |
||||
|
static public function define_restore_log_rules_for_course() { |
||||
|
$rules = array(); |
||||
|
|
||||
|
// Fix old wrong uses (missing extension). |
||||
|
$rules[] = new restore_log_rule('game', 'view all', 'index?id={course}', null, |
||||
|
null, null, 'index.php?id={course}'); |
||||
|
$rules[] = new restore_log_rule('game', 'view all', 'index.php?id={course}', null); |
||||
|
|
||||
|
return $rules; |
||||
|
} |
||||
|
|
||||
|
public function after_restore() { |
||||
|
// Do something at end of restore. |
||||
|
global $DB; |
||||
|
|
||||
|
// Get the blockid. |
||||
|
$gameid = $this->get_activityid(); |
||||
|
|
||||
|
// Extract Game configdata and update it to point to the new glossary. |
||||
|
$rec = $DB->get_record_select( 'game', 'id='.$gameid, |
||||
|
null, 'id,quizid,glossaryid,glossarycategoryid,questioncategoryid,bookid,glossaryid2,glossarycategoryid2'); |
||||
|
|
||||
|
$ret = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'quiz', $rec->quizid); |
||||
|
if ($ret != false) { |
||||
|
$rec->quizid = $ret->newitemid; |
||||
|
} |
||||
|
|
||||
|
$ret = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'glossary', $rec->glossaryid); |
||||
|
if ($ret != false) { |
||||
|
$rec->glossaryid = $ret->newitemid; |
||||
|
} |
||||
|
|
||||
|
$ret = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'glossary_categories', $rec->glossarycategoryid); |
||||
|
if ($ret != false) { |
||||
|
$rec->glossarycategoryid = $ret->newitemid; |
||||
|
} |
||||
|
|
||||
|
$ret = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'question_categories', $rec->questioncategoryid); |
||||
|
if ($ret != false) { |
||||
|
$rec->questioncategoryid = $ret->newitemid; |
||||
|
} |
||||
|
|
||||
|
$ret = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'book', $rec->bookid); |
||||
|
if ($ret != false) { |
||||
|
$rec->bookid = $ret->newitemid; |
||||
|
} |
||||
|
|
||||
|
$ret = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'glossary', $rec->glossaryid2); |
||||
|
if ($ret != false) { |
||||
|
$rec->glossaryid2 = $ret->newitemid; |
||||
|
} |
||||
|
|
||||
|
$ret = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'glossary_categories', $rec->glossarycategoryid); |
||||
|
if ($ret != false) { |
||||
|
$rec->glossarycategoryid = $ret->newitemid; |
||||
|
} |
||||
|
|
||||
|
$DB->update_record( 'game', $rec); |
||||
|
|
||||
|
// Read game_repetitions. |
||||
|
$recs = $DB->get_records_select( 'game_repetitions', 'gameid='.$gameid, null, '', |
||||
|
'id,questionid,glossaryentryid'); |
||||
|
if ($recs != false) { |
||||
|
foreach ($recs as $rec) { |
||||
|
$ret = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'question', $rec->questionid); |
||||
|
if ($ret != false) { |
||||
|
$rec->questionid = $ret->newitemid; |
||||
|
} |
||||
|
|
||||
|
$ret = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'glossary_entry', $rec->glossaryentryid); |
||||
|
if ($ret != false) { |
||||
|
$rec->glossaryentryid = $ret->newitemid; |
||||
|
} |
||||
|
|
||||
|
$DB->update_record( 'game_repetitions', $rec); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// Read game_queries. |
||||
|
$recs = $DB->get_records_select( 'game_queries', 'gameid='.$gameid, null, '', |
||||
|
'id,questionid,glossaryentryid,answerid'); |
||||
|
if ($recs != false) { |
||||
|
foreach ($recs as $rec) { |
||||
|
$ret = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'question', $rec->questionid); |
||||
|
if ($ret != false) { |
||||
|
$rec->questionid = $ret->newitemid; |
||||
|
} |
||||
|
$ret = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'glossary_entry', $rec->glossaryentryid); |
||||
|
if ($ret != false) { |
||||
|
$rec->glossaryentryid = $ret->newitemid; |
||||
|
} |
||||
|
|
||||
|
$ret = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'question_answers', $rec->glossaryentryid); |
||||
|
if ($ret != false) { |
||||
|
$rec->answerid = $ret->newitemid; |
||||
|
} |
||||
|
|
||||
|
$DB->update_record( 'game_queries', $rec); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// Read bookquiz. |
||||
|
$recs = $DB->get_records_select( 'game_bookquiz', 'id='.$gameid, null, '', 'id,lastchapterid'); |
||||
|
if ($recs != false) { |
||||
|
foreach ($recs as $rec) { |
||||
|
$ret = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'book_chapters', $rec->lastchapterid); |
||||
|
if ($ret != false) { |
||||
|
$rec->lastchapterid = $ret->newitemid; |
||||
|
} |
||||
|
|
||||
|
$DB->update_record( 'game_bookquiz', $rec); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// Read bookquiz_chapters. |
||||
|
$sql = "SELECT gbc.* ". |
||||
|
"FROM {game_bookquiz_chapters} gbc LEFT JOIN {game_attempts} a ON gbc.attemptid = a.id". |
||||
|
" WHERE a.gameid=$gameid"; |
||||
|
$recs = $DB->get_records_sql( $sql); |
||||
|
if ($recs != false) { |
||||
|
foreach ($recs as $rec) { |
||||
|
$ret = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'book_chapters', $rec->chapterid); |
||||
|
if ($ret != false) { |
||||
|
$rec->chapterid = $ret->newitemid; |
||||
|
} |
||||
|
$DB->update_record( 'game_bookquiz_chapter', $rec); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// Read bookquiz_questions. |
||||
|
$recs = $DB->get_records_select( 'game_bookquiz_questions', 'id='.$gameid, null, '', 'id,chapterid,questioncategoryid'); |
||||
|
if ($recs != false) { |
||||
|
foreach ($recs as $rec) { |
||||
|
$ret = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'book_chapters', $rec->chapterid); |
||||
|
if ($ret != false) { |
||||
|
$rec->chapterid = $ret->newitemid; |
||||
|
} |
||||
|
|
||||
|
$ret = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'book_chapters', $rec->questioncategoryid); |
||||
|
if ($ret != false) { |
||||
|
$rec->questioncategoryid = $ret->newitemid; |
||||
|
} |
||||
|
|
||||
|
$DB->update_record( 'game_bookquiz_questions', $rec); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,363 @@ |
|||||
|
<?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_game_activity_task |
||||
|
* |
||||
|
* @package mod_game |
||||
|
* @subpackage backup-moodle2 |
||||
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
||||
|
*/ |
||||
|
|
||||
|
defined('MOODLE_INTERNAL') || die(); |
||||
|
|
||||
|
/** |
||||
|
* Structure step to restore one game activity |
||||
|
*/ |
||||
|
class restore_game_activity_structure_step extends restore_activity_structure_step { |
||||
|
|
||||
|
/** |
||||
|
* Defines the neeeded structures. |
||||
|
*/ |
||||
|
protected function define_structure() { |
||||
|
|
||||
|
$paths = array(); |
||||
|
$userinfo = $this->get_setting_value('userinfo'); |
||||
|
|
||||
|
$paths[] = new restore_path_element('game', '/activity/game'); |
||||
|
$paths[] = new restore_path_element('game_export_html', '/activity/game/game_export_htmls/game_export_html'); |
||||
|
$paths[] = new restore_path_element('game_export_javame', '/activity/game/game_export_htmls/game_export_javame'); |
||||
|
$paths[] = new restore_path_element( |
||||
|
'game_bookquiz_question', '/activity/game/game_bookquiz_questions/game_bookquiz_question'); |
||||
|
if ($userinfo) { |
||||
|
$paths[] = new restore_path_element('game_grade', '/activity/game/game_grades/game_grade'); |
||||
|
$paths[] = new restore_path_element('game_repetition', '/activity/game/game_repetiotions/game_repetition'); |
||||
|
$paths[] = new restore_path_element('game_attempt', '/activity/game/game_attempts/game_attempt'); |
||||
|
$paths[] = new restore_path_element('game_query', '/activity/game/game_querys/game_query'); |
||||
|
$paths[] = new restore_path_element('game_bookquiz', '/activity/game/game_bookquizs/game_bookquiz'); |
||||
|
$paths[] = new restore_path_element('game_bookquiz_chapter', |
||||
|
'/activity/game/game_bookquiz_chapters/game_bookquiz_chapter'); |
||||
|
$paths[] = new restore_path_element('game_cross', '/activity/game/game_crosss/game_cross'); |
||||
|
$paths[] = new restore_path_element('game_cryptex', '/activity/game/game_cryptexs/game_cryptex'); |
||||
|
$paths[] = new restore_path_element('game_hangman', '/activity/game/game_hangmans/game_hangman'); |
||||
|
$paths[] = new restore_path_element('game_hiddenpicture', '/activity/game/game_hiddenpictures/game_hiddenpicture'); |
||||
|
$paths[] = new restore_path_element('game_millionaire', '/activity/game/game_millionaires/game_millionaire'); |
||||
|
$paths[] = new restore_path_element('game_snake', '/activity/game/game_snakes/game_snake'); |
||||
|
$paths[] = new restore_path_element('game_sudoku', '/activity/game/game_sudokus/game_sudoku'); |
||||
|
} |
||||
|
|
||||
|
// Return the paths wrapped into standard activity structure. |
||||
|
return $this->prepare_activity_structure($paths); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Restores the game table. |
||||
|
* |
||||
|
* @param stdClass $data |
||||
|
*/ |
||||
|
protected function process_game($data) { |
||||
|
global $DB; |
||||
|
|
||||
|
$data = (object)$data; |
||||
|
$oldid = $data->id; |
||||
|
$data->course = $this->get_courseid(); |
||||
|
$data->timemodified = $this->apply_date_offset($data->timemodified); |
||||
|
|
||||
|
// Insert the game record. |
||||
|
$newitemid = $DB->insert_record('game', $data); |
||||
|
|
||||
|
// Immediately after inserting "activity" record, call this. |
||||
|
$this->apply_activity_instance($newitemid); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Restores the game_export_html table. |
||||
|
* |
||||
|
* @param stdClass $data |
||||
|
*/ |
||||
|
protected function process_game_export_html($data) { |
||||
|
global $DB; |
||||
|
|
||||
|
$data = (object)$data; |
||||
|
|
||||
|
$data->id = $this->get_new_parentid('game'); |
||||
|
if ($data->id != 0) { |
||||
|
$DB->insert_record('game_export_html', $data); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Restores the game_export_javame table. |
||||
|
* |
||||
|
* @param stdClass $game |
||||
|
*/ |
||||
|
protected function process_game_export_javame( $data) { |
||||
|
global $DB; |
||||
|
|
||||
|
$data = (object)$data; |
||||
|
|
||||
|
$data->id = $this->get_new_parentid('game'); |
||||
|
if ($data->id != 0) { |
||||
|
$DB->insert_record('game_export_javame', $data); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Restores the game_grades table. |
||||
|
* |
||||
|
* @param stdClass $data |
||||
|
*/ |
||||
|
protected function process_game_grade( $data) { |
||||
|
global $DB; |
||||
|
|
||||
|
$data = (object)$data; |
||||
|
$oldid = $data->id; |
||||
|
|
||||
|
$data->gameid = $this->get_new_parentid('game'); |
||||
|
$data->userid = $this->get_mappingid('user', $data->userid); |
||||
|
|
||||
|
$DB->insert_record('game_grades', $data); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Restores the game_repetitions table. |
||||
|
* |
||||
|
* @param stdClass $data |
||||
|
*/ |
||||
|
protected function process_game_repetition( $data) { |
||||
|
global $DB; |
||||
|
|
||||
|
$data = (object)$data; |
||||
|
$oldid = $data->id; |
||||
|
|
||||
|
$data->gameid = $this->get_new_parentid('game'); |
||||
|
$data->userid = $this->get_mappingid('user', $data->userid); |
||||
|
|
||||
|
$DB->insert_record('game_repetitions', $data); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Restores the game_attempts table. |
||||
|
* |
||||
|
* @param stdClass $data |
||||
|
*/ |
||||
|
protected function process_game_attempt( $data) { |
||||
|
global $DB; |
||||
|
|
||||
|
$data = (object)$data; |
||||
|
$oldid = $data->id; |
||||
|
|
||||
|
$data->gameid = $this->get_new_parentid('game'); |
||||
|
$data->userid = $this->get_mappingid('user', $data->userid); |
||||
|
|
||||
|
if (!isset( $data->timestart)) { |
||||
|
$data->timestart = 0; |
||||
|
} |
||||
|
if (!isset( $data->timefinish)) { |
||||
|
$data->timefinish = 0; |
||||
|
} |
||||
|
if (!isset( $data->timelastattempt)) { |
||||
|
$data->timelastattempt = 0; |
||||
|
} |
||||
|
|
||||
|
$data->timestart = $this->apply_date_offset($data->timestart); |
||||
|
$data->timefinish = $this->apply_date_offset($data->timefinish); |
||||
|
$data->timelastattempt = $this->apply_date_offset($data->timelastattempt); |
||||
|
|
||||
|
$newitemid = $DB->insert_record('game_attempts', $data); |
||||
|
$this->set_mapping('game_attempt', $oldid, $newitemid); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Restores the game_queries table. |
||||
|
* |
||||
|
* @param stdClass $data |
||||
|
*/ |
||||
|
protected function process_game_query( $data) { |
||||
|
global $DB; |
||||
|
|
||||
|
$data = (object)$data; |
||||
|
$oldid = $data->id; |
||||
|
|
||||
|
$data->gameid = $this->get_new_parentid('game'); |
||||
|
$data->attemptid = get_mappingid('game_attempt', $data->attemptid); |
||||
|
$data->userid = $this->get_mappingid('user', $data->userid); |
||||
|
|
||||
|
$newitemid = $DB->insert_record('game_queries', $data); |
||||
|
$this->set_mapping('game_query', $oldid, $newitemid); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Restores the game_bookquiz table. |
||||
|
* |
||||
|
* @param stdClass $data |
||||
|
*/ |
||||
|
protected function process_game_bookquiz( $data) { |
||||
|
global $DB; |
||||
|
|
||||
|
$data = (object)$data; |
||||
|
|
||||
|
$data->id = $this->get_new_parentid('game'); |
||||
|
|
||||
|
$DB->insert_record('game_bookquiz', $data); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Restores the game_bookauiz_chapters table. |
||||
|
* |
||||
|
* @param stdClass $data |
||||
|
*/ |
||||
|
protected function process_game_bookquiz_chapter( $data) { |
||||
|
global $DB; |
||||
|
|
||||
|
$data = (object)$data; |
||||
|
|
||||
|
$data->gameid = $this->get_new_parentid('game'); |
||||
|
|
||||
|
$DB->insert_record('game_bookquiz_chapters', $data); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Restores the game_bookquiz_questions table. |
||||
|
* |
||||
|
* @param stdClass $data |
||||
|
*/ |
||||
|
protected function process_game_bookquiz_question( $data) { |
||||
|
global $DB; |
||||
|
|
||||
|
$data = (object)$data; |
||||
|
|
||||
|
$data->gameid = $this->get_new_parentid('game'); |
||||
|
|
||||
|
$DB->insert_record('game_bookquiz_questions', $data); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Restores the game_cross table. |
||||
|
* |
||||
|
* @param stdClass $data |
||||
|
*/ |
||||
|
protected function process_game_cross( $data) { |
||||
|
global $DB; |
||||
|
|
||||
|
$data = (object)$data; |
||||
|
|
||||
|
$data->id = $this->get_new_parentid('game'); |
||||
|
|
||||
|
$DB->insert_record('game_cross', $data); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Restores the game_cryptex table. |
||||
|
* |
||||
|
* @param stdClass $data |
||||
|
*/ |
||||
|
protected function process_game_cryptex( $data) { |
||||
|
global $DB; |
||||
|
|
||||
|
$data = (object)$data; |
||||
|
|
||||
|
$data->id = $this->get_new_parentid('game'); |
||||
|
|
||||
|
$DB->insert_record('game_cryptex', $data); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Restores the game_hangman table. |
||||
|
* |
||||
|
* @param stdClass $data |
||||
|
*/ |
||||
|
protected function process_game_hangman( $data) { |
||||
|
global $DB; |
||||
|
|
||||
|
$data = (object)$data; |
||||
|
|
||||
|
$data->id = $this->get_new_parentid('game'); |
||||
|
$data->queryid = $this->get_mappingid('game_query', $data->queryid); |
||||
|
|
||||
|
$DB->insert_record('game_hangman', $data); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Restores the game_hiddenpicture table. |
||||
|
* |
||||
|
* @param stdClass $data |
||||
|
*/ |
||||
|
protected function process_game_hiddenpicture( $data) { |
||||
|
global $DB; |
||||
|
|
||||
|
$data = (object)$data; |
||||
|
|
||||
|
$data->id = $this->get_new_parentid('game'); |
||||
|
|
||||
|
$DB->insert_record('game_hiddenpicture', $data); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Restores the game_millionaire table. |
||||
|
* |
||||
|
* @param stdClass $data |
||||
|
*/ |
||||
|
protected function process_game_millionaire( $data) { |
||||
|
global $DB; |
||||
|
|
||||
|
$data = (object)$data; |
||||
|
|
||||
|
$data->id = $this->get_new_parentid('game'); |
||||
|
$data->queryid = $this->get_mappingid('game_query', $data->queryid); |
||||
|
|
||||
|
$DB->insert_record('game_millionaire', $data); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Restores the game_snakes table. |
||||
|
* |
||||
|
* @param stdClass $data |
||||
|
*/ |
||||
|
protected function process_game_snake( $data) { |
||||
|
global $DB; |
||||
|
|
||||
|
$data = (object)$data; |
||||
|
|
||||
|
$data->id = $this->get_new_parentid('game'); |
||||
|
$data->queryid = $this->get_mappingid('game_query', $data->queryid); |
||||
|
|
||||
|
$DB->insert_record('game_snakes', $data); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Restores the game_sudoku table. |
||||
|
* |
||||
|
* @param stdClass $data |
||||
|
*/ |
||||
|
protected function process_game_sudoku( $data) { |
||||
|
global $DB; |
||||
|
|
||||
|
$data = (object)$data; |
||||
|
|
||||
|
$data->id = $this->get_new_parentid('game'); |
||||
|
|
||||
|
$DB->insert_record('game_sudoku', $data); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Add Game related files, no need to match by itemname (just internally handled context). |
||||
|
*/ |
||||
|
protected function after_execute() { |
||||
|
$this->add_related_files('mod_game', 'snakes_file', null); |
||||
|
$this->add_related_files('mod_game', 'snakes_board', null); |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue