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