Skip to content

Commit 985fa50

Browse files
committed
Merge remote-tracking branch 'origin/nette-3'
2 parents cc6d16c + 6f1d1db commit 985fa50

3 files changed

Lines changed: 39 additions & 20 deletions

File tree

composer.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@
88
"GPL-2.0",
99
"GPL-3.0"
1010
],
11+
"require": {
12+
"php": ">=7.1"
13+
},
1114
"require-dev": {
12-
"kdyby/doctrine": "^3.1",
13-
"ublaboo/datagrid": "^5.0",
14-
"nette/utils": "^2.4",
15-
"nette/di": "^2.4"
15+
"kdyby/doctrine": "^3.1 || ~4.0",
16+
"ublaboo/datagrid": "^5.0 || ~6.0",
17+
"nette/utils": "^2.4 || ~3.0",
18+
"nette/di": "^2.4 || ~3.0"
1619
},
1720
"autoload": {
1821
"psr-4": {

src/DI/QueryObjectDataSourceExtension.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ class QueryObjectDataSourceExtension extends \Nette\DI\CompilerExtension {
66

77
public function loadConfiguration() {
88

9-
$this->getContainerBuilder()
10-
->addDefinition($this->prefix('factory'))
11-
->setImplement(\ADT\QueryObjectDataSource\IQueryObjectDataSourceFactory::class);
9+
$builder = $this->getContainerBuilder();
10+
if (method_exists($builder, 'addFactoryDefinition')) {
11+
$definition = $builder->addFactoryDefinition($this->prefix('factory'));
12+
} else {
13+
$definition = $builder->addDefinition($this->prefix('factory'));
14+
}
15+
$definition->setImplement(\ADT\QueryObjectDataSource\IQueryObjectDataSourceFactory::class);
1216
}
1317

1418
}

src/QueryObjectDataSource.php

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
use Ublaboo\DataGrid\Filter\FilterDateRange;
77
use Ublaboo\DataGrid\Filter\FilterText;
88
use Ublaboo\DataGrid\Utils\DateTimeHelper;
9+
use Ublaboo\DataGrid\DataSource\IDataSource;
910

10-
class QueryObjectDataSource implements \Ublaboo\DataGrid\DataSource\IDataSource {
11+
class QueryObjectDataSource implements IDataSource {
1112

1213
use \Nette\SmartObject;
1314

@@ -32,6 +33,9 @@ class QueryObjectDataSource implements \Ublaboo\DataGrid\DataSource\IDataSource
3233
/** @var callable */
3334
public $limitCallback;
3435

36+
/** @var array */
37+
private $data;
38+
3539
/**
3640
* @param \Kdyby\Doctrine\QueryObject $queryObject
3741
* @param \Kdyby\Doctrine\EntityRepository $repo
@@ -93,7 +97,7 @@ protected function getResultSet() {
9397
* Get count of data
9498
* @return int
9599
*/
96-
public function getCount() {
100+
public function getCount(): int {
97101
return $this->repo
98102
->fetch($this->queryObject)
99103
->getTotalCount();
@@ -103,22 +107,32 @@ public function getCount() {
103107
* Get the data
104108
* @return array
105109
*/
106-
public function getData() {
110+
public function getData(): array {
111+
if ($this->data) {
112+
return $this->data;
113+
}
107114
return $this->getResultSet()->toArray();
108115
}
109116

117+
/**
118+
* Set the data
119+
* @return $this
120+
*/
121+
public function setData($data) {
122+
$this->data = $data;
123+
return $this;
124+
}
125+
110126
/**
111127
* Filter data
112128
* @param array $filters
113129
* @return static
114130
*/
115-
public function filter(array $filters) {
131+
public function filter(array $filters): void {
116132
foreach ($filters as $filter) {
117133
if ($filter->isValueSet()) {
118-
if ($filter->hasConditionCallback()) {
119-
\Nette\Utils\Callback::invokeArgs(
120-
$filter->getConditionCallback(), [ $this->queryObject, $filter->getValue() ]
121-
);
134+
if ($filter->getConditionCallback()) {
135+
call_user_func($filter->getConditionCallback(), $this->queryObject, $filter->getValue());
122136
} else {
123137
if ($this->queryObject instanceof IQueryObject) {
124138
if ($filter instanceof FilterText) {
@@ -134,16 +148,14 @@ public function filter(array $filters) {
134148
if (is_callable($this->filterCallback)) {
135149
call_user_func_array($this->filterCallback, [$this->queryObject, $filters]);
136150
}
137-
138-
return $this;
139151
}
140152

141153
/**
142154
* Filter data - get one row
143155
* @param array $filter
144156
* @return static
145157
*/
146-
public function filterOne(array $filter) {
158+
public function filterOne(array $filter): IDataSource {
147159

148160
if (is_callable($this->filterOneCallback)) {
149161
call_user_func_array($this->filterOneCallback, [$this->queryObject, $filter]);
@@ -158,7 +170,7 @@ public function filterOne(array $filter) {
158170
* @param int $limit
159171
* @return static
160172
*/
161-
public function limit($offset, $limit) {
173+
public function limit($offset, $limit): IDataSource {
162174
$defaultCallback = function () use ($offset, $limit) {
163175
$this->getResultSet()->applyPaging($offset, $limit);
164176
};
@@ -178,7 +190,7 @@ public function limit($offset, $limit) {
178190
* @param \Ublaboo\DataGrid\Utils\Sorting $sorting
179191
* @return static
180192
*/
181-
public function sort(\Ublaboo\DataGrid\Utils\Sorting $sorting) {
193+
public function sort(\Ublaboo\DataGrid\Utils\Sorting $sorting): IDataSource {
182194

183195
if (is_callable($sorting->getSortCallback())) {
184196
call_user_func(

0 commit comments

Comments
 (0)