@@ -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) { |
@@ -155,9 +149,8 @@ discard block |
||
155 | 149 | |
156 | 150 | $output = fopen('php://output', 'w'); |
157 | 151 | foreach ($eData as $v) { |
158 | - self::$export ==='CSV' ? |
|
159 | - fputcsv($output, $v) : |
|
160 | - fputs($output, implode("\t", array_map($escape, $v)) . "\r\n"); |
|
152 | + self::$export === 'CSV' ? |
|
153 | + fputcsv($output, $v) : fputs($output, implode("\t", array_map($escape, $v)) . "\r\n"); |
|
161 | 154 | } |
162 | 155 | fclose($output); |
163 | 156 | break; |
@@ -170,7 +163,7 @@ discard block |
||
170 | 163 | foreach (self::$cols as $c) { |
171 | 164 | $outColumns[] = isset($c[1]) ? $c[1] : null; |
172 | 165 | } |
173 | - if ((self::$t['rows'] = count(self::$data))>0) { |
|
166 | + if ((self::$t['rows'] = count(self::$data)) > 0) { |
|
174 | 167 | foreach (self::$data as $row) { |
175 | 168 | $rowData = []; |
176 | 169 | foreach ($outColumns as $dbName) { |
@@ -189,9 +182,9 @@ discard block |
||
189 | 182 | protected static function jsonGetFooterData() |
190 | 183 | { |
191 | 184 | $jsonArrFooter = []; |
192 | - if (count(self::$data)>0) { |
|
185 | + if (count(self::$data) > 0) { |
|
193 | 186 | $pageNo = self::$t['page']; |
194 | - if ($pageNo ===1&&count(self::$data)<self::$t['paging']) { |
|
187 | + if ($pageNo === 1 && count(self::$data) < self::$t['paging']) { |
|
195 | 188 | //Skips total count query |
196 | 189 | self::$t['rows'] = count(self::$data); |
197 | 190 | } else { |
@@ -202,15 +195,14 @@ discard block |
||
202 | 195 | |
203 | 196 | $v = []; |
204 | 197 | |
205 | - $v['from'] = ($pageNo-1)*self::$t['paging']+1; |
|
206 | - $v['upto'] = ($pageNo*self::$t['paging']<self::$t['rows']) ? |
|
207 | - $pageNo*self::$t['paging'] : |
|
208 | - self::$t['rows']; |
|
198 | + $v['from'] = ($pageNo - 1)*self::$t['paging'] + 1; |
|
199 | + $v['upto'] = ($pageNo*self::$t['paging'] < self::$t['rows']) ? |
|
200 | + $pageNo*self::$t['paging'] : self::$t['rows']; |
|
209 | 201 | |
210 | 202 | $v["total"] = self::$t['rows']; |
211 | 203 | $v["items"] = self::$t['items']; |
212 | 204 | |
213 | - if (self::$exportActive ===true) { |
|
205 | + if (self::$exportActive === true) { |
|
214 | 206 | $url = strtok(self::$t['slug'], "?&") . ".json?table=" . |
215 | 207 | self::$t['items'] . "&export="; |
216 | 208 | $v["export"] = ["url" => $url, "types" => self::config('SAVES')]; |
@@ -260,10 +252,10 @@ discard block |
||
260 | 252 | private static function rows($for) |
261 | 253 | { |
262 | 254 | $trs = ''; |
263 | - if ($for ==='body') { |
|
255 | + if ($for === 'body') { |
|
264 | 256 | foreach (self::jsonGetBodyData() as $r) { |
265 | - if (isset($r[0][1], $r[0][1]['class'])&& |
|
266 | - $r[0][1]['class'] ==='no-results' |
|
257 | + if (isset($r[0][1], $r[0][1]['class']) && |
|
258 | + $r[0][1]['class'] === 'no-results' |
|
267 | 259 | ) { |
268 | 260 | $trs .= '<tr><td' . self::attributes($r[0][1]) . '>' |
269 | 261 | . $r[0][0] . '</td></tr>'; |
@@ -272,8 +264,8 @@ discard block |
||
272 | 264 | . '</td></tr>'; |
273 | 265 | } |
274 | 266 | } |
275 | - } else if ($for ==='footer') { |
|
276 | - if (self::$t['rows']>0) { |
|
267 | + } else if ($for === 'footer') { |
|
268 | + if (self::$t['rows'] > 0) { |
|
277 | 269 | $ftr = self::jsonGetFooterData()[0][0]; |
278 | 270 | $trs .= '<tr><td' . self::attributes($ftr[1]) . '>' |
279 | 271 | . $ftr[0] . '</td></tr>'; |
@@ -295,13 +287,12 @@ discard block |
||
295 | 287 | |
296 | 288 | static function select(string $expression, array $bindings = []) |
297 | 289 | { |
298 | - if (is_object(static::$select)&&(static::$select instanceof Closure)) { |
|
290 | + if (is_object(static::$select) && (static::$select instanceof Closure)) { |
|
299 | 291 | $select = static::$select; |
300 | 292 | $res = $select($expression, $bindings); |
301 | 293 | //if result is single cell value ($res[0]->value), return the value |
302 | - return (count($res) ===1&&count((array) $res[0]) ===1) ? |
|
303 | - reset($res[0]) : |
|
304 | - $res; |
|
294 | + return (count($res) === 1 && count((array)$res[0]) === 1) ? |
|
295 | + reset($res[0]) : $res; |
|
305 | 296 | } else { |
306 | 297 | die('ERROR: table::$select is not a valid closure. ' |
307 | 298 | . __METHOD__ . '() #' . __LINE__); |