diff --git a/src/AggregationFunction/FunctionSum.php b/src/AggregationFunction/FunctionSum.php index 348f70b2c..f708ec7ef 100644 --- a/src/AggregationFunction/FunctionSum.php +++ b/src/AggregationFunction/FunctionSum.php @@ -9,6 +9,9 @@ use Doctrine\ORM\QueryBuilder; use Nette\Database\Table\Selection; use Nette\Utils\Strings; +use Nextras\Orm\Collection\DbalCollection; +use Symfony\Component\ErrorHandler\Debug; +use Tracy\Debugger; use Ublaboo\DataGrid\Utils\PropertyAccessHelper; class FunctionSum implements ISingleColumnAggregationFunction @@ -51,7 +54,7 @@ public function getFilterDataType(): string /** - * @param Fluent|QueryBuilder|Collection|Selection $dataSource + * @param Fluent|QueryBuilder|Collection|Selection|DbalCollection $dataSource */ public function processDataSource($dataSource): void { @@ -82,6 +85,11 @@ public function processDataSource($dataSource): void return true; }); } + + if ( $dataSource instanceof DbalCollection) { + foreach( $dataSource->fetchAll() as $item ) + $this->result += $item->getValue( $this->column ); + } } diff --git a/src/DataSource/NextrasDataSource.php b/src/DataSource/NextrasDataSource.php index d497fd9fd..a68214a05 100755 --- a/src/DataSource/NextrasDataSource.php +++ b/src/DataSource/NextrasDataSource.php @@ -7,6 +7,8 @@ use Nette\Utils\Strings; use Nextras\Orm\Collection\Expression\LikeExpression; use Nextras\Orm\Collection\ICollection; +use Ublaboo\DataGrid\AggregationFunction\IAggregatable; +use Ublaboo\DataGrid\AggregationFunction\IAggregationFunction; use Ublaboo\DataGrid\Exception\DataGridDateTimeHelperException; use Ublaboo\DataGrid\Filter\FilterDate; use Ublaboo\DataGrid\Filter\FilterDateRange; @@ -19,7 +21,7 @@ use Ublaboo\DataGrid\Utils\Sorting; use UnexpectedValueException; -class NextrasDataSource extends FilterableDataSource implements IDataSource +class NextrasDataSource extends FilterableDataSource implements IDataSource, IAggregatable { /** @@ -341,4 +343,13 @@ private function prepareColumn(string $column): string return $column; } + + /** + * @param IAggregationFunction $function + * @return void + */ + public function processAggregation(IAggregationFunction $function): void + { + $function->processDataSource(clone $this->dataSource); + } }