From 6965f9f6c59ef56b0236820ace68bb2b71abd27d Mon Sep 17 00:00:00 2001 From: netw3rker Date: Fri, 14 Nov 2014 13:10:51 -0500 Subject: [PATCH] fix timestamps so that they accurately reflect when a completion happened. --- lib/completionlib.php | 24 +- mod/lesson/view.php | 10 +- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/lib/completionlib.php b/lib/completionlib.php index 2e83745..9f02db3 100644 --- a/lib/completionlib.php +++ b/lib/completionlib.php @@ -568,6 +568,10 @@ class completion_info { ($possibleresult == COMPLETION_COMPLETE && ($current->completionstate == COMPLETION_COMPLETE_PASS || $current->completionstate == COMPLETION_COMPLETE_FAIL))) { + // the state didn't change, but the timestamp needs to be updated with the new completion time + $current->timemodified = time(); + $this->internal_set_data($cm, $current); + return; } @@ -707,10 +711,28 @@ class completion_info { // OK, change state, save it, and update completion $data->viewed = COMPLETION_VIEWED; + $data->timemodified = time(); $this->internal_set_data($cm, $data); - $this->update_state($cm, COMPLETION_COMPLETE, $userid); } + public function set_module_completion($cm, $userid=0,$completion=COMPLETION_COMPLETE) { + global $PAGE; + if ($PAGE->headerprinted) { + debugging('set_module_viewed must be called before header is printed', + DEBUG_DEVELOPER); + } + + // Get current completion state + $data = $this->get_data($cm, false, $userid); + // OK, change state, save it, and update completion + // set the completion state. If already completed, just update the timestamp + $data->completionstate=$completion; + + $this->internal_set_data($cm, $data); + + $this->update_state($cm, $completion, $userid); + } + /** * Determines how much completion data exists for an activity. This is used when * deciding whether completion information should be 'locked' in the module diff --git a/mod/lesson/view.php b/mod/lesson/view.php index 0a008b9..7f9c27a 100644 --- a/mod/lesson/view.php +++ b/mod/lesson/view.php @@ -43,10 +43,15 @@ require_login($course, false, $cm); if ($backtocourse) { redirect(new moodle_url('/course/view.php', array('id'=>$course->id))); } - // Mark as viewed $completion = new completion_info($course); -$completion->set_module_viewed($cm); +$completion->set_module_viewed($cm, 0); + +if($pageid==LESSON_EOL){ + // Mark as potentially completed + $completion->set_module_completion($cm, 0); + +} $url = new moodle_url('/mod/lesson/view.php', array('id'=>$id)); if ($pageid !== null) { @@ -495,7 +500,6 @@ if ($pageid != LESSON_EOL) { $lessoncontent .= get_string("welldone", "lesson"); } } - // update central gradebook lesson_update_grades($lesson, $USER->id); -- 1.9.3 (Apple Git-50)