X-Git-Url: http://git.moodle.org/gw?p=moodle.git;a=blobdiff_plain;f=lib%2Fcompletion%2Fcompletion_completion.php;h=67377894116865da515cab0106c47398052675d8;hp=82903a90c5aa66c8c953469f2a01386bfa453820;hb=3c63deb9a0a00fb4867e482c4aed8ab044778e34;hpb=2be4d090c0c0b5d09aa6140e9348fb65d20263d6 diff --git a/lib/completion/completion_completion.php b/lib/completion/completion_completion.php index 82903a90c5a..67377894116 100644 --- a/lib/completion/completion_completion.php +++ b/lib/completion/completion_completion.php @@ -138,9 +138,9 @@ class completion_completion extends data_object { */ public function mark_enrolled($timeenrolled = null) { - if (!$this->timeenrolled) { + if ($this->timeenrolled === null) { - if (!$timeenrolled) { + if ($timeenrolled === null) { $timeenrolled = time(); } @@ -219,15 +219,8 @@ class completion_completion extends data_object { global $DB; - if (!$this->timeenrolled) { - // Get users timenrolled - // Can't find a more efficient way of doing this without alter get_users_by_capability() - $context = get_context_instance(CONTEXT_COURSE, $this->course); - if ($roleassignment = $DB->get_record('role_assignments', array('contextid' => $context->id, 'userid' => $this->userid))) { - $this->timeenrolled = $roleassignment->timestart; - } else { - $this->timeenrolled = 0; - } + if ($this->timeenrolled === null) { + $this->timeenrolled = 0; } // Save record @@ -239,6 +232,11 @@ class completion_completion extends data_object { $this->reaggregate = 0; } + // Make sure timestarted is not null + if (!$this->timestarted) { + $this->timestarted = 0; + } + $this->insert(); } }