private function processAggregates($aggregates)
    {
        // Step 1. Calculate the aggregate group values.
        foreach ($this->collectionCursor as $model) {
            foreach ($aggregates as $aggregate) {
                $aggregate->calculateByIteration($model, $this->getGroupKeyForModel($model));
            }
        }

        $additionalData = [];

        // Step 2. Extract the group values and apply to models using augmentation data.
        foreach ($aggregates as $aggregate) {
            $groups = $aggregate->getGroups();

            foreach ($this->collectionCursor as $model) {
                $id = $model->UniqueIdentifier;
                $groupKey = $this->getGroupKeyForModel($model);

                if (!isset($additionalData[$id])) {
                    $additionalData[$id] = [];
                }

                if (isset($groups[$groupKey])) {
                    $additionalData[$id][$aggregate->getAlias()] = $groups[$groupKey];
                }
            }
        }

        // Give the cursor the augmentation data.
        $this->collectionCursor->setAugmentationData($additionalData);
    }
private function processAggregates($aggregates)
    {
        // Step 1. Calculate the aggregate group values.
        foreach ($this->collectionCursor as $model) {
            foreach ($aggregates as $aggregate) {
                $aggregate->calculateByIteration($model, $this->getGroupKeyForModel($model));
            }
        }

        $additionalData = [];

        // Step 2. Extract the group values and apply to models using augmentation data.
        foreach ($aggregates as $aggregate) {
            $groups = $aggregate->getGroups();

            foreach ($this->collectionCursor as $model) {
                $id = $model->UniqueIdentifier;
                $groupKey = $this->getGroupKeyForModel($model);

                if (!isset($additionalData[$id])) {
                    $additionalData[$id] = [];
                }

                if (isset($groups[$groupKey])) {
                    $additionalData[$id][$aggregate->getAlias()] = $groups[$groupKey];
                }
            }
        }

        // Give the cursor the augmentation data.
        $this->collectionCursor->setAugmentationData($additionalData);
    }
private function processAggregates ( $ aggregates ) { // Step 1. Calculate the aggregate group values. foreach ( $ this -> collectionCursor as $ model ) { foreach ( $ aggregates as $ aggregate ) { $ aggregate -> calculateByIteration ( $ model , $ this -> getGroupKeyForModel ( $ model ) ) ; } } $ additionalData = [ ] ; // Step 2. Extract the group values and apply to models using augmentation data. foreach ( $ aggregates as $ aggregate ) { $ groups = $ aggregate -> getGroups ( ) ; foreach ( $ this -> collectionCursor as $ model ) { $ id = $ model -> UniqueIdentifier ; $ groupKey = $ this -> getGroupKeyForModel ( $ model ) ; if ( ! isset ( $ additionalData [ $ id ] ) ) { $ additionalData [ $ id ] = [ ] ; } if ( isset ( $ groups [ $ groupKey ] ) ) { $ additionalData [ $ id ] [ $ aggregate -> getAlias ( ) ] = $ groups [ $ groupKey ] ; } } } // Give the cursor the augmentation data. $ this -> collectionCursor -> setAugmentationData ( $ additionalData ) ; }
Takes a collection of aggregate columns and calculates their value.

@param Aggregate[] $aggregates
Takes a collection of aggregate columns and calculates their value .