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

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

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

        // Delete all the competencies proficiency in the plans.
        $DB->delete_records_select(user_competency_plan::TABLE, "planid $insql", $inparams);

        // Delete all the competencies in the plans.
        $DB->delete_records_select(plan_competency::TABLE, "planid $insql", $inparams);

        // Delete all the plans.
        $DB->delete_records_select(plan::TABLE, "id $insql", $inparams);
    }