public static function observe_course_completed(\core\event\course_completed $event) {
        if (!static::is_enabled()) {
            return;
        }

        $sql = 'courseid = :courseid AND ruleoutcome != :nooutcome';
        $params = array(
            'courseid' => $event->courseid,
            'nooutcome' => course_competency::OUTCOME_NONE
        );
        $coursecompetencies = course_competency::get_records_select($sql, $params);

        $course = get_course($event->courseid);
        $courseshortname = format_string($course->shortname, null, array('context' => $event->contextid));

        foreach ($coursecompetencies as $coursecompetency) {

            $outcome = $coursecompetency->get('ruleoutcome');
            $action = null;
            $recommend = false;
            $strdesc = 'evidence_coursecompleted';

            if ($outcome == course_competency::OUTCOME_EVIDENCE) {
                $action = evidence::ACTION_LOG;

            } else if ($outcome == course_competency::OUTCOME_RECOMMEND) {
                $action = evidence::ACTION_LOG;
                $recommend = true;

            } else if ($outcome == course_competency::OUTCOME_COMPLETE) {
                $action = evidence::ACTION_COMPLETE;

            } else {
                throw new moodle_exception('Unexpected rule outcome: ' + $outcome);
            }

            static::add_evidence(
                $event->relateduserid,
                $coursecompetency->get('competencyid'),
                $event->contextid,
                $action,
                $strdesc,
                'core_competency',
                $courseshortname,
                $recommend,
                $event->get_url()
            );
        }
    }
public static function observe_course_completed(\core\event\course_completed $event) {
        if (!static::is_enabled()) {
            return;
        }

        $sql = 'courseid = :courseid AND ruleoutcome != :nooutcome';
        $params = array(
            'courseid' => $event->courseid,
            'nooutcome' => course_competency::OUTCOME_NONE
        );
        $coursecompetencies = course_competency::get_records_select($sql, $params);

        $course = get_course($event->courseid);
        $courseshortname = format_string($course->shortname, null, array('context' => $event->contextid));

        foreach ($coursecompetencies as $coursecompetency) {

            $outcome = $coursecompetency->get('ruleoutcome');
            $action = null;
            $recommend = false;
            $strdesc = 'evidence_coursecompleted';

            if ($outcome == course_competency::OUTCOME_EVIDENCE) {
                $action = evidence::ACTION_LOG;

            } else if ($outcome == course_competency::OUTCOME_RECOMMEND) {
                $action = evidence::ACTION_LOG;
                $recommend = true;

            } else if ($outcome == course_competency::OUTCOME_COMPLETE) {
                $action = evidence::ACTION_COMPLETE;

            } else {
                throw new moodle_exception('Unexpected rule outcome: ' + $outcome);
            }

            static::add_evidence(
                $event->relateduserid,
                $coursecompetency->get('competencyid'),
                $event->contextid,
                $action,
                $strdesc,
                'core_competency',
                $courseshortname,
                $recommend,
                $event->get_url()
            );
        }
    }
public static function observe_course_completed ( \ core \ event \ course_completed $ event ) { if ( ! static :: is_enabled ( ) ) { return ; } $ sql = 'courseid = :courseid AND ruleoutcome != :nooutcome' ; $ params = array ( 'courseid' => $ event -> courseid , 'nooutcome' => course_competency :: OUTCOME_NONE ) ; $ coursecompetencies = course_competency :: get_records_select ( $ sql , $ params ) ; $ course = get_course ( $ event -> courseid ) ; $ courseshortname = format_string ( $ course -> shortname , null , array ( 'context' => $ event -> contextid ) ) ; foreach ( $ coursecompetencies as $ coursecompetency ) { $ outcome = $ coursecompetency -> get ( 'ruleoutcome' ) ; $ action = null ; $ recommend = false ; $ strdesc = 'evidence_coursecompleted' ; if ( $ outcome == course_competency :: OUTCOME_EVIDENCE ) { $ action = evidence :: ACTION_LOG ; } else if ( $ outcome == course_competency :: OUTCOME_RECOMMEND ) { $ action = evidence :: ACTION_LOG ; $ recommend = true ; } else if ( $ outcome == course_competency :: OUTCOME_COMPLETE ) { $ action = evidence :: ACTION_COMPLETE ; } else { throw new moodle_exception ( 'Unexpected rule outcome: ' + $ outcome ) ; } static :: add_evidence ( $ event -> relateduserid , $ coursecompetency -> get ( 'competencyid' ) , $ event -> contextid , $ action , $ strdesc , 'core_competency' , $ courseshortname , $ recommend , $ event -> get_url ( ) ) ; } }
Observe when a course is marked as completed.

Note that the user being logged in while this happens may be anyone.
Do not rely on capability checks here!

@param  \core\event\course_completed $event
@return void
Observe when a course is marked as completed .