Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-26778 Change to completion should immediately affect nav block

Includes change so that updating completion resets the cache, and a debugging
warning if any module calls the completion viewed thing after it's already
printed navigation (which will mean navigation obviously doesn't update right
away). All existing modules that currently update after printing navigation
were updated.
  • Loading branch information...
commit c5e3a242b11a5b73e70fd90d9109766743f8a3a7 1 parent eb9d692
@sammarshallou sammarshallou authored
View
10 lib/completionlib.php
@@ -592,6 +592,9 @@ function internal_get_state($cm, $userid, $current) {
* Should be called whenever a module is 'viewed' (it is up to the module how to
* determine that). Has no effect if viewing is not set as a completion condition.
*
+ * Note that this function must be called before you print the page header because
+ * it is possible that the navigation block may depend on it. If you call it after
+ * printing the header, it shows a developer debug warning.
* @uses COMPLETION_VIEW_NOT_REQUIRED
* @uses COMPLETION_VIEWED
* @uses COMPLETION_COMPLETE
@@ -600,6 +603,11 @@ function internal_get_state($cm, $userid, $current) {
* @return void
*/
public function set_module_viewed($cm, $userid=0) {
+ global $PAGE;
+ if ($PAGE->headerprinted) {
+ debugging('set_module_viewed must be called before header is printed',
+ DEBUG_DEVELOPER);
+ }
// Don't do anything if view condition is not turned on
if ($cm->completionview == COMPLETION_VIEW_NOT_REQUIRED || !$this->is_enabled($cm)) {
return;
@@ -932,6 +940,8 @@ function internal_set_data($cm, $data) {
if ($data->userid == $USER->id) {
$SESSION->completioncache[$cm->course][$cm->id] = $data;
+ $reset = 'reset';
+ get_fast_modinfo($reset);
}
}
View
7 mod/chat/view.php
@@ -79,6 +79,10 @@
$title = $course->shortname . ': ' . format_string($chat->name);
+// Mark viewed by user (if required)
+$completion = new completion_info($course);
+$completion->set_module_viewed($cm);
+
// Initialize $PAGE
$PAGE->set_url('/mod/chat/view.php', array('id' => $cm->id));
$PAGE->set_title($title);
@@ -178,7 +182,4 @@
echo $OUTPUT->box_end();
}
-$completion = new completion_info($course);
-$completion->set_module_viewed($cm);
-
echo $OUTPUT->footer();
View
9 mod/choice/view.php
@@ -50,6 +50,10 @@
$PAGE->set_title(format_string($choice->name));
$PAGE->set_heading($course->fullname);
+ // Mark viewed by user (if required)
+ $completion = new completion_info($course);
+ $completion->set_module_viewed($cm);
+
/// Submit any new data if there is any
if (data_submitted() && is_enrolled($context, NULL, 'mod/choice:choose') && confirm_sesskey()) {
$timenow = time();
@@ -168,8 +172,3 @@
}
echo $OUTPUT->footer();
-
-/// Mark as viewed
- $completion=new completion_info($course);
- $completion->set_module_viewed($cm);
-
View
9 mod/data/view.php
@@ -289,6 +289,10 @@
$PAGE->requires->js('/mod/data/js.php?d='.$data->id, true);
}
+ // Mark as viewed
+ $completion = new completion_info($course);
+ $completion->set_module_viewed($cm);
+
/// Print the page header
// Note: MDL-19010 there will be further changes to printing header and blocks.
// The code will be much nicer than this eventually.
@@ -730,11 +734,6 @@
if (($maxcount || $mode == 'asearch') && $mode != 'single') {
data_print_preference_form($data, $perpage, $search, $sort, $order, $search_array, $advanced, $mode);
}
-
-/// Mark as viewed
- $completion=new completion_info($course);
- $completion->set_module_viewed($cm);
}
echo $OUTPUT->footer();
-
View
8 mod/feedback/complete.php
@@ -121,6 +121,10 @@
print_error('error');
}
+ // Mark activity viewed for completion-tracking
+ $completion = new completion_info($course);
+ $completion->set_module_viewed($cm);
+
/// Print the page header
$strfeedbacks = get_string("modulenameplural", "feedback");
$strfeedback = get_string("modulename", "feedback");
@@ -502,9 +506,5 @@
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
- // Mark activity viewed for completion-tracking
- $completion=new completion_info($course);
- $completion->set_module_viewed($cm);
-
echo $OUTPUT->footer();
View
7 mod/forum/view.php
@@ -97,6 +97,10 @@
rss_add_http_header($context, 'mod_forum', $forum, $rsstitle);
}
+ // Mark viewed if required
+ $completion = new completion_info($course);
+ $completion->set_module_viewed($cm);
+
/// Print header.
/// Add ajax-related libs for ratings if required MDL-20119
$PAGE->requires->yui2_lib('event');
@@ -239,8 +243,7 @@
break;
}
- $completion=new completion_info($course);
- $completion->set_module_viewed($cm);
+
echo $OUTPUT->footer($course);
View
9 mod/glossary/view.php
@@ -125,6 +125,10 @@
}
add_to_log($course->id, "glossary", "view", "view.php?id=$cm->id&tab=$tab", $glossary->id, $cm->id);
+// Mark as viewed
+$completion = new completion_info($course);
+$completion->set_module_viewed($cm);
+
/// stablishing flag variables
if ( $sortorder = strtolower($sortorder) ) {
if ($sortorder != 'asc' and $sortorder != 'desc') {
@@ -495,8 +499,3 @@
/// Finish the page
echo $OUTPUT->footer();
-
-/// Mark as viewed
-$completion=new completion_info($course);
-$completion->set_module_viewed($cm);
-
View
8 mod/lesson/view.php
@@ -45,6 +45,10 @@
redirect(new moodle_url('/course/view.php', array('id'=>$course->id)));
}
+// Mark as viewed
+$completion = new completion_info($course);
+$completion->set_module_viewed($cm);
+
$url = new moodle_url('/mod/lesson/view.php', array('id'=>$id));
if ($pageid !== null) {
$url->param('pageid', $pageid);
@@ -564,7 +568,3 @@
echo $lessoncontent;
echo $lessonoutput->footer();
}
-
-/// Mark as viewed
-$completion=new completion_info($course);
-$completion->set_module_viewed($cm);
View
10 mod/quiz/view.php
@@ -55,6 +55,10 @@
/// Log this request.
add_to_log($course->id, "quiz", "view", "view.php?id=$cm->id", $quiz->id, $cm->id);
+ // Mark module as viewed
+ $completion = new completion_info($course);
+ $completion->set_module_viewed($cm);
+
/// Initialize $PAGE, compute blocks
$PAGE->set_url('/mod/quiz/view.php', array('id' => $cm->id));
@@ -382,10 +386,4 @@
}
echo $OUTPUT->box_end();
- // Mark module as viewed (note, we do this here and not in finish_page,
- // otherwise the 'not enrolled' error conditions would result in marking
- // 'viewed', I think it's better if they don't.)
- $completion=new completion_info($course);
- $completion->set_module_viewed($cm);
-
echo $OUTPUT->footer();
View
8 mod/scorm/player.php
@@ -146,6 +146,10 @@
$SESSION->scorm_mode = $mode;
$SESSION->scorm_attempt = $attempt;
+ // Mark module viewed
+ $completion = new completion_info($course);
+ $completion->set_module_viewed($cm);
+
//
// Print the page header
//
@@ -249,10 +253,6 @@
$PAGE->requires->js_init_call('M.mod_scorm.init', array($scorm->hidenav, $scorm->hidetoc, $result->toctitle, $name, $sco->id));
-
-$completion=new completion_info($course);
-$completion->set_module_viewed($cm);
-
if (!empty($forcejs)) {
echo $OUTPUT->box(get_string("forcejavascriptmessage", "scorm"), "generalbox boxaligncenter forcejavascriptmessage");
}
View
7 mod/workshop/view.php
@@ -51,6 +51,10 @@
$workshop = new workshop($workshop, $cm, $course);
$workshop->log('view');
+// Mark viewed
+$completion = new completion_info($course);
+$completion->set_module_viewed($cm);
+
if (!is_null($editmode) && $PAGE->user_allowed_editing()) {
$USER->editing = $editmode;
}
@@ -538,7 +542,4 @@
default:
}
-$completion = new completion_info($course);
-$completion->set_module_viewed($cm);
-
echo $output->footer();
Please sign in to comment.
Something went wrong with that request. Please try again.