|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Woo\GridView\DataProviders; |
|
4
|
|
|
|
|
5
|
|
|
use Woo\GridView\GridViewRequest; |
|
6
|
|
|
|
|
7
|
|
|
abstract class BaseDataProvider |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* true means that all request filters are accepted, checks by default comparing (like) |
|
11
|
|
|
* false means that filtering is not enabled in this dataprovider |
|
12
|
|
|
* array should contain array of fields, available for filtering. |
|
13
|
|
|
* if key not specified, value should be a name of field, otherwise key - field name, |
|
14
|
|
|
* value - comparing type (=, like) or a callable function |
|
15
|
|
|
* @var bool|array |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $filters = false; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* true means that all request sortings are accepted, checks by default sorting |
|
21
|
|
|
* false means that ordering is not enabled in this dataprovider |
|
22
|
|
|
* array should contain array of fields, available for filtering. |
|
23
|
|
|
* value should be a string |
|
24
|
|
|
* @var bool|array |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $ordering = false; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Should return total amount of rows |
|
30
|
|
|
* @param GridViewRequest $request |
|
31
|
|
|
* @return int |
|
32
|
|
|
*/ |
|
33
|
|
|
abstract public function getCount(GridViewRequest $request) : int; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Should return a list of data for current page |
|
37
|
|
|
* @param GridViewRequest $request |
|
38
|
|
|
* @return mixed |
|
39
|
|
|
*/ |
|
40
|
|
|
abstract public function getData(GridViewRequest $request); |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Allows to set a list of fields, available for filtering |
|
44
|
|
|
* @param array|boolean $filters |
|
45
|
|
|
* @return $this |
|
46
|
|
|
*/ |
|
47
|
|
|
public function setFilters($filters) |
|
48
|
|
|
{ |
|
49
|
|
|
$this->filters = $filters; |
|
50
|
|
|
return $this; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Allows to set a list of ordering fields |
|
55
|
|
|
* @param array|boolean $ordering |
|
56
|
|
|
* @return $this |
|
57
|
|
|
*/ |
|
58
|
|
|
public function setOrdering($ordering) |
|
59
|
|
|
{ |
|
60
|
|
|
$this->ordering = $ordering; |
|
61
|
|
|
return $this; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|