1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
trait trait_table_request |
4
|
|
|
{ |
5
|
|
|
|
6
|
|
|
/*private static function requestFilter() |
7
|
|
|
{ |
8
|
|
|
$filter = filter_input(INPUT_GET, 'filter') ?: false; |
9
|
|
|
if ($filter) { |
10
|
|
|
$by = filter_input(INPUT_GET, 'filter-by', FILTER_VALIDATE_INT); |
11
|
|
|
if ($by === false || is_null($by)) { |
12
|
|
|
$by = self::requestFilterByAll(); |
13
|
|
|
} else { |
14
|
|
|
$by = self::$cols[$by][1]; |
15
|
|
|
} |
16
|
|
|
$by = 'CONCAT(" ",' . $by . ', " ")'; |
17
|
|
|
if (self::config('FILTER_CASE_SENSITIVE') !== true) { |
18
|
|
|
$by .= ' COLLATE ' . self::config('DB_COLLATION_CI'); |
19
|
|
|
} |
20
|
|
|
$filter = $by . ' LIKE ' . '"%' . $filter . '%"'; |
21
|
|
|
} |
22
|
|
|
return $filter; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
private static function requestFilterByAll() |
26
|
|
|
{ |
27
|
|
|
$by = []; |
28
|
|
|
foreach (self::$cols as $v) { |
29
|
|
|
if (isset($v[2]['sort']) && $v[2]['sort'] === false) { |
30
|
|
|
continue; |
31
|
|
|
} |
32
|
|
|
$by[] = 'IFNULL(' . $v[1] . ', "")'; |
33
|
|
|
} |
34
|
|
|
return 'CONCAT(' . implode(',', $by) . ')'; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
private static function requestOrderCol() |
38
|
|
|
{ |
39
|
|
|
if (($col = filter_input(INPUT_GET, 'col', FILTER_VALIDATE_INT))) { |
40
|
|
|
return isset(self::$cols[$col][2]['sort']) ? |
41
|
|
|
self::$cols[$col][2]['sort'] : |
42
|
|
|
self::$cols[$col][1]; |
43
|
|
|
} |
44
|
|
|
return self::$t['order']['col']; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
private static function requestOrderDir() |
48
|
|
|
{ |
49
|
|
|
$reset = filter_has_var(INPUT_GET, 'col') ? 'asc' : null; |
50
|
|
|
return in_array(filter_input(INPUT_GET, 'ord'), ['asc', 'desc']) ? |
51
|
|
|
filter_input(INPUT_GET, 'ord') : |
52
|
|
|
($reset ?: self::$t['order']['dir']); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
private static function requestExport() |
56
|
|
|
{ |
57
|
|
|
$exp = filter_input(INPUT_GET, 'export', FILTER_SANITIZE_STRING); |
58
|
|
|
return in_array($exp, self::config('SAVES')) ? $exp : false; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
private static function requestPage() |
62
|
|
|
{ |
63
|
|
|
return filter_has_var(INPUT_GET, 'pg') && self::$export == false ? |
64
|
|
|
(int)filter_input(INPUT_GET, 'pg', FILTER_SANITIZE_NUMBER_INT) : |
65
|
|
|
self::$t['page']; |
66
|
|
|
}*/ |
67
|
|
|
|
68
|
|
|
final static function request($make = null) |
|
|
|
|
69
|
|
|
{ |
70
|
|
|
switch ($make) { |
71
|
|
|
default: |
72
|
|
|
|
73
|
|
|
self::$export = self::request('Export'); |
|
|
|
|
74
|
|
|
|
75
|
|
|
$t = [ |
76
|
|
|
'order' => [ |
77
|
|
|
'dir' => self::request('OrderDir'), |
78
|
|
|
'col' => self::request('OrderCol') |
79
|
|
|
], |
80
|
|
|
'filter' => self::request('Filter'), |
81
|
|
|
'page' => self::request('Page') |
82
|
|
|
]; |
83
|
|
|
//dd(array_merge(self::$t, $t)); |
84
|
|
|
return array_merge(self::$t, $t); |
85
|
|
|
|
86
|
|
|
case 'Filter': |
87
|
|
|
$filter = filter_input(INPUT_GET, 'filter') ?: false; |
88
|
|
|
if ($filter) { |
89
|
|
|
$by = filter_input(INPUT_GET, 'filter-by', FILTER_VALIDATE_INT); |
90
|
|
|
if ($by === false || is_null($by)) { |
91
|
|
|
$by = self::requestFilterByAll(); |
|
|
|
|
92
|
|
|
} else { |
93
|
|
|
$by = self::$cols[$by][1]; |
94
|
|
|
} |
95
|
|
|
$by = 'CONCAT(" ",' . $by . ', " ")'; |
96
|
|
|
if (self::config('FILTER_CASE_SENSITIVE') !== true) { |
97
|
|
|
$by .= ' COLLATE ' . self::config('DB_COLLATION_CI'); |
98
|
|
|
} |
99
|
|
|
$filter = $by . ' LIKE ' . '"%' . $filter . '%"'; |
100
|
|
|
} |
101
|
|
|
return $filter; |
102
|
|
|
case 'FilterByAll': |
103
|
|
|
$by = []; |
104
|
|
|
foreach (self::$cols as $v) { |
105
|
|
|
if (isset($v[2]['sort']) && $v[2]['sort'] === false) { |
106
|
|
|
continue; |
107
|
|
|
} |
108
|
|
|
$by[] = 'IFNULL(' . $v[1] . ', "")'; |
109
|
|
|
} |
110
|
|
|
return 'CONCAT(' . implode(',', $by) . ')'; |
111
|
|
|
case 'OrderCol': |
112
|
|
|
$col = filter_input(INPUT_GET, 'col', FILTER_VALIDATE_INT); |
113
|
|
|
if ($col) { |
114
|
|
|
return isset(self::$cols[$col][2]['sort']) ? |
115
|
|
|
self::$cols[$col][2]['sort'] : |
116
|
|
|
self::$cols[$col][1]; |
117
|
|
|
} |
118
|
|
|
return self::$t['order']['col']; |
119
|
|
|
case 'OrderDir': |
120
|
|
|
$reset = filter_has_var(INPUT_GET, 'col') ? 'asc' : null; |
121
|
|
|
return |
122
|
|
|
in_array(filter_input(INPUT_GET, 'ord'), ['asc', 'desc']) ? |
123
|
|
|
filter_input(INPUT_GET, 'ord') : |
124
|
|
|
($reset ?: self::$t['order']['dir']); |
125
|
|
|
case 'Page': |
126
|
|
|
return |
127
|
|
|
filter_has_var(INPUT_GET, 'pg') && self::$export == false ? |
128
|
|
|
(int)filter_input(INPUT_GET, 'pg', FILTER_SANITIZE_NUMBER_INT) : |
129
|
|
|
self::$t['page']; |
130
|
|
|
case 'Export': |
131
|
|
|
$exp = filter_input(INPUT_GET, 'export', FILTER_SANITIZE_STRING); |
132
|
|
|
return in_array($exp, self::config('SAVES')) ? $exp : false; |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.