From 5df3dcb12477a05a558d21c4fb6b3f6a3a70b1be Mon Sep 17 00:00:00 2001 From: Vasilis Daloukas Date: Tue, 26 Apr 2016 18:30:30 +0300 Subject: [PATCH] Use get_types or get_shortcuts depended on version of Moodle --- CHANGES.md | 4 + lib.php | 312 +++++++++++++++++++++++++++++++++++++--------------- version.php | 4 +- 3 files changed, 232 insertions(+), 88 deletions(-) mode change 100644 => 100755 CHANGES.md diff --git a/CHANGES.md b/CHANGES.md old mode 100644 new mode 100755 index f95d2c5..244d5a0 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,7 @@ +Changes in version 2016-04-26 (20160426) +---------------------------------------- +- Fix Use get_types or get_shortcuts depended on version of Moodle + Changes in version 2016-03-03 (20160302) ------------------------------------------------------------------ - New: Max compute time in crossword and cryptex diff --git a/lib.php b/lib.php index 077594e..c39e9ff 100755 --- a/lib.php +++ b/lib.php @@ -863,116 +863,256 @@ function game_extend_settings_navigation($settings, $gamenode) { } } -/** - * Returns an array of game type objects to construct - * menu list when adding new game - * - */ -function game_get_types() { - global $DB; - - $config = get_config('game'); +/* Returns an array of game type objects to construct + menu list when adding new game */ +require_once($CFG->dirroot.'/version.php'); +if ($branch >= '31') { + define('USE_GET_SHORTCUTS', '1'); +} - $types = array(); +if (!defined('USE_GET_SHORTCUTS')) { + function game_get_types() { + global $DB; - $type = new stdClass; - $type->modclass = MOD_CLASS_ACTIVITY; - $type->type = "game_group_start"; - $type->typestr = '--'.get_string( 'modulenameplural', 'game'); - $types[] = $type; + $config = get_config('game'); - $hide = ( isset( $config->hidehangman) ? ($config->hidehangman != 0) : false); + $types = array(); - if ($hide == false) { $type = new stdClass; $type->modclass = MOD_CLASS_ACTIVITY; - $type->type = "game&type=hangman"; - $type->typestr = get_string('game_hangman', 'game'); + $type->type = "game_group_start"; + $type->typestr = '--'.get_string( 'modulenameplural', 'game'); $types[] = $type; - } - if (isset( $config->hidecross)) { - $hide = ($config->hidecross != 0); - } else { - $hide = false; - } + $hide = ( isset( $config->hidehangman) ? ($config->hidehangman != 0) : false); - if ($hide == false) { - $type = new stdClass; - $type->modclass = MOD_CLASS_ACTIVITY; - $type->type = "game&type=cross"; - $type->typestr = get_string('game_cross', 'game'); - $types[] = $type; - } + if ($hide == false) { + $type = new stdClass; + $type->modclass = MOD_CLASS_ACTIVITY; + $type->type = "game&type=hangman"; + $type->typestr = get_string('game_hangman', 'game'); + $types[] = $type; + } - if (isset( $config->hidecryptex)) { - $hide = ($config->hidecryptex != 0); - } else { - $hide = false; - } + if (isset( $config->hidecross)) { + $hide = ($config->hidecross != 0); + } else { + $hide = false; + } - if ($hide == false) { - $type = new stdClass; - $type->modclass = MOD_CLASS_ACTIVITY; - $type->type = "game&type=cryptex"; - $type->typestr = get_string('game_cryptex', 'game'); - $types[] = $type; - } + if ($hide == false) { + $type = new stdClass; + $type->modclass = MOD_CLASS_ACTIVITY; + $type->type = "game&type=cross"; + $type->typestr = get_string('game_cross', 'game'); + $types[] = $type; + } - $hide = (isset( $config->hidemillionaire) ? ($config->hidemillionaire != 0) : false); - if ($hide == false) { - $type = new stdClass; - $type->modclass = MOD_CLASS_ACTIVITY; - $type->type = "game&type=millionaire"; - $type->typestr = get_string('game_millionaire', 'game'); - $types[] = $type; - } + if (isset( $config->hidecryptex)) { + $hide = ($config->hidecryptex != 0); + } else { + $hide = false; + } - $hide = (isset( $config->hidesudoku) ? ($config->hidesudoku != 0) : false); - if ($hide == false) { - $type = new stdClass; - $type->modclass = MOD_CLASS_ACTIVITY; - $type->type = "game&type=sudoku"; - $type->typestr = get_string('game_sudoku', 'game'); - $types[] = $type; - } + if ($hide == false) { + $type = new stdClass; + $type->modclass = MOD_CLASS_ACTIVITY; + $type->type = "game&type=cryptex"; + $type->typestr = get_string('game_cryptex', 'game'); + $types[] = $type; + } - $hide = (isset( $config->hidesnakes) ? ($config->hidesnakes != 0) : false); - if ($hide == false) { - $type = new stdClass; - $type->modclass = MOD_CLASS_ACTIVITY; - $type->type = "game&type=snakes"; - $type->typestr = get_string('game_snakes', 'game'); - $types[] = $type; - } + $hide = (isset( $config->hidemillionaire) ? ($config->hidemillionaire != 0) : false); + if ($hide == false) { + $type = new stdClass; + $type->modclass = MOD_CLASS_ACTIVITY; + $type->type = "game&type=millionaire"; + $type->typestr = get_string('game_millionaire', 'game'); + $types[] = $type; + } + + $hide = (isset( $config->hidesudoku) ? ($config->hidesudoku != 0) : false); + if ($hide == false) { + $type = new stdClass; + $type->modclass = MOD_CLASS_ACTIVITY; + $type->type = "game&type=sudoku"; + $type->typestr = get_string('game_sudoku', 'game'); + $types[] = $type; + } + + $hide = (isset( $config->hidesnakes) ? ($config->hidesnakes != 0) : false); + if ($hide == false) { + $type = new stdClass; + $type->modclass = MOD_CLASS_ACTIVITY; + $type->type = "game&type=snakes"; + $type->typestr = get_string('game_snakes', 'game'); + $types[] = $type; + } + + $hide = (isset( $config->hidehiddenpicture) ? ($config->hidehiddenpicture != 0) : false); + if ($hide == false) { + $type = new stdClass; + $type->modclass = MOD_CLASS_ACTIVITY; + $type->type = "game&type=hiddenpicture"; + $type->typestr = get_string('game_hiddenpicture', 'game'); + $types[] = $type; + } + + $hide = (isset( $config->hidebookquiz) ? ($config->hidebookquiz != 0) : false); + if ($hide == false) { + if ($DB->get_record( 'modules', array( 'name' => 'book'), 'id,id')) { + $type = new stdClass; + $type->modclass = MOD_CLASS_ACTIVITY; + $type->type = "game&type=bookquiz"; + $type->typestr = get_string('game_bookquiz', 'game'); + $types[] = $type; + } + } - $hide = (isset( $config->hidehiddenpicture) ? ($config->hidehiddenpicture != 0) : false); - if ($hide == false) { $type = new stdClass; $type->modclass = MOD_CLASS_ACTIVITY; - $type->type = "game&type=hiddenpicture"; - $type->typestr = get_string('game_hiddenpicture', 'game'); + $type->type = "game_group_end"; + $type->typestr = '--'; $types[] = $type; + + return $types; } +} - $hide = (isset( $config->hidebookquiz) ? ($config->hidebookquiz != 0) : false); - if ($hide == false) { - if ($DB->get_record( 'modules', array( 'name' => 'book'), 'id,id')) { +if (defined('USE_GET_SHORTCUTS')) { + /** + * Returns an array of game type objects to construct + * menu list when adding new game + * + */ + function game_get_shortcuts($defaultitem) { + global $DB, $CFG; + $config = get_config('game'); + $types = array(); + $hide = ( isset( $config->hidehangman) ? ($config->hidehangman != 0) : false); + if ($hide == false) { $type = new stdClass; - $type->modclass = MOD_CLASS_ACTIVITY; - $type->type = "game&type=bookquiz"; - $type->typestr = get_string('game_bookquiz', 'game'); + $type->archetype = MOD_CLASS_ACTIVITY; + $type->type = "game&type=hangman"; + $type->name = preg_replace('/.*type=/', '', $type->type); + $type->title = get_string('game_hangman', 'game'); + $type->link = new moodle_url($defaultitem->link, array('type' => $type->name)); + if (empty($type->help) && !empty($type->name) && + get_string_manager()->string_exists('help' . $type->name, 'game')) { + $type->help = get_string('help' . $type->name, 'game'); + } $types[] = $type; } + if (isset( $config->hidecross)) { + $hide = ($config->hidecross != 0); + } else { + $hide = false; + } + if ($hide == false) { + $type = new stdClass; + $type->archetype = MOD_CLASS_ACTIVITY; + $type->type = "game&type=cross"; + $type->name = preg_replace('/.*type=/', '', $type->type); + $type->title = get_string('game_cross', 'game'); + $type->link = new moodle_url($defaultitem->link, array('type' => $type->name)); + if (empty($type->help) && !empty($type->name) && + get_string_manager()->string_exists('help' . $type->name, 'game')) { + $type->help = get_string('help' . $type->name, 'game'); + } + $types[] = $type; + } + if (isset( $config->hidecryptex)) { + $hide = ($config->hidecryptex != 0); + } else { + $hide = false; + } + if ($hide == false) { + $type = new stdClass; + $type->archetype = MOD_CLASS_ACTIVITY; + $type->type = "game&type=cryptex"; + $type->title = get_string('game_cryptex', 'game'); + $type->name = preg_replace('/.*type=/', '', $type->type); + $type->link = new moodle_url($defaultitem->link, array('type' => $type->name)); + if (empty($type->help) && !empty($type->name) && + get_string_manager()->string_exists('help' . $type->name, 'game')) { + $type->help = get_string('help' . $type->name, 'game'); + } + $types[] = $type; + } + $hide = (isset( $config->hidemillionaire) ? ($config->hidemillionaire != 0) : false); + if ($hide == false) { + $type = new stdClass; + $type->archetype = MOD_CLASS_ACTIVITY; + $type->type = "game&type=millionaire"; + $type->title = get_string('game_millionaire', 'game'); + $type->name = preg_replace('/.*type=/', '', $type->type); + $type->link = new moodle_url($defaultitem->link, array('type' => $type->name)); + if (empty($type->help) && !empty($type->name) && + get_string_manager()->string_exists('help' . $type->name, 'game')) { + $type->help = get_string('help' . $type->name, 'game'); + } + $types[] = $type; + } + $hide = (isset( $config->hidesudoku) ? ($config->hidesudoku != 0) : false); + if ($hide == false) { + $type = new stdClass; + $type->archetype = MOD_CLASS_ACTIVITY; + $type->type = "game&type=sudoku"; + $type->title = get_string('game_sudoku', 'game'); + $type->name = preg_replace('/.*type=/', '', $type->type); + $type->link = new moodle_url($defaultitem->link, array('type' => $type->name)); + if (empty($type->help) && !empty($type->name) && + get_string_manager()->string_exists('help' . $type->name, 'game')) { + $type->help = get_string('help' . $type->name, 'game'); + } + $types[] = $type; + } + $hide = (isset( $config->hidesnakes) ? ($config->hidesnakes != 0) : false); + if ($hide == false) { + $type = new stdClass; + $type->archetype = MOD_CLASS_ACTIVITY; + $type->type = "game&type=snakes"; + $type->title = get_string('game_snakes', 'game'); + $type->name = preg_replace('/.*type=/', '', $type->type); + $type->link = new moodle_url($defaultitem->link, array('type' => $type->name)); + if (empty($type->help) && !empty($type->name) && + get_string_manager()->string_exists('help' . $type->name, 'game')) { + $type->help = get_string('help' . $type->name, 'game'); + } + $types[] = $type; + } + $hide = (isset( $config->hidehiddenpicture) ? ($config->hidehiddenpicture != 0) : false); + if ($hide == false) { + $type = new stdClass; + $type->archetype = MOD_CLASS_ACTIVITY; + $type->type = "game&type=hiddenpicture"; + $type->title = get_string('game_hiddenpicture', 'game'); + $type->name = preg_replace('/.*type=/', '', $type->type); + $type->link = new moodle_url($defaultitem->link, array('type' => $type->name)); + if (empty($type->help) && !empty($type->name) && + get_string_manager()->string_exists('help' . $type->name, 'game')) { + $type->help = get_string('help' . $type->name, 'game'); + } + $types[] = $type; + } + $hide = (isset( $config->hidebookquiz) ? ($config->hidebookquiz != 0) : false); + if ($hide == false) { + if ($DB->get_record( 'modules', array( 'name' => 'book'), 'id,id')) { + $type = new stdClass; + $type->archetype = MOD_CLASS_ACTIVITY; + $type->type = "game&type=bookquiz"; + $type->title = get_string('game_bookquiz', 'game'); + $type->name = preg_replace('/.*type=/', '', $type->type); + $type->link = new moodle_url($defaultitem->link, array('type' => $type->name)); + if (empty($type->help) && !empty($type->name) && + get_string_manager()->string_exists('help' . $type->name, 'game')) { + $type->help = get_string('help' . $type->name, 'game'); + } + $types[] = $type; + } + } + return $types; } - - $type = new stdClass; - $type->modclass = MOD_CLASS_ACTIVITY; - $type->type = "game_group_end"; - $type->typestr = '--'; - $types[] = $type; - - return $types; } function mod_game_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) { diff --git a/version.php b/version.php index 43dad29..711043b 100755 --- a/version.php +++ b/version.php @@ -36,10 +36,10 @@ if (!isset( $plugin)) { } $plugin->component = 'mod_game'; // Full name of the plugin (used for diagnostics). -$plugin->version = 2016031202; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2016042601; // 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 = '2016-03-12'; +$plugin->release = '2016-04-26'; if ($useplugin != 2) { $module = $plugin;