MDL-37361 completion: Enabled overriding activity completion status
This commit is contained in:
committed by
Jake Dallimore
parent
d8e9a23c48
commit
a39918daae
+20
-6
@@ -548,9 +548,10 @@ class completion_info {
|
||||
* result. For manual events, COMPLETION_COMPLETE or COMPLETION_INCOMPLETE
|
||||
* must be used; these directly set the specified state.
|
||||
* @param int $userid User ID to be updated. Default 0 = current user
|
||||
* @param bool $override Whether manually overriding the existing completion state.
|
||||
* @return void
|
||||
*/
|
||||
public function update_state($cm, $possibleresult=COMPLETION_UNKNOWN, $userid=0) {
|
||||
public function update_state($cm, $possibleresult=COMPLETION_UNKNOWN, $userid=0, $override = false) {
|
||||
global $USER;
|
||||
|
||||
// Do nothing if completion is not enabled for that activity
|
||||
@@ -569,8 +570,9 @@ class completion_info {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($cm->completion == COMPLETION_TRACKING_MANUAL) {
|
||||
// For manual tracking we set the result directly
|
||||
if ($cm->completion == COMPLETION_TRACKING_MANUAL || $override) {
|
||||
// For manual tracking, or if overriding the completion state manually,
|
||||
// we set the result directly.
|
||||
switch($possibleresult) {
|
||||
case COMPLETION_COMPLETE:
|
||||
case COMPLETION_INCOMPLETE:
|
||||
@@ -581,14 +583,22 @@ class completion_info {
|
||||
}
|
||||
|
||||
} else {
|
||||
// Automatic tracking; get new state
|
||||
$newstate = $this->internal_get_state($cm, $userid, $current);
|
||||
// Automatic tracking.
|
||||
if ($current->overrideby) {
|
||||
// If the current completion state has been set by override, do nothing
|
||||
// as we don't want it to be changed automatically.
|
||||
return;
|
||||
} else {
|
||||
// Get new state.
|
||||
$newstate = $this->internal_get_state($cm, $userid, $current);
|
||||
}
|
||||
}
|
||||
|
||||
// If changed, update
|
||||
if ($newstate != $current->completionstate) {
|
||||
$current->completionstate = $newstate;
|
||||
$current->timemodified = time();
|
||||
$current->overrideby = $override ? $USER->id : null;
|
||||
$this->internal_set_data($cm, $current);
|
||||
}
|
||||
}
|
||||
@@ -958,6 +968,7 @@ class completion_info {
|
||||
$data['userid'] = $userid;
|
||||
$data['completionstate'] = 0;
|
||||
$data['viewed'] = 0;
|
||||
$data['overrideby'] = null;
|
||||
$data['timemodified'] = 0;
|
||||
}
|
||||
$cacheddata[$othercm->id] = $data;
|
||||
@@ -980,6 +991,7 @@ class completion_info {
|
||||
$data['userid'] = $userid;
|
||||
$data['completionstate'] = 0;
|
||||
$data['viewed'] = 0;
|
||||
$data['overrideby'] = null;
|
||||
$data['timemodified'] = 0;
|
||||
}
|
||||
|
||||
@@ -1047,7 +1059,9 @@ class completion_info {
|
||||
'context' => $cmcontext,
|
||||
'relateduserid' => $data->userid,
|
||||
'other' => array(
|
||||
'relateduserid' => $data->userid
|
||||
'relateduserid' => $data->userid,
|
||||
'overrideby' => $data->overrideby,
|
||||
'completionstate' => $data->completionstate
|
||||
)
|
||||
));
|
||||
$event->add_record_snapshot('course_modules_completion', $data);
|
||||
|
||||
Reference in New Issue
Block a user