| @@ -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) { | 
| @@ -157,11 +151,10 @@ discard block | ||
| 157 | 151 |                  header('Content-Disposition:attachment; filename=' . | 
| 158 | 152 | $outFilename . '.csv'); | 
| 159 | 153 | |
| 160 | -                if(($output = fopen('php://output', 'w'))){ | |
| 154 | +                if (($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 | } | 
| @@ -175,7 +168,7 @@ discard block | ||
| 175 | 168 |          foreach (self::$cols as $c) { | 
| 176 | 169 | $outColumns[] = isset($c[1]) ? $c[1] : null; | 
| 177 | 170 | } | 
| 178 | -        if ((self::$t['rows'] = count(self::$data))>0) { | |
| 171 | +        if ((self::$t['rows'] = count(self::$data)) > 0) { | |
| 179 | 172 |              foreach (self::$data as $row) { | 
| 180 | 173 | $rowData = []; | 
| 181 | 174 |                  foreach ($outColumns as $dbName) { | 
| @@ -194,9 +187,9 @@ discard block | ||
| 194 | 187 | protected static function jsonGetFooterData() | 
| 195 | 188 |      { | 
| 196 | 189 | $jsonArrFooter = []; | 
| 197 | -        if (count(self::$data)>0) { | |
| 190 | +        if (count(self::$data) > 0) { | |
| 198 | 191 | $pageNo = self::$t['page']; | 
| 199 | -            if ($pageNo ===1&&count(self::$data)<self::$t['paging']) { | |
| 192 | +            if ($pageNo === 1 && count(self::$data) < self::$t['paging']) { | |
| 200 | 193 | //Skips total count query | 
| 201 | 194 | self::$t['rows'] = count(self::$data); | 
| 202 | 195 |              } else { | 
| @@ -207,15 +200,14 @@ discard block | ||
| 207 | 200 | |
| 208 | 201 | $v = []; | 
| 209 | 202 | |
| 210 | - $v['from'] = ($pageNo-1)*self::$t['paging']+1; | |
| 211 | - $v['upto'] = ($pageNo*self::$t['paging']<self::$t['rows']) ? | |
| 212 | - $pageNo*self::$t['paging'] : | |
| 213 | - self::$t['rows']; | |
| 203 | + $v['from'] = ($pageNo - 1)*self::$t['paging'] + 1; | |
| 204 | + $v['upto'] = ($pageNo*self::$t['paging'] < self::$t['rows']) ? | |
| 205 | + $pageNo*self::$t['paging'] : self::$t['rows']; | |
| 214 | 206 | |
| 215 | 207 | $v["total"] = self::$t['rows']; | 
| 216 | 208 | $v["items"] = self::$t['items']; | 
| 217 | 209 | |
| 218 | -            if (self::$exportActive ===true) { | |
| 210 | +            if (self::$exportActive === true) { | |
| 219 | 211 | $url = strtok(self::$t['slug'], "?&") . ".json?table=" . | 
| 220 | 212 | self::$t['items'] . "&export="; | 
| 221 | 213 |                  $v["export"] = ["url" => $url, "types" => self::config('SAVES')]; | 
| @@ -265,10 +257,10 @@ discard block | ||
| 265 | 257 | private static function rows($for) | 
| 266 | 258 |      { | 
| 267 | 259 | $trs = ''; | 
| 268 | -        if ($for ==='body') { | |
| 260 | +        if ($for === 'body') { | |
| 269 | 261 |              foreach (self::jsonGetBodyData() as $r) { | 
| 270 | - if (isset($r[0][1], $r[0][1]['class'])&& | |
| 271 | - $r[0][1]['class'] ==='no-results' | |
| 262 | + if (isset($r[0][1], $r[0][1]['class']) && | |
| 263 | + $r[0][1]['class'] === 'no-results' | |
| 272 | 264 |                  ) { | 
| 273 | 265 | $trs .= '<tr><td' . self::attributes($r[0][1]) . '>' | 
| 274 | 266 | . $r[0][0] . '</td></tr>'; | 
| @@ -277,8 +269,8 @@ discard block | ||
| 277 | 269 | . '</td></tr>'; | 
| 278 | 270 | } | 
| 279 | 271 | } | 
| 280 | -        } else if ($for ==='footer') { | |
| 281 | -            if (self::$t['rows']>0) { | |
| 272 | +        } else if ($for === 'footer') { | |
| 273 | +            if (self::$t['rows'] > 0) { | |
| 282 | 274 | $ftr = self::jsonGetFooterData()[0][0]; | 
| 283 | 275 | $trs .= '<tr><td' . self::attributes($ftr[1]) . '>' | 
| 284 | 276 | . $ftr[0] . '</td></tr>'; | 
| @@ -300,13 +292,12 @@ discard block | ||
| 300 | 292 | |
| 301 | 293 | static function select(string $expression, array $bindings = []) | 
| 302 | 294 |      { | 
| 303 | -        if (is_object(static::$select)&&(static::$select instanceof Closure)) { | |
| 295 | +        if (is_object(static::$select) && (static::$select instanceof Closure)) { | |
| 304 | 296 | $select = static::$select; | 
| 305 | 297 | $res = $select($expression, $bindings); | 
| 306 | 298 | //if result is single cell value ($res[0]->value), return the value | 
| 307 | - return (count($res) ===1&&count((array) $res[0]) ===1) ? | |
| 308 | - reset($res[0]) : | |
| 309 | - $res; | |
| 299 | + return (count($res) === 1 && count((array)$res[0]) === 1) ? | |
| 300 | + reset($res[0]) : $res; | |
| 310 | 301 |          } else { | 
| 311 | 302 |              die('ERROR: table::$select is not a valid closure. ' | 
| 312 | 303 | . __METHOD__ . '() #' . __LINE__); |