diff --git a/backup/moodle2/backup_game_activity_task.class.php b/backup/moodle2/backup_game_activity_task.class.php index 05e8729..3e095ab 100755 --- a/backup/moodle2/backup_game_activity_task.class.php +++ b/backup/moodle2/backup_game_activity_task.class.php @@ -1,5 +1,4 @@ dirroot . '/mod/game/backup/moodle2/backup_game_stepslib.php'); // Because it exists (must) -require_once($CFG->dirroot . '/mod/game/backup/moodle2/backup_game_settingslib.php'); // Because it exists (optional) - + +require_once($CFG->dirroot . '/mod/game/backup/moodle2/backup_game_stepslib.php'); // Because it exists (must). +require_once($CFG->dirroot . '/mod/game/backup/moodle2/backup_game_settingslib.php'); // Because it exists (optional). + /** * game backup task that provides all the settings and steps to perform one * complete backup of the activity @@ -37,34 +36,34 @@ 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 + // 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')); + // Game only has one structure step. + $this->add_step(new backup_game_activity_structure_step('game_structure', 'game.xml')); } - + /** * Code the transformations to perform in the activity in * order to get transportable (encoded) links */ static public function encode_content_links($content) { global $CFG; - - $base = preg_quote($CFG->wwwroot,"/"); - - // Link to the list of gamess - $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); - + + $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; } } diff --git a/backup/moodle2/backup_game_settingslib.php b/backup/moodle2/backup_game_settingslib.php index ab78ff4..998e8ae 100755 --- a/backup/moodle2/backup_game_settingslib.php +++ b/backup/moodle2/backup_game_settingslib.php @@ -1,5 +1,4 @@ . - + /** * @package moodlecore * @subpackage backup-moodle2 * @copyright 2010 onwards YOUR_NAME_GOES_HERE {@link YOUR_URL_GOES_HERE} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - - // 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) + +/** 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) + */ diff --git a/backup/moodle2/backup_game_stepslib.php b/backup/moodle2/backup_game_stepslib.php index 032ab7d..5ea4205 100755 --- a/backup/moodle2/backup_game_stepslib.php +++ b/backup/moodle2/backup_game_stepslib.php @@ -1,5 +1,4 @@ get_setting_value('userinfo'); - // Define each element separated + // Define each element separated. $game = new backup_nested_element('game', array('id'), array( 'name', 'sourcemodule', 'timeopen', 'timeclose', 'quizid', 'glossaryid', 'glossarycategoryid', 'questioncategoryid', 'bookid', @@ -45,16 +44,17 @@ class backup_game_activity_structure_step extends backup_activity_structure_step 'shuffle', 'timemodified', 'toptext', 'bottomtext', 'grademethod', 'grade', 'decimalpoints', 'popup', 'review', 'attempts', 'glossaryid2', 'glossarycategoryid2', - 'language', 'subcategories', 'maxattempts' + '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')); + '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')); + '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( @@ -63,122 +63,122 @@ class backup_game_activity_structure_step extends backup_activity_structure_step $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'); + + $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')); + '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', + 'gamekind', 'userid', 'sourcemodule', 'questionid', 'glossaryentryid', + 'questiontext', 'score', 'timelastattempt', 'studentanswer', 'col', 'row', 'horizontal', 'answertext', 'correct', 'attachment', 'answerid', 'tries')); - $bookquizs = new backup_nested_element('game_bookquizs'); + $bookquizs = new backup_nested_element('game_bookquizs'); $bookquiz = new backup_nested_element('game_bookquiz', array('id'), array('lastchapterid')); - $bookquiz_chapters = new backup_nested_element('game_bookquiz_chapters'); - $bookquiz_chapter = new backup_nested_element('game_bookquiz_chapter', array('id'), array( 'chapterid')); - - $bookquiz_questions = new backup_nested_element('game_bookquiz_questions'); - $bookquiz_question = new backup_nested_element('game_bookquiz_question', array('id'), array( + $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'); + $crosss = new backup_nested_element('game_crosss'); $cross = new backup_nested_element('game_cross', array('id'), array( - 'cols', 'rows', 'words', 'wordsall', 'createscore', 'createtries', + 'cols', 'rows', 'words', 'wordsall', 'createscore', 'createtries', 'createtimelimit', 'createconnectors', 'createfilleds', 'createspaces', 'triesplay')); - $cryptexs = new backup_nested_element('game_cryptexs'); + $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'); + + $hangmans = new backup_nested_element('game_hangmans'); $hangman = new backup_nested_element('game_hangman', array('id'), array( - 'queryid', 'letters', 'allletters', 'try', 'maxtries', 'finishedword', + 'queryid', 'letters', 'allletters', 'try', 'maxtries', 'finishedword', 'corrects', 'iscorrect')); - $hiddenpictures = new backup_nested_element('game_hiddenpictures'); + $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'); + + $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'); + $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'); + $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($bookquiz_questions); - $bookquiz_questions->add_child($bookquiz_question); - + // 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 + + // All these source definitions only happen if we are including user info. if ($userinfo) { - $game->add_child( $attempts); - $attempts->add_child( $attempt); + $game->add_child( $attempts); + $attempts->add_child( $attempt); + + $attempts->add_child( $querys); + $querys->add_child( $query); - $attempts->add_child( $querys); - $querys->add_child( $query); + $attempts->add_child( $bookquizs); + $bookquizs->add_child( $bookquiz); - $attempts->add_child( $bookquizs); - $bookquizs->add_child( $bookquiz); + $game->add_child( $bookquizchapters); + $bookquizchapters->add_child($bookquizchapter); - $game->add_child($bookquiz_chapters); - $bookquiz_chapters->add_child($bookquiz_chapter); + $attempts->add_child( $crosss); + $crosss->add_child( $cross); - $attempts->add_child( $crosss); - $crosss->add_child( $cross); + $attempts->add_child( $cryptexs); + $cryptexs->add_child( $cryptex); - $attempts->add_child( $cryptexs); - $cryptexs->add_child( $cryptex); + $attempts->add_child( $hangmans); + $hangmans->add_child( $hangman); - $attempts->add_child( $hangmans); - $hangmans->add_child( $hangman); + $attempts->add_child( $hiddenpictures); + $hiddenpictures->add_child( $hiddenpicture); - $attempts->add_child( $hiddenpictures); - $hiddenpictures->add_child( $hiddenpicture); + $attempts->add_child( $millionaires); + $millionaires->add_child( $millionaire); - $attempts->add_child( $millionaires); - $millionaires->add_child( $millionaire); + $attempts->add_child( $snakes); + $snakes->add_child( $snake); - $attempts->add_child( $snakes); - $snakes->add_child( $snake); - - $attempts->add_child( $sudokus); - $sudokus->add_child( $sudoku); - } - - // Define sources + $attempts->add_child( $sudokus); + $sudokus->add_child( $sudoku); + } + + // Define sources. $game->set_source_table('game', array('id' => backup::VAR_ACTIVITYID)); - $bookquiz_question->set_source_table('game_bookquiz_questions', array('gameid' => 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 + + // 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)); - $bookquiz_chapter->set_source_table('game_bookquiz_chapters', array( 'id' => backup::VAR_PARENTID)); - + $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)); @@ -187,7 +187,7 @@ class backup_game_activity_structure_step extends backup_activity_structure_step $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 + // Define id annotations. $attempt->annotate_ids('user', 'userid'); $grade->annotate_ids('user', 'userid'); $repetition->annotate_ids('user', 'userid'); @@ -198,17 +198,17 @@ class backup_game_activity_structure_step extends backup_activity_structure_step $query->annotate_ids('glossary_enrty', 'glossaryentryid'); $query->annotate_ids('question_answer', 'answerid'); - $bookquiz_question->annotate_ids('book_chapter', 'chapterid'); - $bookquiz_question->annotate_ids('question_category', 'questioncategoryid'); - $bookquiz_chapter->annotate_ids('book_chapter', 'chapterid'); + $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 + + // 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); } } diff --git a/backup/moodle2/restore_game_activity_task.class.php b/backup/moodle2/restore_game_activity_task.class.php index 81b9134..e6b7d84 100755 --- a/backup/moodle2/restore_game_activity_task.class.php +++ b/backup/moodle2/restore_game_activity_task.class.php @@ -1,5 +1,4 @@ -dirroot . '/mod/game/backup/moodle2/restore_game_stepslib.php'); // Because it exists (must) +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 @@ -35,14 +34,14 @@ 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 + // 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 + // Game only has one structure step. $this->add_step(new restore_game_activity_structure_step('game_structure', 'game.xml')); } @@ -77,7 +76,7 @@ class restore_game_activity_task extends restore_activity_task { */ 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}'); @@ -87,7 +86,7 @@ class restore_game_activity_task extends restore_activity_task { return $rules; } - + /** * Define the restore log rules that will be applied * by the {@link restore_logs_processor} when restoring @@ -100,134 +99,149 @@ class restore_game_activity_task extends restore_activity_task { */ static public function define_restore_log_rules_for_course() { $rules = array(); - - // Fix old wrong uses (missing extension) + + // 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 + // Do something at end of restore. global $DB; - // Get the blockid + // 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'); + + // 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) + if ($ret != false) { $rec->quizid = $ret->newitemid; - + } + $ret = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'glossary', $rec->glossaryid); - if( $ret != false) + if ($ret != false) { $rec->glossaryid = $ret->newitemid; - + } + $ret = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'glossary_categories', $rec->glossarycategoryid); - if( $ret != false) + if ($ret != false) { $rec->glossarycategoryid = $ret->newitemid; - + } + $ret = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'question_categories', $rec->questioncategoryid); - if( $ret != false) + if ($ret != false) { $rec->questioncategoryid = $ret->newitemid; - + } + $ret = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'book', $rec->bookid); - if( $ret != false) + if ($ret != false) { $rec->bookid = $ret->newitemid; - + } + $ret = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'glossary', $rec->glossaryid2); - if( $ret != false) + if ($ret != false) { $rec->glossaryid2 = $ret->newitemid; - + } + $ret = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'glossary_categories', $rec->glossarycategoryid); - if( $ret != false) + if ($ret != false) { $rec->glossarycategoryid = $ret->newitemid; - + } + $DB->update_record( 'game', $rec); - //game_repetitions + // Read game_repetitions. $recs = $DB->get_records_select( 'game_repetitions', 'gameid='.$gameid, null, '', 'id,questionid,glossaryentryid'); - if( $recs != false){ - foreach( $recs as $rec){ + if ($recs != false) { + foreach ($recs as $rec) { $ret = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'question', $rec->questionid); - if( $ret != false) + if ($ret != false) { $rec->questionid = $ret->newitemid; - + } + $ret = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'glossary_entry', $rec->glossaryentryid); - if( $ret != false) + if ($ret != false) { $rec->glossaryentryid = $ret->newitemid; - + } + $DB->update_record( 'game_repetitions', $rec); - } + } } - - //game_queries + + // Read game_queries. $recs = $DB->get_records_select( 'game_queries', 'gameid='.$gameid, null, '', 'id,questionid,glossaryentryid,answerid'); - if( $recs != false){ - foreach( $recs as $rec){ + if ($recs != false) { + foreach ($recs as $rec) { $ret = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'question', $rec->questionid); - if( $ret != false) + if ($ret != false) { $rec->questionid = $ret->newitemid; - + } $ret = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'glossary_entry', $rec->glossaryentryid); - if( $ret != false) + if ($ret != false) { $rec->glossaryentryid = $ret->newitemid; - + } + $ret = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'question_answers', $rec->glossaryentryid); - if( $ret != false) + if ($ret != false) { $rec->answerid = $ret->newitemid; - - $DB->update_record( 'game_queries', $rec); - } + } + + $DB->update_record( 'game_queries', $rec); + } } - //bookquiz + // Read bookquiz. $recs = $DB->get_records_select( 'game_bookquiz', 'id='.$gameid, null, '', 'id,lastchapterid'); - if( $recs != false){ - foreach( $recs as $rec){ + if ($recs != false) { + foreach ($recs as $rec) { $ret = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'book_chapters', $rec->lastchapterid); - if( $ret != false) + if ($ret != false) { $rec->lastchapterid = $ret->newitemid; - - $DB->update_record( 'game_bookquiz', $rec); - } + } + + $DB->update_record( 'game_bookquiz', $rec); + } } - - //bookquiz_chapters - $sql = "SELECT gbc.* FROM {game_bookquiz_chapters} gbc LEFT JOIN {game_attempts} a ON gbc.attemptid = a.id WHERE a.gameid=$gameid"; + + // 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){ + if ($recs != false) { + foreach ($recs as $rec) { $ret = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'book_chapters', $rec->chapterid); - if( $ret != false) + if ($ret != false) { $rec->chapterid = $ret->newitemid; - - $DB->update_record( 'game_bookquiz_chapter', $rec); - } - } + } + $DB->update_record( 'game_bookquiz_chapter', $rec); + } + } - //bookquiz_questions + // Read bookquiz_questions. $recs = $DB->get_records_select( 'game_bookquiz_questions', 'id='.$gameid, null, '', 'id,chapterid,questioncategoryid'); - if( $recs != false){ - foreach( $recs as $rec){ + if ($recs != false) { + foreach ($recs as $rec) { $ret = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'book_chapters', $rec->chapterid); - if( $ret != false) + if ($ret != false) { $rec->chapterid = $ret->newitemid; - + } + $ret = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'book_chapters', $rec->questioncategoryid); - if( $ret != false) + if ($ret != false) { $rec->questioncategoryid = $ret->newitemid; - - $DB->update_record( 'game_bookquiz_questions', $rec); - } + } + + $DB->update_record( 'game_bookquiz_questions', $rec); + } } - } } diff --git a/backup/moodle2/restore_game_stepslib.php b/backup/moodle2/restore_game_stepslib.php index fa976cb..ab9e20b 100755 --- a/backup/moodle2/restore_game_stepslib.php +++ b/backup/moodle2/restore_game_stepslib.php @@ -1,5 +1,4 @@ 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'); + $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_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'); @@ -54,50 +55,48 @@ class restore_game_activity_structure_step extends restore_activity_structure_st $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 the paths wrapped into standard activity structure. return $this->prepare_activity_structure($paths); } - + protected function process_game($data) { global $DB; - + $data = (object)$data; $oldid = $data->id; - $data->course = $this->get_courseid(); + $data->course = $this->get_courseid(); $data->timemodified = $this->apply_date_offset($data->timemodified); - - // insert the game record + + // Insert the game record. $newitemid = $DB->insert_record('game', $data); - - // immediately after inserting "activity" record, call this + + // Immediately after inserting "activity" record, call this. $this->apply_activity_instance($newitemid); } - + protected function process_game_export_html($data) { global $DB; - + $data = (object)$data; - + $data->id = $this->get_new_parentid('game'); - if( $data->id == 0) - return; - - $DB->insert_record('game_export_html', $data); + if ($data->id ! 0) { + $DB->insert_record('game_export_html', $data); + } } - + protected function process_game_export_javame($data) { global $DB; - + $data = (object)$data; - + $data->id = $this->get_new_parentid('game'); - if( $data->id == 0) - return; - - $DB->insert_record('game_export_javame', $data); - } - + if ($data->id != 0) { + $DB->insert_record('game_export_javame', $data); + } + } + protected function process_game_grade($data) { global $DB; @@ -109,7 +108,7 @@ class restore_game_activity_structure_step extends restore_activity_structure_st $DB->insert_record('game_grades', $data); } - + protected function process_game_repetition($data) { global $DB; @@ -118,10 +117,10 @@ class restore_game_activity_structure_step extends restore_activity_structure_st $data->gameid = $this->get_new_parentid('game'); $data->userid = $this->get_mappingid('user', $data->userid); - + $DB->insert_record('game_repetitions', $data); } - + protected function process_game_attempt($data) { global $DB; @@ -131,13 +130,16 @@ class restore_game_activity_structure_step extends restore_activity_structure_st $data->gameid = $this->get_new_parentid('game'); $data->userid = $this->get_mappingid('user', $data->userid); - if( !isset( $data->timestart)) + if (!isset( $data->timestart)) { $data->timestart = 0; - if( !isset( $data->timefinish)) + } + if (!isset( $data->timefinish)) { $data->timefinish = 0; - if( !isset( $data->timelastattempt)) - $data->timelastattempt = 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); @@ -145,7 +147,7 @@ class restore_game_activity_structure_step extends restore_activity_structure_st $newitemid = $DB->insert_record('game_attempts', $data); $this->set_mapping('game_attempt', $oldid, $newitemid); } - + protected function process_game_query($data) { global $DB; @@ -158,8 +160,8 @@ class restore_game_activity_structure_step extends restore_activity_structure_st $newitemid = $DB->insert_record('game_queries', $data); $this->set_mapping('game_query', $oldid, $newitemid); - } - + } + protected function process_game_bookquiz($data) { global $DB; @@ -168,7 +170,7 @@ class restore_game_activity_structure_step extends restore_activity_structure_st $data->id = $this->get_new_parentid('game'); $DB->insert_record('game_bookquiz', $data); - } + } protected function process_game_bookquiz_chapter($data) { global $DB; @@ -178,17 +180,17 @@ class restore_game_activity_structure_step extends restore_activity_structure_st $data->gameid = $this->get_new_parentid('game'); $DB->insert_record('game_bookquiz_chapters', $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); - } + } protected function process_game_cross($data) { global $DB; @@ -198,7 +200,7 @@ class restore_game_activity_structure_step extends restore_activity_structure_st $data->id = $this->get_new_parentid('game'); $DB->insert_record('game_cross', $data); - } + } protected function process_game_cryptex($data) { global $DB; @@ -208,7 +210,7 @@ class restore_game_activity_structure_step extends restore_activity_structure_st $data->id = $this->get_new_parentid('game'); $DB->insert_record('game_cryptex', $data); - } + } protected function process_game_hangman($data) { global $DB; @@ -219,7 +221,7 @@ class restore_game_activity_structure_step extends restore_activity_structure_st $data->queryid = $this->get_mappingid('game_query', $data->queryid); $DB->insert_record('game_hangman', $data); - } + } protected function process_game_hiddenpicture($data) { global $DB; @@ -229,7 +231,7 @@ class restore_game_activity_structure_step extends restore_activity_structure_st $data->id = $this->get_new_parentid('game'); $DB->insert_record('game_hiddenpicture', $data); - } + } protected function process_game_millionaire($data) { global $DB; @@ -240,9 +242,9 @@ class restore_game_activity_structure_step extends restore_activity_structure_st $data->queryid = $this->get_mappingid('game_query', $data->queryid); $DB->insert_record('game_millionaire', $data); - } - - protected function process_game_snake($data) { + } + + protected function process_game_snake($data) { global $DB; $data = (object)$data; @@ -252,7 +254,7 @@ class restore_game_activity_structure_step extends restore_activity_structure_st $DB->insert_record('game_snakes', $data); } - + protected function process_game_sudoku($data) { global $DB; @@ -262,9 +264,9 @@ class restore_game_activity_structure_step extends restore_activity_structure_st $DB->insert_record('game_sudoku', $data); } - + protected function after_execute() { - // Add Game related files, no need to match by itemname (just internally handled context) + // Add Game related files, no need to match by itemname (just internally handled context). $this->add_related_files('mod_game', 'snakes_file', null); $this->add_related_files('mod_game', 'snakes_board', null); } diff --git a/bookquiz/importodt.php b/bookquiz/importodt.php index e2907fa..28f3e72 100755 --- a/bookquiz/importodt.php +++ b/bookquiz/importodt.php @@ -1,4 +1,19 @@ -. + /** * This is a very rough importer for odt * @@ -10,60 +25,61 @@ * @package game **/ - require_once("../../../config.php"); - require_once( "../header.php"); - require_once("../locallib.php"); +require_once("../../../config.php"); +require_once( "../header.php"); +require_once("../locallib.php"); - $subchapter = optional_param('subchapter', '', PARAM_ALPHA); - $overwrite = optional_param('overwrite', 0, PARAM_INT); - $attempt = game_getattempt( $game, $detail); - $bookid = $game->bookid; - if( $bookid == 0){ - print_error( get_string( 'bookquiz_not_select_book', 'game')); - } +$subchapter = optional_param('subchapter', '', PARAM_ALPHA); +$overwrite = optional_param('overwrite', 0, PARAM_INT); +$attempt = game_getattempt( $game, $detail); +$bookid = $game->bookid; +if ($bookid == 0) { + print_error( get_string( 'bookquiz_not_select_book', 'game')); +} - if ($form = data_submitted()) - { /// Filename +if ($form = data_submitted()) { + // Filename. + if (empty($_FILES['newfile'])) { + // File was just uploaded. + notify(get_string("uploadproblem") ); + } - if (empty($_FILES['newfile'])) - { // file was just uploaded - notify(get_string("uploadproblem") ); - } + if ((!is_uploaded_file($_FILES['newfile']['tmp_name']) or $_FILES['newfile']['size'] == 0)) { + notify(get_string("uploadnofilefound") ); + } else { + // Valid file is found. + if (readdata( $course->id, 'game', $dirtemp, $rlevels, $rtitles, $rtexts, $dirfordelete)) { + // First try to reall all of the data in. + if ($overwrite) { + game_bookquiz_deletebook( $course->id, $bookid); + } + // Parse all the html files into objects. + $pageobjects = extract_data( $course->id, 'book', $bookid, $dirtemp, $subchapter, $rlevels, $rtitles, $rtexts); + clean_temp( $dirfordelete); // All done with files so dump em. - if ((!is_uploaded_file($_FILES['newfile']['tmp_name']) or $_FILES['newfile']['size'] == 0)) - { - notify(get_string("uploadnofilefound") ); - } else - { // Valid file is found - if ( readdata( $course->id, 'game', $dirtemp, $r_levels, $r_titles, $r_texts, $dirfordelete)) - { // first try to reall all of the data in - if( $overwrite){ - game_bookquiz_deletebook( $course->id, $bookid); - } - $pageobjects = extract_data( $course->id, 'book', $bookid, $dirtemp, $subchapter, $r_levels, $r_titles, $r_texts); // parse all the html files into objects - clean_temp( $dirfordelete); // all done with files so dump em - - $objects = game_bookquiz_create_objects( $pageobjects, $bookid); // function to preps the data to be sent to DB - - if( !game_bookquiz_save_objects($objects)) - { // sends it to DB - print_error('could not save'); - } - }else - print_error('could not get data'); + // Function to preps the data to be sent to DB. + $objects = game_bookquiz_create_objects( $pageobjects, $bookid); - print_continue("{$CFG->wwwroot}/mod/game/view.php?id=$cm->id"); - echo $OUTPUT->footer($course); - exit; + if (!game_bookquiz_save_objects( $objects)) { + // Sends it to DB. + print_error('could not save'); + } + } else { + print_error('could not get data'); } + + print_continue("{$CFG->wwwroot}/mod/game/view.php?id=$cm->id"); + echo $OUTPUT->footer($course); + exit; } +} - /// Print upload form +// Print upload form. print_heading_with_help( get_string( "bookquiz_import_odt", "game"), "importodt", "game"); echo $OUTPUT->box_start('center'); - ?> +?>