Skip to content

Commit

Permalink
Removed mandatory IDataSource typehint
Browse files Browse the repository at this point in the history
  • Loading branch information
juniwalk committed Apr 20, 2017
1 parent 1e14669 commit ae8b03b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
12 changes: 9 additions & 3 deletions src/AggregationFunction/FunctionSum.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
namespace Ublaboo\DataGrid\AggregationFunction;

use DibiFluent;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\QueryBuilder;
use Nette\Utils\Strings;
use Ublaboo\DataGrid\DataSource\IDataSource;

final class FunctionSum implements IAggregationFunction
{
Expand Down Expand Up @@ -57,10 +57,10 @@ public function getFilterDataType()


/**
* @param IDataSource $dataSource
* @param mixed $dataSource
* @return void
*/
public function processDataSource(IDataSource $dataSource)
public function processDataSource($dataSource)
{
if ($dataSource instanceof DibiFluent) {
$connection = $dataSource->getConnection();
Expand All @@ -80,6 +80,12 @@ public function processDataSource(IDataSource $dataSource)
->getQuery()
->getSingleScalarResult();
}

if ($dataSource instanceof Collection) {
$dataSource->forAll(function ($key, $value) {
$this->result += $value->{$this->column};
});
}
}


Expand Down
6 changes: 2 additions & 4 deletions src/AggregationFunction/IAggregationFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

namespace Ublaboo\DataGrid\AggregationFunction;

use Ublaboo\DataGrid\DataSource\IDataSource;

interface IAggregationFunction
{
const DATA_TYPE_ALL = 'data_type_all';
Expand All @@ -23,10 +21,10 @@ interface IAggregationFunction
public function getFilterDataType();

/**
* @param IDataSource $dataSource
* @param mixed $dataSource
* @return void
*/
public function processDataSource(IDataSource $dataSource);
public function processDataSource($dataSource);

/**
* @return mixed
Expand Down
12 changes: 11 additions & 1 deletion src/DataSource/DoctrineCollectionDataSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@

use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
use Ublaboo\DataGrid\AggregationFunction\IAggregatable;
use Ublaboo\DataGrid\Filter;
use Ublaboo\DataGrid\Utils\DateTimeHelper;
use Ublaboo\DataGrid\Utils\Sorting;

final class DoctrineCollectionDataSource extends FilterableDataSource implements IDataSource
final class DoctrineCollectionDataSource extends FilterableDataSource implements IDataSource, IAggregatable
{

/**
Expand Down Expand Up @@ -261,4 +262,13 @@ public function sort(Sorting $sorting)
return $this;
}


/**
* @param callable $aggregationCallback
* @return void
*/
public function processAggregation(callable $aggregationCallback)
{
call_user_func($aggregationCallback, clone $this->data_source);
}
}

0 comments on commit ae8b03b

Please sign in to comment.