Skip to content

Commit

Permalink
Merge branch 'MDL-26778-master' of git://github.com/sammarshallou/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Apr 11, 2011
2 parents 72e97b5 + 6553cda commit 9ff913b
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 41 deletions.
10 changes: 10 additions & 0 deletions lib/completionlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down
7 changes: 4 additions & 3 deletions mod/chat/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -178,7 +182,4 @@
echo $OUTPUT->box_end();
}

$completion = new completion_info($course);
$completion->set_module_viewed($cm);

echo $OUTPUT->footer();
9 changes: 4 additions & 5 deletions mod/choice/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -168,8 +172,3 @@
}

echo $OUTPUT->footer();

/// Mark as viewed
$completion=new completion_info($course);
$completion->set_module_viewed($cm);

9 changes: 4 additions & 5 deletions mod/data/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();

8 changes: 4 additions & 4 deletions mod/feedback/complete.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -502,9 +506,5 @@
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////

// Mark activity viewed for completion-tracking
$completion=new completion_info($course);
$completion->set_module_viewed($cm);

echo $OUTPUT->footer();

7 changes: 5 additions & 2 deletions mod/forum/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -239,8 +243,7 @@

break;
}
$completion=new completion_info($course);
$completion->set_module_viewed($cm);

echo $OUTPUT->footer($course);


9 changes: 4 additions & 5 deletions mod/glossary/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down Expand Up @@ -495,8 +499,3 @@

/// Finish the page
echo $OUTPUT->footer();

/// Mark as viewed
$completion=new completion_info($course);
$completion->set_module_viewed($cm);

8 changes: 4 additions & 4 deletions mod/lesson/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -564,7 +568,3 @@
echo $lessoncontent;
echo $lessonoutput->footer();
}

/// Mark as viewed
$completion=new completion_info($course);
$completion->set_module_viewed($cm);
10 changes: 4 additions & 6 deletions mod/quiz/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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();
8 changes: 4 additions & 4 deletions mod/scorm/player.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down Expand Up @@ -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");
}
Expand Down
7 changes: 4 additions & 3 deletions mod/workshop/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -538,7 +542,4 @@
default:
}

$completion = new completion_info($course);
$completion->set_module_viewed($cm);

echo $output->footer();

0 comments on commit 9ff913b

Please sign in to comment.