From 70708fd18aa2a5922fb890f84136fc11061aad29 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 26 Jul 2013 00:49:45 +0300 Subject: [PATCH] Fix: Show the correct number of attempts to a user --- db/install.xml | 401 +++++++++++++++++++++++++------------------------ db/upgrade.php | 17 ++- lib.php | 2 +- version.php | 4 +- view.php | 4 +- 5 files changed, 222 insertions(+), 206 deletions(-) diff --git a/db/install.xml b/db/install.xml index cf4206a..2bcf4a0 100755 --- a/db/install.xml +++ b/db/install.xml @@ -1,68 +1,69 @@ - - +
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
- +
- - - - - - - - - - - - - + + + + + + + + + + + + + @@ -71,44 +72,44 @@
- +
- - - - - + + + + + - - + +
- +
- - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + @@ -117,79 +118,79 @@
- +
- - - - - - - - - + + + + + + + + +
- +
- - - - - - - - - - - - + + + + + + + + + + + +
- +
- - + +
- +
- - - - + + + +
- +
- - - - - + + + + +
- +
- - - - + + + + @@ -198,20 +199,20 @@
- +
- - + +
- +
- - - + + + @@ -220,12 +221,12 @@
- +
- - - - + + + + @@ -234,113 +235,113 @@
- +
- - - - - - - - - - - + + + + + + + + + + +
- +
- - - - - - - - - + + + + + + + + +
- +
- - - - - + + + + +
- +
- - - - - - - - - - - - - + + + + + + + + + + + + +
- +
- - - + + +
- +
- - - - - + + + + +
- +
- - - - + + + +
- +
- - - - - - + + + + + + diff --git a/db/upgrade.php b/db/upgrade.php index f6a311d..7f7eedf 100755 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -1476,7 +1476,22 @@ function xmldb_game_upgrade($oldversion) { // game savepoint reached upgrade_mod_savepoint(true, 2011082604, 'game'); - } + } + + if ($oldversion < 2013072601) { + + // Define field timeclose to be added to game + $table = new xmldb_table('game'); + $field = new xmldb_field('maxattempts', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, null, null, '0', 'subcategories'); + + // Conditionally launch add field maxattempts + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + // game savepoint reached + upgrade_mod_savepoint(true, 2013072601, 'game'); + } return true; } diff --git a/lib.php b/lib.php index 2744c54..383705e 100755 --- a/lib.php +++ b/lib.php @@ -730,7 +730,7 @@ function game_get_extra_capabilities() { function game_num_attempt_summary($game, $cm, $returnzero = false, $currentgroup = 0) { global $CFG, $USER, $DB; - $numattempts = $DB->count_records('game_attempts', array('gameid'=> $game->id, 'preview'=>0)); + $numattempts = $DB->count_records('game_attempts', array('gameid'=> $game->id, 'preview'=>0));echo "num=$numattempts gameid=$game->id
"; if ($numattempts || $returnzero) { if (groups_get_activity_groupmode($cm)) { $a = new stdClass(); diff --git a/version.php b/version.php index 93cf48f..978993b 100755 --- a/version.php +++ b/version.php @@ -11,7 +11,7 @@ defined('MOODLE_INTERNAL') || die(); $module->component = 'mod_game'; // Full name of the plugin (used for diagnostics) -$module->version = 2013072501; // The current module version (Date: YYYYMMDDXX) +$module->version = 2013072601; // The current module version (Date: YYYYMMDDXX) $module->requires = 2010112400; // Requires Moodle 2.0 $module->cron = 0; // Period for cron to check this module (secs) -$module->release = '3.7.25'; +$module->release = '3.7.26'; diff --git a/view.php b/view.php index 7ed5fd3..536f647 100755 --- a/view.php +++ b/view.php @@ -90,10 +90,10 @@ /// Show number of attempts summary to those who can view reports. if (has_capability('mod/game:viewreports', $context)) { - if ($strattemptnum = game_num_attempt_summary($game, $cm)) { + if ($strattemptnum = game_get_user_attempts($game->id, $USER->id)) { //echo '\n"; - echo $strattemptnum; + echo get_string( 'attempts', 'game').': '.count( $strattemptnum); if( $game->maxattempts) { echo ' ('.get_string( 'max', 'quiz').': '.$game->maxattempts.')';