There are several states of completion of the course
Settings→Course administration→Edit settings Completion tracking → 'Disabled, not shown in activity settings'
Database(DB): table 'mdl_course' field 'enablecompletion' is 0
Settings→Course administration→Edit settings Completion tracking → 'Enabled, control via…..'
DB: table 'mdl_course' field 'enablecompletion' is 1
DB: table 'mdl_course_completion_criteria' does not contain any records with 'course' = [concrete course id]
DB: table 'mdl_course_completion_criteria' contains record(s) with 'course' = [concrete course id]
DB: table 'mdl_course_completions' field 'timecompleted' != NULL
via php code:
$params = array( 'userid' => $user_id, 'course' => $course_id ); $ccompletion = new completion_completion($params); $ccompletion->is_complete();