From 4184be8f11506a70a2f0dec9f0ed71060b37773a Mon Sep 17 00:00:00 2001 From: bdaloukas Date: Mon, 12 Jun 2017 07:28:21 +0300 Subject: [PATCH] phpdocs compatibility --- .../backup_game_activity_task.class.php | 74 ++++ backup/moodle2/backup_game_stepslib.php | 218 +++++++++++ .../restore_game_activity_task.class.php | 246 ++++++++++++ backup/moodle2/restore_game_stepslib.php | 363 ++++++++++++++++++ snakes/play.php | 111 +++++- sudoku/class.Sudoku.php | 126 +----- sudoku/create.php | 23 ++ sudoku/export.php | 3 + sudoku/play.php | 134 ++++++- sudoku/sdd/class.SDD.php | 13 - sudoku/sdd/class.logfile.php | 8 +- version.php | 4 +- 12 files changed, 1183 insertions(+), 140 deletions(-) create mode 100644 backup/moodle2/backup_game_activity_task.class.php create mode 100644 backup/moodle2/backup_game_stepslib.php create mode 100644 backup/moodle2/restore_game_activity_task.class.php create mode 100644 backup/moodle2/restore_game_stepslib.php diff --git a/backup/moodle2/backup_game_activity_task.class.php b/backup/moodle2/backup_game_activity_task.class.php new file mode 100644 index 0000000..b4fda95 --- /dev/null +++ b/backup/moodle2/backup_game_activity_task.class.php @@ -0,0 +1,74 @@ +. + +/** + * 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; + } +} diff --git a/backup/moodle2/backup_game_stepslib.php b/backup/moodle2/backup_game_stepslib.php new file mode 100644 index 0000000..f83f359 --- /dev/null +++ b/backup/moodle2/backup_game_stepslib.php @@ -0,0 +1,218 @@ +. + +/** + * 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); + } +} diff --git a/backup/moodle2/restore_game_activity_task.class.php b/backup/moodle2/restore_game_activity_task.class.php new file mode 100644 index 0000000..f121444 --- /dev/null +++ b/backup/moodle2/restore_game_activity_task.class.php @@ -0,0 +1,246 @@ +. + +/** + * @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); + } + } + } +} diff --git a/backup/moodle2/restore_game_stepslib.php b/backup/moodle2/restore_game_stepslib.php new file mode 100644 index 0000000..70d14a8 --- /dev/null +++ b/backup/moodle2/restore_game_stepslib.php @@ -0,0 +1,363 @@ +. + +/** + * 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); + } +} diff --git a/snakes/play.php b/snakes/play.php index 0555a6e..2ff7d01 100644 --- a/snakes/play.php +++ b/snakes/play.php @@ -14,8 +14,6 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -defined('MOODLE_INTERNAL') || die(); - /** * This files plays the game "Snakes and Ladders". * @@ -23,6 +21,17 @@ defined('MOODLE_INTERNAL') || die(); * @copyright 2007 Vasilis Daloukas * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +defined('MOODLE_INTERNAL') || die(); + +/** + * Plays the game "Snakes and Ladders". + * + * @param int $id + * @param stdClass $game + * @param stdClass $attempt + * @param stdClass $snakes + * @param stdClass $context + */ function game_snakes_continue( $id, $game, $attempt, $snakes, $context) { if ($attempt != false and $snakes != false) { return game_snakes_play( $id, $game, $attempt, $snakes, $context); @@ -50,6 +59,15 @@ function game_snakes_continue( $id, $game, $attempt, $snakes, $context) { return game_snakes_play( $id, $game, $attempt, $newrec, $context); } +/** + * Plays the game "Snakes and Ladders". + * + * @param int $id + * @param stdClass $game + * @param stdClass $attempt + * @param stdClass $snakes + * @param stdClass $context + */ function game_snakes_play( $id, $game, $attempt, $snakes, $context) { global $CFG, $DB, $OUTPUT; @@ -149,6 +167,12 @@ top:height / 3));?>px; "> position - 1) % $board->cols; $y = floor( ($snakes->position - 1) / $board->cols); @@ -178,6 +202,13 @@ function game_snakes_computeplayerposition( $snakes, $board) { return $pos; } +/** + * Computes next question. + * + * @param stdClass $game + * @param stdClass $snakes + * @param stdClass $quert + */ function game_snakes_computenextquestion( $game, &$snakes, &$query) { global $DB, $USER; @@ -235,6 +266,15 @@ function game_snakes_computenextquestion( $game, &$snakes, &$query) { return true; } +/** + * Shows the question. + * + * @param int $id + * @param stdClass $game + * @param stdClass $snakes + * @param stdClass $query + * @param stdClass $context + */ function game_snakes_showquestion( $id, $game, $snakes, $query, $context) { if ($query->sourcemodule == 'glossary') { game_snakes_showquestion_glossary( $id, $snakes, $query, $game); @@ -243,6 +283,15 @@ function game_snakes_showquestion( $id, $game, $snakes, $query, $context) { } } +/** + * Shows the question. + * + * @param stdClass $game + * @param $id + * @param stdClass $snakes + * @param stdClass $query + * @param stdClass $context + */ function game_snakes_showquestion_question( $game, $id, $snakes, $query, $context) { global $CFG; @@ -269,6 +318,14 @@ function game_snakes_showquestion_question( $game, $id, $snakes, $query, $contex echo "\n"; } +/** + * Show a glossary question. + * + * @param int $id + * @param stdClass $snakes + * @param stdClass $query + * @param stdClass $game + */ function game_snakes_showquestion_glossary( $id, $snakes, $query, $game) { global $CFG, $DB; @@ -301,6 +358,15 @@ function game_snakes_showquestion_glossary( $id, $snakes, $query, $game) { echo "\n"; } +/** + * Checks if answer is correct. + * + * @param int $id + * @param stdClass $game + * @param stdClass $attempt + * @param stdClass $snakes + * @param stdClass $context + */ function game_snakes_check_questions( $id, $game, $attempt, $snakes, $context) { global $CFG, $DB; @@ -337,6 +403,15 @@ function game_snakes_check_questions( $id, $game, $attempt, $snakes, $context) { game_snakes_position( $id, $game, $attempt, $snakes, $correct, $query, $context); } +/** + * Checks if the glossary answer is correct. + * + * @param int $id + * @param stdClass $game + * @param stdClass $attempt + * @param stdClass $snakes + * @param stdClass $context + */ function game_snakes_check_glossary( $id, $game, $attempt, $snakes, $context) { global $CFG, $DB; @@ -369,6 +444,18 @@ function game_snakes_check_glossary( $id, $game, $attempt, $snakes, $context) { game_snakes_position( $id, $game, $attempt, $snakes, $correct, $query, $context); } +/** + * Computes the position. + * + * @param int $id + * @param stdClass $game + * @param stdClass $attempt + * @param stdClass $snakes + * @param $correct + * @param stsdClass $correct + * @param stdClasss $query + * @param stdClass $context + */ function game_snakes_position( $id, $game, $attempt, $snakes, $correct, $query, $context) { global $DB; @@ -406,7 +493,12 @@ function game_snakes_position( $id, $game, $attempt, $snakes, $correct, $query, game_snakes_play( $id, $game, $attempt, $snakes, $context); } -// In lander go forward. +/** + * In lander go forward. + * + * @param int $position + * @param $data + */ function game_snakes_foundlander( $position, $data) { preg_match( "/L$position-([0-9]*)/", $data, $matches); @@ -417,7 +509,12 @@ function game_snakes_foundlander( $position, $data) { return 0; } -// In snake go backward. +/** + * In snake go backward. + * + * @param int $position + * @param $data + */ function game_snakes_foundsnake( $position, $data) { preg_match( "/S([0-9]*)-$position,/", $data.',', $matches); @@ -428,6 +525,12 @@ function game_snakes_foundsnake( $position, $data) { return 0; } +/** + * Removes attempt data. + * + * @param int $questionusageid + * @param int $questionid + */ function game_snakes_remove_attemptdata ($questionusageid, $questionid) { global $DB; diff --git a/sudoku/class.Sudoku.php b/sudoku/class.Sudoku.php index 02ed3d0..91a48cf 100644 --- a/sudoku/class.Sudoku.php +++ b/sudoku/class.Sudoku.php @@ -54,6 +54,14 @@ * attempting to distribute clues more optimally. */ +/** + * This class is used by Sudoku game. + * + * @package mod_game + * @copyright 2007 Vasilis Daloukas + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + defined('MOODLE_INTERNAL') || die(); @require_once("SDD/class.SDD.php"); @@ -97,7 +105,6 @@ class objects { /* * Deep copy anything. * - * @access public * @param array $theArray [optional] Something to be deep copied. Default is the current * ObjectS. * @return mixed The deep copy of the input. All references embedded within @@ -115,7 +122,6 @@ class objects { /** * @desc Debugging output interface. - * @access public * @param mixed $theValue The "thing" to be pretty printed. * @param boolean $theHTMLFlag True if the output will be seen in a browser, false otherwise. */ @@ -125,14 +131,16 @@ class objects { } } -/* +/** * The individual cell on the Sudoku board. * * These cells aren't restricted to 9x9 Sudoku (although pretty much everything else * at the moment). This class provides the state manipulation and searching capabilities * needed by the inference engine (class RCS). * - * @package Sudoku + * @package mod_game + * @copyright 2007 Vasilis Daloukas + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class cell extends objects { protected $r; @@ -171,7 +179,6 @@ class cell extends objects { * contents of the tuple removed. * * @desc apply a 23Tuple to a cell. - * @access public * @param array $aTuple the tuple to be eliminated. */ @@ -192,10 +199,8 @@ class cell extends objects { * For more details on the pair tuple algorithm, see RCS::_pairSolution. * * @desc Remove all values in the tuple, but only if the cell is a superset. - * @access public * @param array A tuple to be eliminated from the cell's state. */ - public function applytuple($atuple) { if (is_array($this->state)) { if (!$this->array_equal($atuple, $this->state)) { @@ -208,11 +213,9 @@ class cell extends objects { /** * @desc Return the string representation of the cell. - * @access public * @param boolean $theFlag true if the intermediate states of the cell are to be visible. * @return string */ - public function asstring($theflag = false) { if (is_array($this->state)) { if (($theflag) || (count($this->state) == 1)) { @@ -231,40 +234,32 @@ class cell extends objects { * Sudoku::_newSolvedPosition. * * @desc Assert pending solution. - * @access public - * @param integer $value The value for the solved position. +] * @param integer $value The value for the solved position. */ - public function flagsolvedposition($value) { $this->state = array($value => $value); } /* * @desc return the state of a cell. - * @access protected * @return mixed Either solved state or array of state pending solution. */ - public function &getstate() { return $this->state; } /* * @desc Has the state of this cell been applied to the board. - * @access public * @return boolean True if it has, false otherwise. Implies that IsSolved is true as well. */ - public function isapplied() { return $this->applied; } /* * @desc Has this cell been solved? - * @access public * @return boolean True if this cell has hit a single state. */ - public function issolved() { return !is_array($this->state); } @@ -274,12 +269,10 @@ class cell extends objects { * in the code. * * @desc Return information about the state of a cell. - * @access public * @return integer 0 => the cell has been solved. * 1 => the cell has been solved but not seen a solved. * 2 => the cell has not been solved. */ - public function solvedstate() { if (is_array($this->state)) { if (count($this->state) == 1) { @@ -299,11 +292,9 @@ class cell extends objects { * cell is promoted into the solved state. * * @desc Eliminate one or more values from the state information of the cell. - * @access public * @param mixed The value or values to be removed from the cell state. * @return boolean True if the cell state was modified, false otherwise. */ - public function un_set($thevalues) { if (is_array($thevalues)) { $thereturn = false; @@ -333,7 +324,6 @@ class cell extends objects { * * @package Sudoku */ - class rcs extends ObjectS { protected $theindex; @@ -346,7 +336,6 @@ class rcs extends ObjectS { /** * This * @desc Constructor - * @access public * @param string $theTag "Row", "Column", "Square", used primarily in debugging. * @param integer $theIndex 1..9, where is this on the board. Square are numbered top * left, ending bottom right @@ -378,7 +367,6 @@ class rcs extends ObjectS { * 9x9 Sudoku, they probably aren't of interested. * * @desc - * @access private * @return boolean True if a 23 solution exists and has been applied. */ @@ -447,7 +435,6 @@ class rcs extends ObjectS { /** * @desc apply a tuple to exclude items from within the row/column/square. * @param array $aTuple the tuple to be excluded. - * @access private * @return boolean true if anything changes. */ @@ -473,13 +460,11 @@ class rcs extends ObjectS { * the clue sets are substantially smaller than simple random placement. * * @desc Calculate the coupling for a cell within the row/column/square. - * @access abstract * @param integer $theRow the row coordinate on the board of the cell. * @param integer $theColumn the column coordinate on the board of the cell. * @return integer the degree of coupling between the cell and the rest of the cells * within the row/column/square. */ - public function coupling($therow, $thecolumn) { return 0; } @@ -492,13 +477,11 @@ class rcs extends ObjectS { * pair (generally) only 2. The unique solution adds no new information. * * @desc Run the inference engine for a row/column/square. - * @access public * @param array theRow A row/column/square data structure. * @param string theType A string merged with the standard headers during * intermediate solution printing. * @return boolean True when at least one inference has succeeded. */ - public function doaninference() { $this->theheader = null; @@ -514,7 +497,6 @@ class rcs extends ObjectS { * @param array Array of n size tuples. * @returns array of tuples that appear the same number of times as the size of the contents */ - public function _findtuples(&$thearray) { $thereturn = array(); for ($i = 0; $i < count($thearray); $i++) { @@ -545,10 +527,8 @@ class rcs extends ObjectS { /** * @desc Get a reference to the specified cell. - * @access public * @return reference to ObjectS of class Cell. */ - public function &getcell($i) { return $this->therow[$i]; } @@ -557,7 +537,6 @@ class rcs extends ObjectS { * @desc Get the header set by the last call to doAnInference. * */ - public function getheader() { return $this->theheader; } @@ -570,10 +549,8 @@ class rcs extends ObjectS { * me that these situations really occurred. * * @desc Eliminate tuple-locked alternatives. - * @access private * @return boolean True if something changed. */ - protected function _pairsolution() { $thecounts = array(); $thetuples = array(); @@ -649,10 +626,8 @@ class rcs extends ObjectS { * For example, if two cells must contain the values 5 or 6, then no other cell in that * row/column/square may contain those values, similarly for 3 cells, etc. * - * @access private * @return boolean True if one or more values in the RCS has changed state. */ - protected function _uniquesolution() { $theset = array(); @@ -703,11 +678,9 @@ class rcs extends ObjectS { /* * @desc Check to see if the RCS contains a valid state. - * @access public * @return boolean True if the state of the RCS could be part of a valid * solution, false otherwise. */ - public function validatesolution() { $thenewset = array(); @@ -729,10 +702,8 @@ class rcs extends ObjectS { * Only items that are actually solved are compared. This is used during puzzle * generation. * - * @access public * @return True if the input parameter contains a valid solution, false otherwise. */ - public function validatetrialsolution() { $thenewset = array(); @@ -753,11 +724,9 @@ class rcs extends ObjectS { * * @package Sudoku */ - class r extends rcs { /** * @desc Constructor - * @access public * @param string $theTag "Row", "Column", "Square", used primarily in debugging. * @param integer $theIndex 1..9, where is this on the board. Square are numbered top * left, ending bottom right @@ -768,7 +737,6 @@ class r extends rcs { /** * @see RCS::coupling */ - public function coupling($therow, $thecolumn) { return $thestate = $this->_coupling($thecolumn); } @@ -776,13 +744,11 @@ class r extends rcs { /** * @see RCS::coupling * @desc Heavy lifting for row/column coupling calculations. - * @access private * @param integer $theIndex the index of the cell within the row or column. * @return integer the "coupling coefficient" for the cell. The sum of the * sizes of the intersection between this and all other * cells in the row or column. */ - protected function _coupling($theindex) { $thecommonstate =& $this->getCell($theindex); $thecommonstate =& $thecommonstate->getstate(); @@ -807,11 +773,9 @@ class r extends rcs { * * @package Sudoku */ - class c extends r { /** * @desc Constructor - * @access public * @param string $theTag "Row", "Column", "Square", used primarily in debugging. * @param integer $theIndex 1..9, where is this on the board. Square are numbered top * left, ending bottom right @@ -833,14 +797,12 @@ class c extends r { * * @package Sudoku */ - class s extends rcs { /* * The cells within the 3x3 sudoku which participate in the coupling calculation for a square. * Remember that the missing cells have already participated in the row or column coupling * calculation. * - * @access private * @var array */ @@ -856,7 +818,6 @@ class s extends rcs { /** * @desc Constructor - * @access public * @param string $theTag "Row", "Column", "Square", used primarily in debugging. * @param integer $theIndex 1..9, where is this on the board. Square are numbered top * left, ending bottom right @@ -867,7 +828,6 @@ class s extends rcs { /** * @see RCS::coupling */ - public function coupling($therow, $thecolumn) { $theindex = ((($therow - 1) % 3) * 3) + (($thecolumn - 1) % 3) + 1; $thecommonstate =& $this->getcell($theindex); @@ -918,51 +878,40 @@ class s extends rcs { * @example ./example2.php * @example ./example3.php */ - class sudoku extends ObjectS { /* * An array of Cell ObjectSs, organized into rows and columns. * - * @access private * @var array of ObjectSs of type Cell. */ - protected $theboard = array(); /* * True if debugging output is to be provided during a run. * - * @access private * @var boolean */ - protected $thedebug = false; /* * An array of RCS ObjectSs, one ObjectS for each row. * - * @access private * @var ObjectS of type R */ - protected $therows = array(); /* * An array of RCS ObjectSs, one ObjectS for each Column. * - * @access private * @var ObjectS of type C */ - private $thecolumns = array(); /** * An array of RCS ObjectSs, one ObjectS for each square. * - * @access private * @var ObjectS of type S */ - protected $thesquares = array(); /* @@ -970,10 +919,8 @@ class sudoku extends ObjectS { * eventually be some use of theLevel to figure out where to stop * the backtrace when puzzle generation fails. * - * @access private * @var integer. */ - protected $thelevel = 0; /* @@ -983,10 +930,8 @@ class sudoku extends ObjectS { * a solution, it just might take a very long time. This is a way to * limit the damage before taking another guess. * - * @access private * @var integer. */ - protected $themaxiterations = 50; /* @@ -996,10 +941,8 @@ class sudoku extends ObjectS { * a couple of failures in a row, so this should be sufficient * to get a puzzle generated. * - * @access private * @var integer. */ - protected $thetrys = 10; /* @@ -1007,10 +950,8 @@ class sudoku extends ObjectS { * during puzzle generation. It the number gets above $theMaxIterations, * puzzle generation has failed and another try is made. * - * @access private * @var integer. */ - protected $thegenerationiterations = 0; public function init($thedebug = false) { @@ -1033,11 +974,9 @@ class sudoku extends ObjectS { * This applies the "negative" inference that no row, column, or square * containing the value within the cell. * - * @access private * @param integer $row The row of the board's element whose value is now fixed. * @param integer $col The column of the board's element whose value is now fixed. */ - protected function _applysolvedposition($row, $col) { $thevalue = $this->theboard[$row][$col]->getstate(); @@ -1057,11 +996,9 @@ class sudoku extends ObjectS { /* * @desc Apply all pending solved positions to the board. - * @access private * @return boolean True if at least one solved position was applied, false * otherwise. */ - protected function _applysolvedpositions() { $thereturn = false; @@ -1088,9 +1025,7 @@ class sudoku extends ObjectS { /* * @desc build the row/column/square structures for the board. - * @access private */ - protected function _buildrcs() { for ($i = 1; $i <= 9; $i++) { $this->therows[$i] = new r("Row", @@ -1139,11 +1074,9 @@ class sudoku extends ObjectS { * Given a solution, see if there are any alternates within the solution. * In theory this should return the "minimum" solution given any solution. * - * @access public * @param array $theInitialState (@see Sudoku::initializePuzzleFromArray) * @return array A set of triples containing the minimum solution. */ - public function findalternatesolution($theinitialstate) { $j = count($theinitialstate); @@ -1175,7 +1108,6 @@ class sudoku extends ObjectS { * a long time to force a solution, it's easier to probe for a solution * if you go "too long". * - * @access public * @param integer $theDifficultyLevel [optional] Since virtually everybody who * plays sudoku wants a variety of difficulties this controls that. * 1 is the easiest, 10 the most difficult. The easier Sudoku have @@ -1188,7 +1120,6 @@ class sudoku extends ObjectS { * @return array A set of triples suitable for initializing a new Sudoku class * (@see Sudoku::initializePuzzleFromArray). */ - public function generatepuzzle($thedifficultylevel = 10, $themaxiterations = 50, $thetrys = 10) { $thedifficultylevel = min($thedifficultylevel, 10); $thedifficultylevel = max($thedifficultylevel, 1); @@ -1271,7 +1202,6 @@ class sudoku extends ObjectS { * of iterations are asserted. Once these limits are passed, the generator gives up and * makes another try. If enough tries are made, the generator gives up entirely. * - * @access private * @param array $theAvailablePositions A set of pairs for all positions which have not been * filled by the solver or the set of guesses. When we run out of available * positions, the solution is in hand. @@ -1281,7 +1211,6 @@ class sudoku extends ObjectS { * @return array NULL array if no solution is possible, otherwise a set of triples * suitable for feeding to {@link Sudoku::initializePuzzleFromArray} */ - protected function _generatepuzzle($theavailablepositions, $thecluespositions, $theclues) { $this->thelevel++; @@ -1332,7 +1261,6 @@ class sudoku extends ObjectS { * of the work is likely to be associated with finding better algorithms to solve * Sudoku (which would have the effect of generating harder ones). */ - $thecouplings = array(); foreach ($theavailablepositions as $xxx) { @@ -1433,9 +1361,7 @@ class sudoku extends ObjectS { * has not yet been solved. * * @desc Get the current state of the board as a string. - * @access public */ - public function getboardasstring() { $thestring = ""; @@ -1456,10 +1382,8 @@ class sudoku extends ObjectS { * Each element of the input array is a triple consisting of (row, column, value). * Each of these values is in the range 1..9. * - * @access public * @param array $theArray */ - public function initializepuzzlefromarray($thearray) { foreach ($thearray as $xxx) { $c =& $this->getcell($xxx[0], $xxx[1]); @@ -1475,11 +1399,9 @@ class sudoku extends ObjectS { * 1..9. Input lines that are blank (all whitespace) or which begin with whitespace * followed by a "#" character are ignored. * - * @access public * @param mixed $theHandle [optional] defaults to STDIN. If a string is passed * instead of a file handle, the file is opened. */ - public function initializepuzzlefromfile($thehandle = STDIN) { $theopenedfileflag = false; @@ -1522,10 +1444,8 @@ class sudoku extends ObjectS { * are provide, the string is padded on the right. * * @desc Initialize puzzle from a string. - * @access public * @param string $theString The initial state of each cell in the puzzle. */ - public function initializepuzzlefromstring($thestring) { $thestring = str_pad($thestring, 81, " "); @@ -1540,10 +1460,8 @@ class sudoku extends ObjectS { /* * @desc predicate to determine if the current puzzle has been solved. - * @access public * @return boolean true if the puzzle has been solved. */ - public function issolved() { for ($i = 1; $i <= 9; $i++) { for ($j = 1; $j <= 9; $j++) { @@ -1562,10 +1480,8 @@ class sudoku extends ObjectS { * This step is actually unnecessary unless you want a pretty output of the * intermediate. * - * @access private * @return boolean True if at least on pending solution existed, false otherwise. */ - protected function _newsolvedposition() { $thereturn = false; @@ -1589,11 +1505,9 @@ class sudoku extends ObjectS { * * @see SudokuIntermediateSolution. * - * @access private * @param string $theHeader [optional] The header line to be output along * with the intermediate solution. */ - protected function _printintermediatesolution($theheader = null) { if ($this->thedebug) { $this->printsolution( $theheader); @@ -1606,11 +1520,9 @@ class sudoku extends ObjectS { * Simple output, is tailored by hand so that an initial state and * a solution will find nicely upon a single 8.5 x 11 page of paper. * - * @access public * @param mixed $theHeader [optional] The header line[s] to be output along * with the solution. */ - public function printsolution($theheader = null) { if (($this->thedebug) && ($theheader != null)) { if (is_array($theheader)) { @@ -1695,13 +1607,11 @@ class sudoku extends ObjectS { * During processing I explain which structures (row, column, square) * are being used to infer solutions. * - * @access public * @param boolean $theInitialStateFlag [optional] True if the initial * state of the board is to be printed upon entry, false * otherwise. [Default = true] * @return boolean true if a solution was possible, false otherwise. */ - public function solve($theinitialstateflag = true) { $theheader = "
Initial Position:"; @@ -1776,10 +1686,8 @@ class sudoku extends ObjectS { * straightforward and looks a lot like that of generatePuzzle. * * @desc Brute force additional solutions. - * @access public * @returns array The clues added sufficient to solve the puzzle. */ - public function solvebruteforce($i = 1, $j = 1) { for (; $i <= 9; $i++) { for (; $j <= 9; $j++) { @@ -1831,7 +1739,6 @@ class sudoku extends ObjectS { * @param integer $theColumn the column coordinate. * @return integer the square index in the range 1..9 */ - protected function _squareindex($therow, $thecolumn) { $theindex = ((int)(($therow - 1) / 3) * 3) + (int)(($thecolumn - 1) / 3) + 1; return $theindex; @@ -1844,11 +1751,9 @@ class sudoku extends ObjectS { * report any inconsistencies. This is primarily intended for debugging * purposes. * - * @access public * @return mixed true if the solution is valid, an array containing the * error details. */ - public function validatesolution() { $thereturn = array(); @@ -1872,10 +1777,8 @@ class sudoku extends ObjectS { * * Used during puzzle generation to determine when to backtrace. * - * @access private * @return True when the intermediate soltuion is valid, false otherwise. */ - protected function _validatetrialsolution() { for ($i = 1; $i <= 9; $i++) { if (!(($this->therows[$i]->validatetrialsolution()) && @@ -1896,7 +1799,6 @@ class sudoku extends ObjectS { * * @package Sudoku */ - class SudokuTemplates extends Sudoku { public function generatepuzzlefromfile($thehandle = STDIN, $thedifficultylevel = 10) { @@ -1923,7 +1825,6 @@ class SudokuTemplates extends Sudoku ** template cells, we construct the clues from the board and the ** input array before continuing to generate the puzzle. */ - foreach ($thearray as $thekey => $theposition) { $thetemplateclues[] = array($theposition[0], $theposition[1], $this->theboard[$theposition[0]][$theposition[1]]); } @@ -1939,7 +1840,6 @@ class SudokuTemplates extends Sudoku * * @package Sudoku */ - class sudokuintermediatesolution extends sudoku { public function sudokuintermediateresults($thedebug = false) { $this->sudoku($thedebug); diff --git a/sudoku/create.php b/sudoku/create.php index ad5f770..9b030af 100644 --- a/sudoku/create.php +++ b/sudoku/create.php @@ -57,6 +57,9 @@ function showform() { sourcemodule, $attempt, $numbers, $correctquestions); @@ -142,7 +163,14 @@ function game_sudoku_play( $id, $game, $attempt, $sudoku, $onlyshow, $showsoluti } } -// Returns a map with an offset and id of each question. +/** + * Returns a map with an offset and id of each question. + * + * @param $sourcemodule + * @param $attemp + * @param $numbers + * @param $correctquestions + */ function game_sudoku_compute_offsetquestions( $sourcemodule, $attempt, &$numbers, &$correctquestions) { global $CFG, $DB; @@ -179,6 +207,9 @@ function game_sudoku_compute_offsetquestions( $sourcemodule, $attempt, &$numbers return $offsetquestions; } +/** + * Select a sudoku randomly + */ function getrandomsudoku() { global $DB; @@ -203,6 +234,11 @@ function getrandomsudoku() { return false; } +/** + * Get closed + * + * @param $data + */ function game_sudoku_getclosed( $data) { $a = array(); @@ -217,6 +253,15 @@ function game_sudoku_getclosed( $data) { return $a; } +/** + * Shows the sudoku + * + * @param $data + * @param $guess + * @param boolean $bshowlegend + * @param boolean $bshowsolution + * @param $offsetquestions + */ function game_sudoku_showsudoku( $data, $guess, $bshowlegend, $bshowsolution, $offsetquestions, $correctquestions, $id, $attempt, $game) { global $CFG, $DB; @@ -319,6 +364,11 @@ function game_sudoku_showsudoku( $data, $guess, $bshowlegend, $bshowsolution, $o return $count; } +/** + * Get question list + * + * @param $offsetquestions + */ function game_sudoku_getquestionlist( $offsetquestions) { $questionlist = ''; foreach ($offsetquestions as $q) { @@ -335,6 +385,14 @@ function game_sudoku_getquestionlist( $offsetquestions) { return $questionlist; } +/** + * Get glossary entries + * + * @param $game + * @param $offsetentries + * @param $entrylist + * @param $numbers + */ function game_sudoku_getglossaryentries( $game, $offsetentries, &$entrylist, $numbers) { global $DB; @@ -352,6 +410,16 @@ function game_sudoku_getglossaryentries( $game, $offsetentries, &$entrylist, $nu return $entries; } +/** + * Plays the game hangman + * + * @param $id + * @param $game + * @param $attempt + * @param $sudoku + * @param $offsetquestions + * @param $numbers + */ function game_sudoku_showquestions_quiz( $id, $game, $attempt, $sudoku, $offsetquestions, $numbers, $correctquestions, $onlyshow, $showsolution, $context) { global $CFG; @@ -421,7 +489,16 @@ function game_sudoku_showquestions_quiz( $id, $game, $attempt, $sudoku, $offsetq } } -// Show the sudoku and glossaryentries. +/** + * Show the sudoku and glossaryentries. + * + * @param $id + * @param $game + * @param $attempt + * @param $sudoku + * @param $offsetentries + * @param $numbers + */ function game_sudoku_showquestions_glossary( $id, $game, $attempt, $sudoku, $offsetentries, $numbers, $correctentries, $onlyshow, $showsolution) { global $CFG; @@ -496,6 +573,14 @@ function game_sudoku_showquestions_glossary( $id, $game, $attempt, $sudoku, $off echo "\n"; } +/** + * Show question onfinish + * + * @param $id + * @param $game + * @param $attempt + * @param $sudoku + */ function game_sudoku_showquestion_onfinish( $id, $game, $attempt, $sudoku) { if (!set_field( 'game_attempts', 'finish', 1, 'id', $attempt->id)) { print_error( "game_sudoku_showquestion_onfinish: Can't update game_attempts id=$attempt->id"); @@ -508,12 +593,25 @@ function game_sudoku_showquestion_onfinish( $id, $game, $attempt, $sudoku) { echo "wwwroot}?id=$id\">".get_string( 'finish', 'game').' '; } +/** + * Check answers + */ function game_sudoku_checkanswers() { $responses = data_submitted(); $actions = question_extract_responses($questions, $responses, $event); } +/** + * Checks questions + * + * @param $id + * @param $game + * @param $attempt + * @param $sudoku + * @param $finishattempt + * @param $course + */ function game_sudoku_check_questions( $id, $game, $attempt, $sudoku, $finishattempt, $course) { global $DB; @@ -553,6 +651,16 @@ function game_sudoku_check_questions( $id, $game, $attempt, $sudoku, $finishatte game_sudoku_check_last( $id, $game, $attempt, $sudoku, $finishattempt, $course); } +/** + * Check glossary entries + * + * @param $id + * @param $game + * @param $attempt + * @param $sudoku + * @param $finishattempt + * @param $course + */ function game_sudoku_check_glossaryentries( $id, $game, $attempt, $sudoku, $finishattempt, $course) { global $DB; @@ -599,7 +707,16 @@ function game_sudoku_check_glossaryentries( $id, $game, $attempt, $sudoku, $fini return true; } -// This is the last function after submiting the answers. +/**This is the last function after submiting the answers. + * + * + * @param $id + * @param $game + * @param $attempt + * @param $sudoku + * @param $finishattempt + * @param $course + */ function game_sudoku_check_last( $id, $game, $attempt, $sudoku, $finishattempt, $course) { global $CFG, $DB; @@ -614,6 +731,17 @@ function game_sudoku_check_last( $id, $game, $attempt, $sudoku, $finishattempt, game_updateattempts( $game, $attempt, $grade, $finishattempt); } +/** + * Check number + * + * @param $id + * @param $game + * @param $attempt + * @param $sudoku + * @param $pos + * @param $num + * @param stdClass $context + */ function game_sudoku_check_number( $id, $game, $attempt, $sudoku, $pos, $num, $context) { global $DB; diff --git a/sudoku/sdd/class.SDD.php b/sudoku/sdd/class.SDD.php index 14be41c..307a2cf 100644 --- a/sudoku/sdd/class.SDD.php +++ b/sudoku/sdd/class.SDD.php @@ -52,7 +52,6 @@ class sdd { /* * Constructor. * - * @access public * @param boolean $theHTMLFlag [optional] True if HTML is to be generated. * If omitted, $_SERVER is used to "guess" the state of * the HTML flag. Be default, HTML is generated when @@ -73,7 +72,6 @@ class sdd { /* * Close the log file. * - * @access public * @abstract */ @@ -284,14 +282,12 @@ class sdd { /* * Write a debugging value to a log file. * - * @access public * @abstract * @param mixed Data to be logged. * @param string $theHeader [optional] string to be emitted prior to * logging the data. By default it is a date/time * stamp. */ - public function log(&$thedata, $theheader = null) { $theheader = date('[Y-m-d H:i:s]: ') . $theheader; @@ -317,9 +313,7 @@ class sdd { * @param integer [optional] the number of newlines. * @param boolean [optional] true if generating html newlines. * @return string newlines. - * @access public */ - public function newline($thecount = 1, $thehtmlflag = null) { if ($thehtmlflag === null) { if (empty($this)) { @@ -346,7 +340,6 @@ class sdd { * @param mixed $theVariable the variable to be dumped. * @param boolean $theHtmlFlag true if html is to be generated. */ - public function scalar(&$thevariable, $thehtmlflag) { if ($thehtmlflag) { return "
" . preg_replace('|<|s', '<', var_export($thevariable, true)) . "
"; @@ -358,13 +351,11 @@ class sdd { /* * Write data to the log file. * - * @access public * @abstract * @parameter string $theData [by reference] the data to be written * into the log file. * @return integer the number of bytes written into the log file. */ - public function writelog(&$thedata) { return strlen($this->m_log[] = $thedata); } @@ -372,10 +363,8 @@ class sdd { /* * Return the state of the logging flag. * - * @access public * @return boolean */ - public function getlogging() { return $this->m_logging; } @@ -383,10 +372,8 @@ class sdd { /* * Set the state of the logging flag. * - * @access public * @return boolean */ - public function setlogging($thelogging=false) { $this->m_logging = $thelogging; } diff --git a/sudoku/sdd/class.logfile.php b/sudoku/sdd/class.logfile.php index 29a2c61..ee9e302 100644 --- a/sudoku/sdd/class.logfile.php +++ b/sudoku/sdd/class.logfile.php @@ -44,10 +44,7 @@ class logfile extends SDD { /* * Constructor - * - * @access public */ - public function init($thefilename) { if (file_exists($thefilename)) { $this->m_handle = fopen($thefilename, 'a'); @@ -56,6 +53,9 @@ class logfile extends SDD { } } + /* + * close + */ public function close() { fclose($this->m_handle); } @@ -68,9 +68,7 @@ class logfile extends SDD { * @param mixed Data to be logged. * @return integer number of bytes written to the log. */ - public function log(&$thedata) { return fwrite($this->m_handle, date('[Y-m-d H:i:s]: ') . $this->dump($thedata) . "\n"); } } - diff --git a/version.php b/version.php index 71a38a2..cab0fe0 100644 --- a/version.php +++ b/version.php @@ -35,10 +35,10 @@ if (!isset( $plugin)) { } $plugin->component = 'mod_game'; // Full name of the plugin (used for diagnostics). -$plugin->version = 2017061101; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2017061201; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2010112400; // Requires Moodle 2.0. $plugin->cron = 0; // Period for cron to check this module (secs). -$plugin->release = '2017-06-11'; +$plugin->release = '2017-06-12'; if ($useplugin != 2) { $module = $plugin;