diff --git a/lib.php b/lib.php index 9aa9d28..4e8839a 100755 --- a/lib.php +++ b/lib.php @@ -1100,3 +1100,38 @@ function game_reset_userdata($data) { return $status; } +/** + * Obtains the automatic completion state for this module based on any conditions + * in game settings. + * + * @param object $course Course + * @param object $cm Course-module + * @param int $userid User ID + * @param bool $type Type of comparison (or/and; can be used as return value if no conditions) + * @return bool True if completed, false if not, $type if conditions not set. + */ +function game_get_completion_state($course, $cm, $userid, $type) { + global $CFG,$DB; + + require_once($CFG->dirroot . '/mod/game/locallib.php'); + + if( ($cm->completion == 0) or ($cm->completion == 1)){ + // Completion option is not enabled so just return $type. + return $type; + } + + if( $cm->completionview) + { + //Just want to view it. Not needed it + return true; + } + + if (! $game = $DB->get_record('game', array('id' => $cm->instance))) { + print_error('invalidcoursemodule'); + } + + $grade = $DB->get_record_select('game_grades', "userid=$userid AND gameid = $cm->instance", null, 'id,score'); + + return $grade && $grade->score > 0; +} + diff --git a/version.php b/version.php index c19751e..13bc9ed 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 = 2012122002; // The current module version (Date: YYYYMMDDXX) +$module->version = 2012122701; // 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 = 'v.2.12.20.2 (2012122002)'; +$module->release = 'v.2.12.27 (2012122701)'; diff --git a/view.php b/view.php index 2065b80..2fb2d27 100755 --- a/view.php +++ b/view.php @@ -50,6 +50,10 @@ /// Log this request. add_to_log($course->id, 'game', 'view', "view.php?id=$cm->id", $game->id, $cm->id); + // Mark as viewed + $completion=new completion_info($course); + $completion->set_module_viewed($cm); + /// Initialize $PAGE, compute blocks $PAGE->set_url('/mod/game/view.php', array('id' => $cm->id)); @@ -288,5 +292,5 @@ echo $OUTPUT->continue_button($CFG->wwwroot . '/course/view.php?id=' . $course->id); } echo $OUTPUT->box_end(); - + echo $OUTPUT->footer();