@@ -22,23 +22,22 @@ discard block |
||
22 | 22 | if (self::$cols) { |
23 | 23 | $ths = []; |
24 | 24 | $length = sizeof(self::$cols); |
25 | - for ($i = 0; $i<$length; $i++) { |
|
25 | + for ($i = 0; $i < $length; $i++) { |
|
26 | 26 | list($lbl, $col, $arg) = array_pad(self::$cols[$i], 3, null); |
27 | 27 | |
28 | 28 | if (is_null($col)) { |
29 | 29 | $arg['sort'] = false; |
30 | 30 | } |
31 | 31 | |
32 | - $sortable = !isset($arg['sort'])||$arg['sort'] !==false; |
|
32 | + $sortable = !isset($arg['sort']) || $arg['sort'] !== false; |
|
33 | 33 | |
34 | 34 | $sort = $sortable ? |
35 | - (isset($arg['sort']) ? $arg['sort'] : $col) : |
|
36 | - null; |
|
35 | + (isset($arg['sort']) ? $arg['sort'] : $col) : null; |
|
37 | 36 | |
38 | - if (($del = isset($arg['type'])&&$arg['type'] =='delete')) { |
|
37 | + if (($del = isset($arg['type']) && $arg['type'] == 'delete')) { |
|
39 | 38 | $sortable = false; |
40 | - if (!isset($arg['width'])&& |
|
41 | - false ===strpos($arg['width'], 'width:') |
|
39 | + if (!isset($arg['width']) && |
|
40 | + false === strpos($arg['width'], 'width:') |
|
42 | 41 | ) { |
43 | 42 | $arg['width'] = '1%'; |
44 | 43 | } |
@@ -47,21 +46,19 @@ discard block |
||
47 | 46 | if (isset($arg['width'])) { // Width attribute -> style |
48 | 47 | $width = 'width:' . $arg['width'] . ';'; |
49 | 48 | $arg['style'] = isset($arg['style']) ? |
50 | - $width . $arg['style'] : |
|
51 | - $width; |
|
49 | + $width . $arg['style'] : $width; |
|
52 | 50 | } |
53 | 51 | |
54 | - $attr = array_diff_key((array) $arg, ['sort', 'type', 'width']); |
|
52 | + $attr = array_diff_key((array)$arg, ['sort', 'type', 'width']); |
|
55 | 53 | |
56 | 54 | $th = '<th' . self::attributes($attr) . '>'; |
57 | 55 | if ($sortable) { |
58 | 56 | $th .= '<a onclick="table.Sort(' . $i . ',this);">'; |
59 | 57 | } |
60 | 58 | if (!$del) { |
61 | - if ($sort ==self::$t['order']['col']) { |
|
62 | - $span = self::$t['order']['dir'] ==='desc' ? |
|
63 | - self::config('UTF8_DESC_SYMBOL') : |
|
64 | - self::config('UTF8_ASC_SYMBOL'); |
|
59 | + if ($sort == self::$t['order']['col']) { |
|
60 | + $span = self::$t['order']['dir'] === 'desc' ? |
|
61 | + self::config('UTF8_DESC_SYMBOL') : self::config('UTF8_ASC_SYMBOL'); |
|
65 | 62 | } else { |
66 | 63 | $span = ""; |
67 | 64 | } |
@@ -91,9 +88,8 @@ discard block |
||
91 | 88 | protected static function q($q, $cond = null, array $order = [], $limit = 0, $h = false) |
92 | 89 | { |
93 | 90 | //Condition: '' | '(HAVING|WHERE|AND) ' . $cond |
94 | - $c = !empty($cond)&&!strpos($q, ($cl = !$h ? 'WHERE' : 'HAVING')) ? |
|
95 | - (' ' . (!strpos($q, $cl) ? $cl : ' AND ') . ' ' . $cond ) : |
|
96 | - ''; |
|
91 | + $c = !empty($cond) && !strpos($q, ($cl = !$h ? 'WHERE' : 'HAVING')) ? |
|
92 | + (' ' . (!strpos($q, $cl) ? $cl : ' AND ') . ' ' . $cond) : ''; |
|
97 | 93 | //Order: '' | 'ORDER BY ' . array_keys($order)[0] . ' ' . $order[0] |
98 | 94 | $o = !empty($order) ? |
99 | 95 | ' ORDER BY ' . implode(', ', |
@@ -104,8 +100,7 @@ discard block |
||
104 | 100 | ''; |
105 | 101 | //Limit: '' | ' LIMIT ' . '(20, 40|20)' |
106 | 102 | $l = !empty($limit) ? |
107 | - (' LIMIT ' . (is_array($limit) ? implode(', ', $limit) : $limit)) : |
|
108 | - ''; |
|
103 | + (' LIMIT ' . (is_array($limit) ? implode(', ', $limit) : $limit)) : ''; |
|
109 | 104 | |
110 | 105 | return $q . $c . $o . $l; |
111 | 106 | } |
@@ -113,8 +108,7 @@ discard block |
||
113 | 108 | protected static function exportData() |
114 | 109 | { |
115 | 110 | $data = self::$exportDataAsDisplayed ? |
116 | - self::$data : |
|
117 | - self::select(self::$t['q']); |
|
111 | + self::$data : self::select(self::$t['q']); |
|
118 | 112 | $fnReplace = []; |
119 | 113 | $fnReplace[':app'] = self::$app; |
120 | 114 | $fnReplace[':items'] = self::$t['items']; |
@@ -124,14 +118,14 @@ discard block |
||
124 | 118 | $outFilename = strtr(self::config('EXPORT_FILE_NAME'), $fnReplace); |
125 | 119 | $outColumns = $outHeader = []; |
126 | 120 | foreach (self::$cols as $c) { |
127 | - if (isset($c[2]['sort'])&&$c[2]['sort'] ===false) { |
|
121 | + if (isset($c[2]['sort']) && $c[2]['sort'] === false) { |
|
128 | 122 | continue; |
129 | 123 | } |
130 | 124 | $outColumns[] = $c[1]; |
131 | 125 | $outHeader[] = $c[0]; |
132 | 126 | } |
133 | 127 | $eData = [$outHeader]; |
134 | - if (count($data)>0) { |
|
128 | + if (count($data) > 0) { |
|
135 | 129 | foreach ($data as $row) { |
136 | 130 | $rowData = []; |
137 | 131 | foreach ($row as $dbName => $value) { |
@@ -159,9 +153,8 @@ discard block |
||
159 | 153 | |
160 | 154 | $output = fopen('php://output', 'w'); |
161 | 155 | foreach ($eData as $v) { |
162 | - self::$export ==='CSV' ? |
|
163 | - fputcsv($output, $v) : |
|
164 | - fputs($output, implode("\t", array_map($escape, $v)) . "\r\n"); |
|
156 | + self::$export === 'CSV' ? |
|
157 | + fputcsv($output, $v) : fputs($output, implode("\t", array_map($escape, $v)) . "\r\n"); |
|
165 | 158 | } |
166 | 159 | fclose($output); |
167 | 160 | break; |
@@ -174,7 +167,7 @@ discard block |
||
174 | 167 | foreach (self::$cols as $c) { |
175 | 168 | $outColumns[] = isset($c[1]) ? $c[1] : null; |
176 | 169 | } |
177 | - if ((self::$t['rows'] = count(self::$data))>0) { |
|
170 | + if ((self::$t['rows'] = count(self::$data)) > 0) { |
|
178 | 171 | foreach (self::$data as $row) { |
179 | 172 | $rowData = []; |
180 | 173 | foreach ($outColumns as $dbName) { |
@@ -193,9 +186,9 @@ discard block |
||
193 | 186 | protected static function jsonGetFooterData() |
194 | 187 | { |
195 | 188 | $jsonArrFooter = []; |
196 | - if (count(self::$data)>0) { |
|
189 | + if (count(self::$data) > 0) { |
|
197 | 190 | $pageNo = self::$t['page']; |
198 | - if ($pageNo ===1&&count(self::$data)<self::$t['paging']) { |
|
191 | + if ($pageNo === 1 && count(self::$data) < self::$t['paging']) { |
|
199 | 192 | //Skips total count query |
200 | 193 | self::$t['rows'] = count(self::$data); |
201 | 194 | } else { |
@@ -206,15 +199,14 @@ discard block |
||
206 | 199 | |
207 | 200 | $v = []; |
208 | 201 | |
209 | - $v['from'] = ($pageNo-1)*self::$t['paging']+1; |
|
210 | - $v['upto'] = ($pageNo*self::$t['paging']<self::$t['rows']) ? |
|
211 | - $pageNo*self::$t['paging'] : |
|
212 | - self::$t['rows']; |
|
202 | + $v['from'] = ($pageNo - 1)*self::$t['paging'] + 1; |
|
203 | + $v['upto'] = ($pageNo*self::$t['paging'] < self::$t['rows']) ? |
|
204 | + $pageNo*self::$t['paging'] : self::$t['rows']; |
|
213 | 205 | |
214 | 206 | $v["total"] = self::$t['rows']; |
215 | 207 | $v["items"] = self::$t['items']; |
216 | 208 | |
217 | - if (self::$exportActive ===true) { |
|
209 | + if (self::$exportActive === true) { |
|
218 | 210 | $url = strtok(self::$t['slug'], "?&") . ".json?table=" . |
219 | 211 | self::$t['items'] . "&export="; |
220 | 212 | $v["export"] = ["url" => $url, "types" => self::config('SAVES')]; |
@@ -264,10 +256,10 @@ discard block |
||
264 | 256 | private static function rows($for) |
265 | 257 | { |
266 | 258 | $trs = ''; |
267 | - if ($for ==='body') { |
|
259 | + if ($for === 'body') { |
|
268 | 260 | foreach (self::jsonGetBodyData() as $r) { |
269 | - if (isset($r[0][1], $r[0][1]['class'])&& |
|
270 | - $r[0][1]['class'] ==='no-results' |
|
261 | + if (isset($r[0][1], $r[0][1]['class']) && |
|
262 | + $r[0][1]['class'] === 'no-results' |
|
271 | 263 | ) { |
272 | 264 | $trs .= '<tr><td' . self::attributes($r[0][1]) . '>' |
273 | 265 | . $r[0][0] . '</td></tr>'; |
@@ -276,8 +268,8 @@ discard block |
||
276 | 268 | . '</td></tr>'; |
277 | 269 | } |
278 | 270 | } |
279 | - } else if ($for ==='footer') { |
|
280 | - if (self::$t['rows']>0) { |
|
271 | + } else if ($for === 'footer') { |
|
272 | + if (self::$t['rows'] > 0) { |
|
281 | 273 | $ftr = self::jsonGetFooterData()[0][0]; |
282 | 274 | $trs .= '<tr><td' . self::attributes($ftr[1]) . '>' |
283 | 275 | . $ftr[0] . '</td></tr>'; |
@@ -299,13 +291,12 @@ discard block |
||
299 | 291 | |
300 | 292 | static function select(string $expression, array $bindings = []) |
301 | 293 | { |
302 | - if (is_object(static::$select)&&(static::$select instanceof Closure)) { |
|
294 | + if (is_object(static::$select) && (static::$select instanceof Closure)) { |
|
303 | 295 | $select = static::$select; |
304 | 296 | $res = $select($expression, $bindings); |
305 | 297 | //if result is single cell value ($res[0]->value), return the value |
306 | - return (count($res) ===1&&count((array) $res[0]) ===1) ? |
|
307 | - reset($res[0]) : |
|
308 | - $res; |
|
298 | + return (count($res) === 1 && count((array)$res[0]) === 1) ? |
|
299 | + reset($res[0]) : $res; |
|
309 | 300 | } else { |
310 | 301 | die('ERROR: table::$select is not a valid closure. ' |
311 | 302 | . __METHOD__ . '() #' . __LINE__); |
@@ -33,10 +33,8 @@ discard block |
||
33 | 33 | self::prepare(true); |
34 | 34 | self::$t['order']['col'] = $orderBy; |
35 | 35 | $dir = strtolower($orderDir); |
36 | - self::$t['order']['dir'] = in_array($dir, ['asc', 'desc']) ? $dir : |
|
37 | - die('Invalid orderDir(Asc/Desc): ' . $orderDir); |
|
38 | - self::$t['paging'] = ($p = abs($paging)) > 10 ? $p : |
|
39 | - die('Invalid paging(>10): ' . $paging); |
|
36 | + self::$t['order']['dir'] = in_array($dir, ['asc', 'desc']) ? $dir : die('Invalid orderDir(Asc/Desc): ' . $orderDir); |
|
37 | + self::$t['paging'] = ($p = abs($paging)) > 10 ? $p : die('Invalid paging(>10): ' . $paging); |
|
40 | 38 | } |
41 | 39 | |
42 | 40 | /** #2. Execute (queries) |
@@ -55,15 +53,15 @@ discard block |
||
55 | 53 | |
56 | 54 | $filter = self::requestFilter(); |
57 | 55 | $order = [self::$t['order']['col'] => self::$t['order']['dir']]; |
58 | - $offset = (self::$t['page'] - 1) * self::$t['paging']; |
|
56 | + $offset = (self::$t['page'] - 1)*self::$t['paging']; |
|
59 | 57 | $limit = [$offset, self::$t['paging']]; |
60 | 58 | self::$t['q'] = self::q($q, $filter, $order, $limit, true); |
61 | 59 | |
62 | - $qAll = isset($qTotal) && ! $filter ? $qTotal : $q; |
|
63 | - $orderAll = ! self::$export ? [] : $order; |
|
60 | + $qAll = isset($qTotal) && !$filter ? $qTotal : $q; |
|
61 | + $orderAll = !self::$export ? [] : $order; |
|
64 | 62 | self::$t['qAll'] = self::q($qAll, $filter, $orderAll, 0, true); |
65 | 63 | |
66 | - $query = ! self::$export ? self::$t['q'] : self::$t['qAll']; |
|
64 | + $query = !self::$export ? self::$t['q'] : self::$t['qAll']; |
|
67 | 65 | |
68 | 66 | try { |
69 | 67 | self::$data = self::select($query); |
@@ -81,7 +79,7 @@ discard block |
||
81 | 79 | ob_get_clean(); |
82 | 80 | $tableId = filter_input(INPUT_GET, 'table-id') ?: null; |
83 | 81 | if ($tableId === self::$t['items'] . '-table') { |
84 | - if ( ! self::$export) { |
|
82 | + if (!self::$export) { |
|
85 | 83 | header('Content-Type: application/json'); |
86 | 84 | $jsonArr = ['body' => self::jsonGetBodyData(), |
87 | 85 | 'footer' => self::jsonGetFooterData()]; |
@@ -99,8 +97,7 @@ discard block |
||
99 | 97 | public static function prepare($setOrCheck = false) |
100 | 98 | { |
101 | 99 | //@see http://php.net/manual/es/function.filter-input.php#77307 |
102 | - $uri = filter_input(INPUT_SERVER, 'REQUEST_URI', FILTER_SANITIZE_URL) ?: |
|
103 | - filter_var($_SERVER['REQUEST_URI'], FILTER_SANITIZE_URL); |
|
100 | + $uri = filter_input(INPUT_SERVER, 'REQUEST_URI', FILTER_SANITIZE_URL) ?: filter_var($_SERVER['REQUEST_URI'], FILTER_SANITIZE_URL); |
|
104 | 101 | |
105 | 102 | $extension = pathinfo(strtok($uri, '?'), PATHINFO_EXTENSION); |
106 | 103 | |
@@ -108,7 +105,7 @@ discard block |
||
108 | 105 | self::$pageExt = strtolower($extension); |
109 | 106 | |
110 | 107 | if (self::$helper_class::prepare(__METHOD__, $setOrCheck) !== true) { |
111 | - if (self::$pageExt === 'json' && ! isset(self::$t['prepared'])) { |
|
108 | + if (self::$pageExt === 'json' && !isset(self::$t['prepared'])) { |
|
112 | 109 | ob_start(); |
113 | 110 | self::$t['prepared'] = true; |
114 | 111 | } |