public function calculation($type, $query, array $options = []) {
		$query->calculate($type);

		switch ($type) {
			case 'count':
				if (strpos($fields = $this->fields($query->fields(), $query), ',') !== false) {
					$fields = "*";
				}
				$query->fields("COUNT({$fields}) as count", true);
				$query->map([$query->alias() => ['count']]);

				$result = $this->read($query, $options)->data();

				if (!$result || !isset($result[0]['count'])) {
					return null;
				}
				return (integer) $result[0]['count'];
		}
	}
public function calculation($type, $query, array $options = []) {
		$query->calculate($type);

		switch ($type) {
			case 'count':
				if (strpos($fields = $this->fields($query->fields(), $query), ',') !== false) {
					$fields = "*";
				}
				$query->fields("COUNT({$fields}) as count", true);
				$query->map([$query->alias() => ['count']]);

				$result = $this->read($query, $options)->data();

				if (!$result || !isset($result[0]['count'])) {
					return null;
				}
				return (integer) $result[0]['count'];
		}
	}
public function calculation ( $ type , $ query , array $ options = [ ] ) { $ query -> calculate ( $ type ) ; switch ( $ type ) { case 'count' : if ( strpos ( $ fields = $ this -> fields ( $ query -> fields ( ) , $ query ) , ',' ) !== false ) { $ fields = "*" ; } $ query -> fields ( "COUNT({$fields}) as count" , true ) ; $ query -> map ( [ $ query -> alias ( ) => [ 'count' ] ] ) ; $ result = $ this -> read ( $ query , $ options ) -> data ( ) ; if ( ! $ result || ! isset ( $ result [ 0 ] [ 'count' ] ) ) { return null ; } return ( integer ) $ result [ 0 ] [ 'count' ] ; } }
Executes calculation-related queries, such as those required for `count` and other
aggregates.

When building `count` queries and a single field is given, will use that to build
the `COUNT()` fragment. When multiple fields are given forces a `COUNT(*)`.

@param string $type Only accepts `count`.
@param mixed $query The query to be executed.
@param array $options Optional arguments for the `read()` query that will be executed
to obtain the calculation result.
@return integer|null Result of the calculation or `null` if the calculation failed.
Executes calculation - related queries such as those required for count and other aggregates .