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
|
|
|
protected static function request($make = null) |
|
|
|
|
69
|
|
|
{ |
70
|
|
|
$export = function() |
71
|
|
|
{ |
72
|
|
|
$exp = filter_input(INPUT_GET, 'export', FILTER_SANITIZE_STRING); |
73
|
|
|
return in_array($exp, self::config('SAVES')) ? $exp : false; |
74
|
|
|
}; |
75
|
|
|
$order_dir = function() |
76
|
|
|
{ |
77
|
|
|
$reset = filter_has_var(INPUT_GET, 'col') ? 'asc' : null; |
78
|
|
|
return |
79
|
|
|
in_array(filter_input(INPUT_GET, 'ord'), ['asc', 'desc']) ? |
80
|
|
|
filter_input(INPUT_GET, 'ord') : |
81
|
|
|
($reset ?: self::$t['order']['dir']); |
82
|
|
|
}; |
83
|
|
|
$order_col = function() |
84
|
|
|
{ |
85
|
|
|
$col = filter_input(INPUT_GET, 'col', FILTER_VALIDATE_INT); |
86
|
|
|
if ($col) { |
87
|
|
|
return isset(self::$cols[$col][2]['sort']) ? |
88
|
|
|
self::$cols[$col][2]['sort'] : |
89
|
|
|
self::$cols[$col][1]; |
90
|
|
|
} |
91
|
|
|
return self::$t['order']['col']; |
92
|
|
|
}; |
93
|
|
|
$filter = function() |
94
|
|
|
{ |
95
|
|
|
$filter = filter_input(INPUT_GET, 'filter') ?: false; |
96
|
|
|
if ($filter) { |
97
|
|
|
$by = filter_input(INPUT_GET, 'filter-by', FILTER_VALIDATE_INT); |
98
|
|
|
if ($by === false || is_null($by)) { |
99
|
|
|
$by = self::request('FilterByAll'); |
100
|
|
|
} else { |
101
|
|
|
$by = self::$cols[$by][1]; |
102
|
|
|
} |
103
|
|
|
$by = 'CONCAT(" ",' . $by . ', " ")'; |
104
|
|
|
if (self::config('FILTER_CASE_SENSITIVE') !== true) { |
105
|
|
|
$by .= ' COLLATE ' . self::config('DB_COLLATION_CI'); |
106
|
|
|
} |
107
|
|
|
$filter = $by . ' LIKE ' . '"%' . $filter . '%"'; |
108
|
|
|
} |
109
|
|
|
return $filter; |
110
|
|
|
}; |
111
|
|
|
$page = function() |
112
|
|
|
{ |
113
|
|
|
return filter_has_var(INPUT_GET, 'pg') && self::$export == false ? |
114
|
|
|
(int)filter_input(INPUT_GET, 'pg', FILTER_SANITIZE_NUMBER_INT) : |
115
|
|
|
self::$t['page']; |
116
|
|
|
}; |
117
|
|
|
|
118
|
|
|
self::$export = $export(); |
|
|
|
|
119
|
|
|
|
120
|
|
|
$t = [ |
121
|
|
|
'order' => [ |
122
|
|
|
'dir' => $order_dir(), |
123
|
|
|
'col' => $order_col() |
124
|
|
|
], |
125
|
|
|
'filter' => $filter(), |
126
|
|
|
'page' => $page() |
127
|
|
|
]; |
128
|
|
|
//dd(array_merge(self::$t, $t)); |
129
|
|
|
return array_merge(self::$t, $t); |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.