public function depends_on($reset_cache=false) {
        global $CFG, $DB;

        if ($reset_cache) {
            $this->dependson_cache = null;
        } else if (isset($this->dependson_cache)) {
            return $this->dependson_cache;
        }

        if ($this->is_locked()) {
            // locked items do not need to be regraded
            $this->dependson_cache = array();
            return $this->dependson_cache;
        }

        if ($this->is_calculated()) {
            if (preg_match_all('/##gi(\d+)##/', $this->calculation, $matches)) {
                $this->dependson_cache = array_unique($matches[1]); // remove duplicates
                return $this->dependson_cache;
            } else {
                $this->dependson_cache = array();
                return $this->dependson_cache;
            }

        } else if ($grade_category = $this->load_item_category()) {
            $params = array();

            //only items with numeric or scale values can be aggregated
            if ($this->gradetype != GRADE_TYPE_VALUE and $this->gradetype != GRADE_TYPE_SCALE) {
                $this->dependson_cache = array();
                return $this->dependson_cache;
            }

            $grade_category->apply_forced_settings();

            if (empty($CFG->enableoutcomes) or $grade_category->aggregateoutcomes) {
                $outcomes_sql = "";
            } else {
                $outcomes_sql = "AND gi.outcomeid IS NULL";
            }

            if (empty($CFG->grade_includescalesinaggregation)) {
                $gtypes = "gi.gradetype = ?";
                $params[] = GRADE_TYPE_VALUE;
            } else {
                $gtypes = "(gi.gradetype = ? OR gi.gradetype = ?)";
                $params[] = GRADE_TYPE_VALUE;
                $params[] = GRADE_TYPE_SCALE;
            }

            $params[] = $grade_category->id;
            $params[] = $this->courseid;
            $params[] = $grade_category->id;
            $params[] = $this->courseid;
            if (empty($CFG->grade_includescalesinaggregation)) {
                $params[] = GRADE_TYPE_VALUE;
            } else {
                $params[] = GRADE_TYPE_VALUE;
                $params[] = GRADE_TYPE_SCALE;
            }
            $sql = "SELECT gi.id
                      FROM {grade_items} gi
                     WHERE $gtypes
                           AND gi.categoryid = ?
                           AND gi.courseid = ?
                           $outcomes_sql
                    UNION

                    SELECT gi.id
                      FROM {grade_items} gi, {grade_categories} gc
                     WHERE (gi.itemtype = 'category' OR gi.itemtype = 'course') AND gi.iteminstance=gc.id
                           AND gc.parent = ?
                           AND gi.courseid = ?
                           AND $gtypes
                           $outcomes_sql";

            if ($children = $DB->get_records_sql($sql, $params)) {
                $this->dependson_cache = array_keys($children);
                return $this->dependson_cache;
            } else {
                $this->dependson_cache = array();
                return $this->dependson_cache;
            }

        } else {
            $this->dependson_cache = array();
            return $this->dependson_cache;
        }
    }