|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace OpenSkill\Datatable\Queries; |
|
4
|
|
|
|
|
5
|
|
|
use OpenSkill\Datatable\Columns\ColumnOrder; |
|
6
|
|
|
use OpenSkill\Datatable\Columns\ColumnSearch; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class DTQueryConfiguration |
|
10
|
|
|
* @package OpenSkill\Datatable\Interfaces |
|
11
|
|
|
* |
|
12
|
|
|
* This class contains all parameters that the frontend queries from the backend. |
|
13
|
|
|
* So this class contains the parsed query parameters, abstracted away form the data table frontend |
|
14
|
|
|
*/ |
|
15
|
|
|
class QueryConfiguration |
|
16
|
|
|
{ |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* DTQueryConfiguration constructor. |
|
20
|
|
|
* @param string $drawCall the frontend draw call forwarded to the backend |
|
21
|
|
|
* @param int $start the start index of the data entries |
|
22
|
|
|
* @param int $length the amount of items that should be returned |
|
23
|
|
|
* @param string $searchValue the global search value that should be searched for |
|
24
|
|
|
* @param bool $searchRegex true if the search value should be evaluated as a regex expression |
|
25
|
|
|
* @param ColumnSearch[] $columnSearches all search values for the individual columns if available and allowed |
|
26
|
|
|
* @param ColumnOrder[] $columnOrders the order for each column if available and allowed |
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct( |
|
29
|
|
|
$drawCall, |
|
30
|
|
|
$start, |
|
31
|
|
|
$length, |
|
32
|
|
|
$searchValue, |
|
33
|
|
|
$searchRegex, |
|
34
|
|
|
array $columnSearches, |
|
35
|
|
|
array $columnOrders |
|
36
|
|
|
) { |
|
37
|
|
|
$this->drawCall = $drawCall; |
|
38
|
|
|
$this->start = $start; |
|
39
|
|
|
$this->length = $length; |
|
40
|
|
|
$this->searchValue = $searchValue; |
|
41
|
|
|
$this->searchRegex = $searchRegex; |
|
42
|
|
|
$this->searchColumns = $columnSearches; |
|
43
|
|
|
$this->orderColumns = $columnOrders; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Most data tables will send a drawCall with the request to make sure that the data |
|
48
|
|
|
* is not cached. |
|
49
|
|
|
* |
|
50
|
|
|
* @var string $drawCall |
|
51
|
|
|
*/ |
|
52
|
|
|
protected $drawCall; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @var string The string we are searching for (note: for searchColumns) |
|
56
|
|
|
*/ |
|
57
|
|
|
protected $searchValue = null; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @var ColumnSearch[] the columns that we are searching, the content that has been put in. |
|
61
|
|
|
* It is a map with the following structure: ['id' => column] |
|
62
|
|
|
*/ |
|
63
|
|
|
protected $searchColumns = []; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @var bool the search is a regular expression |
|
67
|
|
|
*/ |
|
68
|
|
|
protected $searchRegex = true; |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @var ColumnOrder[] a list of the columns we are sorting by, with their direction, this is just a list of objects |
|
72
|
|
|
*/ |
|
73
|
|
|
protected $orderColumns = []; |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @var int which result to start from |
|
77
|
|
|
*/ |
|
78
|
|
|
protected $start; |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @var int the length of the wished result. |
|
82
|
|
|
*/ |
|
83
|
|
|
protected $length; |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @return string will return the draw value that the frontend send to the backend |
|
87
|
|
|
*/ |
|
88
|
|
|
public function drawCall() |
|
89
|
|
|
{ |
|
90
|
|
|
return $this->drawCall; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @return int will return the value that the results should start with |
|
95
|
|
|
*/ |
|
96
|
|
|
public function start() |
|
97
|
|
|
{ |
|
98
|
|
|
return $this->start; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @return int returns the amount of items the frontend requested |
|
103
|
|
|
*/ |
|
104
|
|
|
public function length() |
|
105
|
|
|
{ |
|
106
|
|
|
return $this->length; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @return string will return the value that the frontend wants to search for globally |
|
111
|
|
|
*/ |
|
112
|
|
|
public function searchValue() |
|
113
|
|
|
{ |
|
114
|
|
|
return $this->searchValue; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* @return bool will return if the current search value should be used as a regex |
|
119
|
|
|
*/ |
|
120
|
|
|
public function isGlobalRegex() |
|
121
|
|
|
{ |
|
122
|
|
|
return $this->searchRegex; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* @return ColumnSearch[] |
|
127
|
|
|
*/ |
|
128
|
|
|
public function searchColumns() |
|
129
|
|
|
{ |
|
130
|
|
|
return $this->searchColumns; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* @return ColumnOrder[] |
|
135
|
|
|
*/ |
|
136
|
|
|
public function orderColumns() |
|
137
|
|
|
{ |
|
138
|
|
|
return $this->orderColumns; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* @return bool true if global search is enabled |
|
143
|
|
|
*/ |
|
144
|
|
|
public function isGlobalSearch() |
|
145
|
|
|
{ |
|
146
|
|
|
return !empty($this->searchValue); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* @param string $columnName the name of the column |
|
151
|
|
|
* @return bool |
|
152
|
|
|
*/ |
|
153
|
|
|
public function hasSearchColumn($columnName) |
|
154
|
|
|
{ |
|
155
|
|
|
return array_key_exists($columnName, $this->searchColumns); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
public function hasOrderColumn() |
|
159
|
|
|
{ |
|
160
|
|
|
return !empty($this->orderColumns); |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* @return bool will return true if the query asks for a column search, false otherwise |
|
165
|
|
|
*/ |
|
166
|
|
|
public function isColumnSearch() |
|
167
|
|
|
{ |
|
168
|
|
|
return count($this->searchColumns) != 0; |
|
169
|
|
|
} |
|
170
|
|
|
} |