public function can_apply_limit_rules() {
        if ($this->canapplylimitrules !== null) {
            return $this->canapplylimitrules;
        }

        // Set it to be supported by default.
        $this->canapplylimitrules = true;

        // Natural aggregation.
        if ($this->aggregation == GRADE_AGGREGATE_SUM) {
            $canapply = true;

            // Check until one child breaks the rules.
            $gradeitems = $this->get_children();
            $validitems = 0;
            $lastweight = null;
            $lastmaxgrade = null;
            foreach ($gradeitems as $gradeitem) {
                $gi = $gradeitem['object'];

                if ($gradeitem['type'] == 'category') {
                    // Sub categories are not allowed because they can have dynamic weights/maxgrades.
                    $canapply = false;
                    break;
                }

                if ($gi->aggregationcoef > 0) {
                    // Extra credit items are not allowed.
                    $canapply = false;
                    break;
                }

                if ($lastweight !== null && $lastweight != $gi->aggregationcoef2) {
                    // One of the weight differs from another item.
                    $canapply = false;
                    break;
                }

                if ($lastmaxgrade !== null && $lastmaxgrade != $gi->grademax) {
                    // One of the max grade differ from another item. This is not allowed for now
                    // because we could be end up with different max grade between users for this category.
                    $canapply = false;
                    break;
                }

                $lastweight = $gi->aggregationcoef2;
                $lastmaxgrade = $gi->grademax;
            }

            $this->canapplylimitrules = $canapply;
        }

        return $this->canapplylimitrules;
    }