public function is_used() {
        global $DB;
        global $CFG;

        // count grade items excluding the
        $params = array($this->id);
        $sql = "SELECT COUNT(id) FROM {grade_items} WHERE scaleid = ? AND outcomeid IS NULL";
        if ($DB->count_records_sql($sql, $params)) {
            return true;
        }

        // count outcomes
        $sql = "SELECT COUNT(id) FROM {grade_outcomes} WHERE scaleid = ?";
        if ($DB->count_records_sql($sql, $params)) {
            return true;
        }

        // Ask the competency subsystem.
        if (\core_competency\api::is_scale_used_anywhere($this->id)) {
            return true;
        }

        // Ask all plugins if the scale is used anywhere.
        $pluginsfunction = get_plugins_with_function('scale_used_anywhere');
        foreach ($pluginsfunction as $plugintype => $plugins) {
            foreach ($plugins as $pluginfunction) {
                if ($pluginfunction($this->id)) {
                    return true;
                }
            }
        }

        return false;
    }