diff --git a/composer.json b/composer.json index 2493fcb..d1c3e93 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "hanaboso/data-grid", "license": "proprietary", - "version": "2.1.1", + "version": "2.1.2", "description": "Data grid", "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index 166c489..f0d30a8 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c75be27c0e47e358097e364d003cc642", + "content-hash": "65d3e297c520fd55e2cb54f3199a58b4", "packages": [ { "name": "beberlei/doctrineextensions", @@ -962,16 +962,16 @@ }, { "name": "hanaboso/utils", - "version": "1.0.6", + "version": "1.0.7", "source": { "type": "git", "url": "https://github.com/hanaboso/utils.git", - "reference": "e15f974ccab8cd2d3a03e99faeb8860b9c736fce" + "reference": "ec87b4918e05e601d6aa74d8110b8d5dda5c003c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/hanaboso/utils/zipball/e15f974ccab8cd2d3a03e99faeb8860b9c736fce", - "reference": "e15f974ccab8cd2d3a03e99faeb8860b9c736fce", + "url": "https://api.github.com/repos/hanaboso/utils/zipball/ec87b4918e05e601d6aa74d8110b8d5dda5c003c", + "reference": "ec87b4918e05e601d6aa74d8110b8d5dda5c003c", "shasum": "" }, "require": { @@ -1011,7 +1011,7 @@ "role": "Developer" } ], - "time": "2020-01-14T08:53:03+00:00" + "time": "2020-01-14T12:09:32+00:00" }, { "name": "psr/container", diff --git a/src/GridFilterAbstract.php b/src/GridFilterAbstract.php index 358c3f1..9eabca2 100644 --- a/src/GridFilterAbstract.php +++ b/src/GridFilterAbstract.php @@ -99,12 +99,10 @@ public function __construct(EntityManager $em) $this->em = $em; $this->setEntity(); - $this->countQuery = $this->configCustomCountQuery(); $this->filterCols = $this->filterCols(); - $this->filterColsCallbacks = $this->configFilterColsCallbacks(); $this->orderCols = $this->orderCols(); $this->searchableCols = $this->searchableCols(); - $this->searchQuery = $this->prepareSearchQuery(); + $this->filterColsCallbacks = $this->configFilterColsCallbacks(); $this->fetchJoin = $this->useFetchJoin(); } @@ -117,7 +115,8 @@ public function __construct(EntityManager $em) */ public function getData(GridRequestDtoInterface $gridRequestDto, array $dateFields = []): array { - $this->prepareSearchQuery(); + $this->searchQuery = $this->prepareSearchQuery(); + $this->countQuery = $this->configCustomCountQuery(); $this->processSortations($gridRequestDto); $this->processConditions($gridRequestDto, $this->searchQuery); @@ -193,8 +192,8 @@ private function processSortations(GridRequestDtoInterface $dto): void */ private function processConditions(GridRequestDtoInterface $dto, QueryBuilder $builder): void { - $conditions = $dto->getFilter(); - $advancedConditionExpression = $builder->expr()->andX(); + $conditions = $dto->getFilter(); + $conditionExpression = $builder->expr()->andX(); $exp = FALSE; foreach ($conditions as $andCondition) { @@ -248,13 +247,13 @@ private function processConditions(GridRequestDtoInterface $dto, QueryBuilder $b } if ($hasExpression) { - $advancedConditionExpression = $advancedConditionExpression->add($expression); - $exp = TRUE; + $conditionExpression = $conditionExpression->add($expression); + $exp = TRUE; } } if ($exp) { - $builder->andWhere($advancedConditionExpression); + $builder->andWhere($conditionExpression); } $search = $dto->getSearch(); @@ -364,13 +363,18 @@ abstract protected function orderCols(): array; abstract protected function searchableCols(): array; /** - * @return bool + * -------------------------------------------- HELPERS ----------------------------------------------- */ - abstract protected function useFetchJoin(): bool; /** - * -------------------------------------------- HELPERS ----------------------------------------------- + * Whether the query joins a collection (true by default). + * + * @return bool */ + protected function useFetchJoin(): bool + { + return TRUE; + } /** * In child can configure GridFilterAbstract::filterColsCallbacks diff --git a/tests/Filter/EntityFilter.php b/tests/Filter/EntityFilter.php index 7895dda..643ccf0 100644 --- a/tests/Filter/EntityFilter.php +++ b/tests/Filter/EntityFilter.php @@ -64,6 +64,8 @@ protected function searchableCols(): array */ protected function useFetchJoin(): bool { + parent::useFetchJoin(); + return TRUE; } diff --git a/tests/Integration/FilterTest.php b/tests/Integration/FilterTest.php index 7750d40..53d683f 100644 --- a/tests/Integration/FilterTest.php +++ b/tests/Integration/FilterTest.php @@ -2542,4 +2542,47 @@ public function testGetConditionNotBetween(): void ); } + /** + * @throws Exception + */ + public function testGetDataMissingCountQuery(): void + { + $f = $this->getMockBuilder(EntityFilter::class) + ->setMethods(['configCustomCountQuery']) + ->setConstructorArgs([$this->em]) + ->getMock(); + $f->method('configCustomCountQuery')->willReturn(NULL); + $this->setProperty($f, 'em', $this->em); + + $result = $f->getData( + new GridRequestDto( + [ + self::FILTER => [ + [ + [ + 'column' => 'string', + 'value' => 'ing 1', + 'operator' => 'ENDS', + ], + ], + ], + ] + ), + ['date'] + ); + self::assertEquals( + [ + [ + 'id' => $result[0]['id'], + 'string' => 'String 1', + 'int' => 1, + 'float' => 1.1, + 'bool' => FALSE, + 'date' => $this->today->modify('1 day')->format(self::DATETIME), + ], + ], + $result + ); + } + }