protected static function delete_user_competencies($userid) {
        global $DB;
        $usercontext = context_user::instance($userid);

        // Remove all the comments made on user competencies.
        \core_comment\privacy\provider::delete_comments_for_all_users($usercontext, 'competency', 'user_competency');

        // Find the user competency IDs.
        $ucids = $DB->get_fieldset_select(user_competency::TABLE, 'id', 'userid = :userid', ['userid' => $userid]);
        if (empty($ucids)) {
            return;
        }
        list($insql, $inparams) = $DB->get_in_or_equal($ucids, SQL_PARAMS_NAMED);

        // Delete all the evidence associated with competencies.
        $DB->delete_records_select(evidence::TABLE, "usercompetencyid $insql", $inparams);

        // Delete all the record of competency.
        $DB->delete_records_select(user_competency::TABLE, "id $insql", $inparams);
    }