Skip to content

Commit 6f55f51

Browse files
committed
changes compatible with latest QueryObject
1 parent 144032e commit 6f55f51

3 files changed

Lines changed: 5 additions & 38 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
],
88
"require": {
99
"php": ">=7.4",
10-
"adt/doctrine-components": "^2.0",
10+
"adt/doctrine-components": "^2.3",
1111
"ublaboo/datagrid": "^6.0",
1212
"nette/di": "^2.4|^3.0"
1313
},

src/IQueryObject.php

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/QueryObjectDataSource.php

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class QueryObjectDataSource implements IDataSource
1818
/** @var \Doctrine\ORM\EntityRepository */
1919
protected $repo;
2020

21-
/** @var \ADT\DoctrineComponents\QueryObject|IQueryObject */
21+
/** @var \ADT\DoctrineComponents\QueryObject */
2222
protected $queryObject;
2323

2424
/** @var callable */
@@ -39,15 +39,10 @@ class QueryObjectDataSource implements IDataSource
3939
/**
4040
* QueryObjectDataSource constructor.
4141
* @param \ADT\DoctrineComponents\QueryObject $queryObject
42-
* @param \Doctrine\ORM\EntityRepository|null $repo
4342
* @throws \Exception
4443
*/
45-
public function __construct(\ADT\DoctrineComponents\QueryObject $queryObject, \Doctrine\ORM\EntityRepository $repo = null)
44+
public function __construct(\ADT\DoctrineComponents\QueryObject $queryObject)
4645
{
47-
if (!$repo && (!$queryObject instanceof IQueryObject)) {
48-
throw new \Exception('"repo" must be set or "queryObject" has to implement IQueryObject interface.');
49-
}
50-
5146
$this->queryObject = $queryObject;
5247
$this->repo = $repo ?: $queryObject->getEntityManager();
5348
}
@@ -147,7 +142,7 @@ public function filter(array $filters): void
147142
if ($filter->getConditionCallback()) {
148143
call_user_func($filter->getConditionCallback(), $this->queryObject, $filter->getValue());
149144
}
150-
elseif (!$filter instanceof FilterDateRange && $this->queryObject instanceof IQueryObject) {
145+
elseif (!$filter instanceof FilterDateRange) {
151146
$this->queryObject->searchIn(
152147
$filter instanceof OneColumnFilter ? $filter->getColumn() : $filter->getKey(),
153148
$filter->getValue(),
@@ -205,21 +200,7 @@ public function sort(\Ublaboo\DataGrid\Utils\Sorting $sorting): IDataSource {
205200
);
206201

207202
} else {
208-
209-
$sort = $sorting->getSort();
210-
211-
if (!empty($sort) && ($this->queryObject instanceof IQueryObject)) {
212-
$isFirst = true;
213-
foreach ($sort as $column => $order) {
214-
if ($isFirst) {
215-
$this->queryObject->orderBy($column, $order);
216-
}
217-
else {
218-
$this->queryObject->addOrderBy($column, $order);
219-
}
220-
$isFirst = false;
221-
}
222-
}
203+
$this->queryObject->orderBy($sorting->getSort());
223204
}
224205

225206
if (is_callable($this->sortCallback)) {

0 commit comments

Comments
 (0)