Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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 6553cda7c9b9d9ae5439a22841f7986c9b67bc36 1 parent 6b14adf
sam marshall sammarshallou authored
10 lib/completionlib.php
@@ -592,6 +592,9 @@ function internal_get_state($cm, $userid, $current) {
592 592 * Should be called whenever a module is 'viewed' (it is up to the module how to
593 593 * determine that). Has no effect if viewing is not set as a completion condition.
594 594 *
  595 + * Note that this function must be called before you print the page header because
  596 + * it is possible that the navigation block may depend on it. If you call it after
  597 + * printing the header, it shows a developer debug warning.
595 598 * @uses COMPLETION_VIEW_NOT_REQUIRED
596 599 * @uses COMPLETION_VIEWED
597 600 * @uses COMPLETION_COMPLETE
@@ -600,6 +603,11 @@ function internal_get_state($cm, $userid, $current) {
600 603 * @return void
601 604 */
602 605 public function set_module_viewed($cm, $userid=0) {
  606 + global $PAGE;
  607 + if ($PAGE->headerprinted) {
  608 + debugging('set_module_viewed must be called before header is printed',
  609 + DEBUG_DEVELOPER);
  610 + }
603 611 // Don't do anything if view condition is not turned on
604 612 if ($cm->completionview == COMPLETION_VIEW_NOT_REQUIRED || !$this->is_enabled($cm)) {
605 613 return;
@@ -932,6 +940,8 @@ function internal_set_data($cm, $data) {
932 940
933 941 if ($data->userid == $USER->id) {
934 942 $SESSION->completioncache[$cm->course][$cm->id] = $data;
  943 + $reset = 'reset';
  944 + get_fast_modinfo($reset);
935 945 }
936 946 }
937 947
7 mod/chat/view.php
@@ -79,6 +79,10 @@
79 79
80 80 $title = $course->shortname . ': ' . format_string($chat->name);
81 81
  82 +// Mark viewed by user (if required)
  83 +$completion = new completion_info($course);
  84 +$completion->set_module_viewed($cm);
  85 +
82 86 // Initialize $PAGE
83 87 $PAGE->set_url('/mod/chat/view.php', array('id' => $cm->id));
84 88 $PAGE->set_title($title);
@@ -178,7 +182,4 @@
178 182 echo $OUTPUT->box_end();
179 183 }
180 184
181   -$completion = new completion_info($course);
182   -$completion->set_module_viewed($cm);
183   -
184 185 echo $OUTPUT->footer();
9 mod/choice/view.php
@@ -50,6 +50,10 @@
50 50 $PAGE->set_title(format_string($choice->name));
51 51 $PAGE->set_heading($course->fullname);
52 52
  53 + // Mark viewed by user (if required)
  54 + $completion = new completion_info($course);
  55 + $completion->set_module_viewed($cm);
  56 +
53 57 /// Submit any new data if there is any
54 58 if (data_submitted() && is_enrolled($context, NULL, 'mod/choice:choose') && confirm_sesskey()) {
55 59 $timenow = time();
@@ -168,8 +172,3 @@
168 172 }
169 173
170 174 echo $OUTPUT->footer();
171   -
172   -/// Mark as viewed
173   - $completion=new completion_info($course);
174   - $completion->set_module_viewed($cm);
175   -
9 mod/data/view.php
@@ -289,6 +289,10 @@
289 289 $PAGE->requires->js('/mod/data/js.php?d='.$data->id, true);
290 290 }
291 291
  292 + // Mark as viewed
  293 + $completion = new completion_info($course);
  294 + $completion->set_module_viewed($cm);
  295 +
292 296 /// Print the page header
293 297 // Note: MDL-19010 there will be further changes to printing header and blocks.
294 298 // The code will be much nicer than this eventually.
@@ -730,11 +734,6 @@
730 734 if (($maxcount || $mode == 'asearch') && $mode != 'single') {
731 735 data_print_preference_form($data, $perpage, $search, $sort, $order, $search_array, $advanced, $mode);
732 736 }
733   -
734   -/// Mark as viewed
735   - $completion=new completion_info($course);
736   - $completion->set_module_viewed($cm);
737 737 }
738 738
739 739 echo $OUTPUT->footer();
740   -
8 mod/feedback/complete.php
@@ -121,6 +121,10 @@
121 121 print_error('error');
122 122 }
123 123
  124 + // Mark activity viewed for completion-tracking
  125 + $completion = new completion_info($course);
  126 + $completion->set_module_viewed($cm);
  127 +
124 128 /// Print the page header
125 129 $strfeedbacks = get_string("modulenameplural", "feedback");
126 130 $strfeedback = get_string("modulename", "feedback");
@@ -502,9 +506,5 @@
502 506 ///////////////////////////////////////////////////////////////////////////
503 507 ///////////////////////////////////////////////////////////////////////////
504 508
505   - // Mark activity viewed for completion-tracking
506   - $completion=new completion_info($course);
507   - $completion->set_module_viewed($cm);
508   -
509 509 echo $OUTPUT->footer();
510 510
7 mod/forum/view.php
@@ -97,6 +97,10 @@
97 97 rss_add_http_header($context, 'mod_forum', $forum, $rsstitle);
98 98 }
99 99
  100 + // Mark viewed if required
  101 + $completion = new completion_info($course);
  102 + $completion->set_module_viewed($cm);
  103 +
100 104 /// Print header.
101 105 /// Add ajax-related libs for ratings if required MDL-20119
102 106 $PAGE->requires->yui2_lib('event');
@@ -239,8 +243,7 @@
239 243
240 244 break;
241 245 }
242   - $completion=new completion_info($course);
243   - $completion->set_module_viewed($cm);
  246 +
244 247 echo $OUTPUT->footer($course);
245 248
246 249
9 mod/glossary/view.php
@@ -125,6 +125,10 @@
125 125 }
126 126 add_to_log($course->id, "glossary", "view", "view.php?id=$cm->id&tab=$tab", $glossary->id, $cm->id);
127 127
  128 +// Mark as viewed
  129 +$completion = new completion_info($course);
  130 +$completion->set_module_viewed($cm);
  131 +
128 132 /// stablishing flag variables
129 133 if ( $sortorder = strtolower($sortorder) ) {
130 134 if ($sortorder != 'asc' and $sortorder != 'desc') {
@@ -495,8 +499,3 @@
495 499
496 500 /// Finish the page
497 501 echo $OUTPUT->footer();
498   -
499   -/// Mark as viewed
500   -$completion=new completion_info($course);
501   -$completion->set_module_viewed($cm);
502   -
8 mod/lesson/view.php
@@ -45,6 +45,10 @@
45 45 redirect(new moodle_url('/course/view.php', array('id'=>$course->id)));
46 46 }
47 47
  48 +// Mark as viewed
  49 +$completion = new completion_info($course);
  50 +$completion->set_module_viewed($cm);
  51 +
48 52 $url = new moodle_url('/mod/lesson/view.php', array('id'=>$id));
49 53 if ($pageid !== null) {
50 54 $url->param('pageid', $pageid);
@@ -564,7 +568,3 @@
564 568 echo $lessoncontent;
565 569 echo $lessonoutput->footer();
566 570 }
567   -
568   -/// Mark as viewed
569   -$completion=new completion_info($course);
570   -$completion->set_module_viewed($cm);
10 mod/quiz/view.php
@@ -55,6 +55,10 @@
55 55 /// Log this request.
56 56 add_to_log($course->id, "quiz", "view", "view.php?id=$cm->id", $quiz->id, $cm->id);
57 57
  58 + // Mark module as viewed
  59 + $completion = new completion_info($course);
  60 + $completion->set_module_viewed($cm);
  61 +
58 62 /// Initialize $PAGE, compute blocks
59 63 $PAGE->set_url('/mod/quiz/view.php', array('id' => $cm->id));
60 64
@@ -382,10 +386,4 @@
382 386 }
383 387 echo $OUTPUT->box_end();
384 388
385   - // Mark module as viewed (note, we do this here and not in finish_page,
386   - // otherwise the 'not enrolled' error conditions would result in marking
387   - // 'viewed', I think it's better if they don't.)
388   - $completion=new completion_info($course);
389   - $completion->set_module_viewed($cm);
390   -
391 389 echo $OUTPUT->footer();
8 mod/scorm/player.php
@@ -146,6 +146,10 @@
146 146 $SESSION->scorm_mode = $mode;
147 147 $SESSION->scorm_attempt = $attempt;
148 148
  149 + // Mark module viewed
  150 + $completion = new completion_info($course);
  151 + $completion->set_module_viewed($cm);
  152 +
149 153 //
150 154 // Print the page header
151 155 //
@@ -249,10 +253,6 @@
249 253
250 254 $PAGE->requires->js_init_call('M.mod_scorm.init', array($scorm->hidenav, $scorm->hidetoc, $result->toctitle, $name, $sco->id));
251 255
252   -
253   -$completion=new completion_info($course);
254   -$completion->set_module_viewed($cm);
255   -
256 256 if (!empty($forcejs)) {
257 257 echo $OUTPUT->box(get_string("forcejavascriptmessage", "scorm"), "generalbox boxaligncenter forcejavascriptmessage");
258 258 }
7 mod/workshop/view.php
@@ -51,6 +51,10 @@
51 51 $workshop = new workshop($workshop, $cm, $course);
52 52 $workshop->log('view');
53 53
  54 +// Mark viewed
  55 +$completion = new completion_info($course);
  56 +$completion->set_module_viewed($cm);
  57 +
54 58 if (!is_null($editmode) && $PAGE->user_allowed_editing()) {
55 59 $USER->editing = $editmode;
56 60 }
@@ -538,7 +542,4 @@
538 542 default:
539 543 }
540 544
541   -$completion = new completion_info($course);
542   -$completion->set_module_viewed($cm);
543   -
544 545 echo $output->footer();

0 comments on commit 6553cda

Please sign in to comment.
Something went wrong with that request. Please try again.