1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Order and search component handling generation of ordering and |
5
|
|
|
* searching conditions in loading data tables. |
6
|
|
|
* |
7
|
|
|
* phpMyAdmin Error reporting server |
8
|
|
|
* Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/) |
9
|
|
|
* |
10
|
|
|
* Licensed under The MIT License |
11
|
|
|
* For full copyright and license information, please see the LICENSE.txt |
12
|
|
|
* Redistributions of files must retain the above copyright notice. |
13
|
|
|
* |
14
|
|
|
* @copyright Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/) |
15
|
|
|
* @license https://opensource.org/licenses/mit-license.php MIT License |
16
|
|
|
* |
17
|
|
|
* @see https://www.phpmyadmin.net/ |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace App\Controller\Component; |
21
|
|
|
|
22
|
|
|
use Cake\Controller\Component; |
23
|
|
|
use Cake\Http\ServerRequest; |
24
|
|
|
|
25
|
|
|
use function array_keys; |
26
|
|
|
use function count; |
27
|
|
|
use function intval; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Github api component handling comunication with github. |
31
|
|
|
*/ |
32
|
|
|
class OrderSearchComponent extends Component |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* Indexes are +1'ed because first column is of checkboxes |
36
|
|
|
* and hence it should be ignored. |
37
|
|
|
* |
38
|
|
|
* @param string[] $aColumns The columns |
39
|
|
|
* |
40
|
|
|
* @return array |
41
|
|
|
*/ |
42
|
14 |
|
public function getSearchConditions(array $aColumns, ServerRequest $request): array |
43
|
|
|
{ |
44
|
14 |
|
$searchConditions = ['OR' => []]; |
45
|
14 |
|
$keys = array_keys($aColumns); |
46
|
14 |
|
$columnsCount = count($aColumns); |
47
|
|
|
|
48
|
14 |
|
$sSearch = $request->getQuery('sSearch'); |
49
|
14 |
|
if ($sSearch !== '' && $sSearch !== null) { |
50
|
7 |
|
for ($i = 0; $i < $columnsCount; ++$i) { |
51
|
7 |
|
if ($request->getQuery('bSearchable_' . ($i + 1)) !== 'true') { |
52
|
7 |
|
continue; |
53
|
|
|
} |
54
|
|
|
|
55
|
7 |
|
$searchConditions['OR'][] = [$aColumns[$keys[$i]] . ' LIKE' => '%' . $sSearch . '%']; |
|
|
|
|
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/* Individual column filtering */ |
60
|
14 |
|
for ($i = 0; $i < $columnsCount; ++$i) { |
61
|
14 |
|
$searchTerm = $request->getQuery('sSearch_' . ($i + 1)); |
62
|
14 |
|
if ($searchTerm === '' || $searchTerm === null) { |
63
|
14 |
|
continue; |
64
|
|
|
} |
65
|
|
|
|
66
|
7 |
|
$searchConditions[] = [$aColumns[$keys[$i]] . ' LIKE' => $searchTerm]; |
67
|
|
|
} |
68
|
|
|
|
69
|
14 |
|
return $searchConditions; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @param string[] $aColumns The columns |
74
|
|
|
* |
75
|
|
|
* @return array|null |
76
|
|
|
*/ |
77
|
14 |
|
public function getOrder(array $aColumns, ServerRequest $request): ?array |
78
|
|
|
{ |
79
|
14 |
|
if ($request->getQuery('iSortCol_0') !== null) { |
80
|
7 |
|
$order = []; |
81
|
|
|
//Seems like we need to sort with only one column each time, so no need to loop |
82
|
7 |
|
$sort_column_index = intval($request->getQuery('iSortCol_0')); |
83
|
|
|
|
84
|
7 |
|
$keys = array_keys($aColumns); |
85
|
|
|
|
86
|
|
|
if ( |
87
|
7 |
|
$sort_column_index > 0 |
88
|
7 |
|
&& $request->getQuery('bSortable_' . $sort_column_index) === 'true' |
89
|
|
|
) { |
90
|
|
|
$order[$aColumns[$keys[$sort_column_index - 1]]] = $request->getQuery('sSortDir_0'); |
91
|
|
|
} |
92
|
|
|
|
93
|
7 |
|
return $order; |
94
|
|
|
} |
95
|
|
|
|
96
|
14 |
|
return null; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|