-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGrid.php
79 lines (64 loc) · 1.49 KB
/
Grid.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
namespace Kora\Grid;
use Kora\DataProvider\DataProviderInterface;
use Kora\DataProvider\DataProviderOperatorsSetup;
use Kora\DataProvider\Result;
use Kora\Grid\ResultDisplay\Column;
use Kora\Grid\ResultDisplay\ResultDisplay;
/**
* Class Grid
* @author Paweł Gierlasiński <[email protected]>
*/
class Grid extends DataProviderOperatorsSetup
{
/**
* @var ResultDisplay
*/
protected $resultDisplay;
/**
* @var string[]
*/
protected $orderColumns = [];
/**
* Grid constructor.
*/
public function __construct()
{
$this->resultDisplay = new ResultDisplay();
}
/**
* @param Column $column
* @return Grid
*/
public function addColumn(Column $column): Grid
{
$this->resultDisplay->addColumn($column);
if($column->isSortable()) {
$this->orderColumns[] = $column->getName();
}
return $this;
}
/**
* @return ResultDisplay
*/
public function getResultDisplay(): ResultDisplay
{
return $this->resultDisplay;
}
/**
* @param DataProviderInterface $dataProvider
* @param array $params
* @return Result
*/
public function fetchData(DataProviderInterface $dataProvider, array $params = []): Result
{
if($this->order !== null) {
$this->order->setOrderColumns($this->orderColumns);
}
$this->setData($params);
$result = $dataProvider->fetchData($this);
$this->resultDisplay->getDataAccessor()->setMapping($dataProvider->getMapper()->getColumnMap());
$this->resultDisplay->setResult($result);
return $result;
}
}