src/Titon/Db/Repository.php
public function aggregate(Query $query, $function, $field) {
        $query->fields(
            Query::func(strtoupper($function), [$field => Func::FIELD])->asAlias('aggregate')
        );

        $results = $this->getDriver()
            ->setContext('read')
            ->executeQuery($query)
            ->find();

        if (isset($results[0])) {
            return (int) $results[0]['aggregate'];
        }

        return 0;
    }
public function aggregate(Query $query, $function, $field) {
        $query->fields(
            Query::func(strtoupper($function), [$field => Func::FIELD])->asAlias('aggregate')
        );

        $results = $this->getDriver()
            ->setContext('read')
            ->executeQuery($query)
            ->find();

        if (isset($results[0])) {
            return (int) $results[0]['aggregate'];
        }

        return 0;
    }
public function aggregate ( Query $ query , $ function , $ field ) { $ query -> fields ( Query :: func ( strtoupper ( $ function ) , [ $ field => Func :: FIELD ] ) -> asAlias ( 'aggregate' ) ) ; $ results = $ this -> getDriver ( ) -> setContext ( 'read' ) -> executeQuery ( $ query ) -> find ( ) ; if ( isset ( $ results [ 0 ] ) ) { return ( int ) $ results [ 0 ] [ 'aggregate' ] ; } return 0 ; }
Perform an aggregation on the database and return the calculated value.
The currently supported aggregates are `avg`, `count`, `min`, `max`, and `sum`.

@param \Titon\Db\Query $query
@param string $function
@param string $field
@return int
Perform an aggregation on the database and return the calculated value . The currently supported aggregates are avg count min max and sum .