MDL-32103 completion: Allow instant completion updates.
For activity based course completion criteria allow instant course completion updates if the activity completion state was changed for a single user.
This commit is contained in:
@@ -101,6 +101,7 @@ class completion_completion extends data_object {
|
||||
* If the user is already marked as started, no change will occur
|
||||
*
|
||||
* @param integer $timeenrolled Time enrolled (optional)
|
||||
* @return int|null id of completion record on successful update.
|
||||
*/
|
||||
public function mark_enrolled($timeenrolled = null) {
|
||||
|
||||
@@ -122,6 +123,7 @@ class completion_completion extends data_object {
|
||||
* If the user is already marked as inprogress, the time will not be changed
|
||||
*
|
||||
* @param integer $timestarted Time started (optional)
|
||||
* @return int|null id of completion record on successful update.
|
||||
*/
|
||||
public function mark_inprogress($timestarted = null) {
|
||||
|
||||
@@ -149,14 +151,14 @@ class completion_completion extends data_object {
|
||||
* in the course are complete.
|
||||
*
|
||||
* @param integer $timecomplete Time completed (optional)
|
||||
* @return void
|
||||
* @return int|null id of completion record on successful update.
|
||||
*/
|
||||
public function mark_complete($timecomplete = null) {
|
||||
global $USER;
|
||||
|
||||
// Never change a completion time.
|
||||
if ($this->timecompleted) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
// Use current time if nothing supplied.
|
||||
@@ -166,7 +168,6 @@ class completion_completion extends data_object {
|
||||
|
||||
// Set time complete.
|
||||
$this->timecompleted = $timecomplete;
|
||||
|
||||
// Save record.
|
||||
if ($result = $this->_save()) {
|
||||
$data = $this->get_record_data();
|
||||
@@ -211,17 +212,16 @@ class completion_completion extends data_object {
|
||||
*
|
||||
* This method creates a course_completions record if none exists
|
||||
* @access private
|
||||
* @return bool
|
||||
* @return int|null id of completion record on successful update.
|
||||
*/
|
||||
private function _save() {
|
||||
if ($this->timeenrolled === null) {
|
||||
$this->timeenrolled = 0;
|
||||
}
|
||||
|
||||
$result = false;
|
||||
// Save record
|
||||
if ($this->id) {
|
||||
$result = $this->update();
|
||||
if (isset($this->id)) {
|
||||
$success = $this->update();
|
||||
} else {
|
||||
// Make sure reaggregate field is not null
|
||||
if (!$this->reaggregate) {
|
||||
@@ -233,17 +233,18 @@ class completion_completion extends data_object {
|
||||
$this->timestarted = 0;
|
||||
}
|
||||
|
||||
$result = $this->insert();
|
||||
$success = $this->insert();
|
||||
}
|
||||
|
||||
if ($result) {
|
||||
if ($success) {
|
||||
// Update the cached record.
|
||||
$cache = cache::make('core', 'coursecompletion');
|
||||
$data = $this->get_record_data();
|
||||
$key = $data->userid . '_' . $data->course;
|
||||
$cache->set($key, ['value' => $data]);
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
return $result;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user