public static function create_from_user_competency_viewed_in_course(user_competency_course $usercompetencycourse) {
        if (!$usercompetencycourse->get('id')) {
            throw new \coding_exception('The user competency course ID must be set.');
        }
        $params = array(
            'objectid' => $usercompetencycourse->get('id'),
            'relateduserid' => $usercompetencycourse->get('userid'),
            'other' => array(
                'competencyid' => $usercompetencycourse->get('competencyid')
            )
        );
        $coursecontext = context_course::instance($usercompetencycourse->get('courseid'));
        $params['contextid'] = $coursecontext->id;
        $params['courseid'] = $usercompetencycourse->get('courseid');

        $event = static::create($params);
        $event->add_record_snapshot(user_competency_course::TABLE, $usercompetencycourse->to_record());
        return $event;
    }