@@ -14,13 +14,12 @@ discard block |
||
14 | 14 | |
15 | 15 | $limit = 10; |
16 | 16 | |
17 | - $v['start'] = $v['page'] > ($limit / 2) ? |
|
18 | - ($v['page'] - $limit / 2) : |
|
19 | - 1; |
|
17 | + $v['start'] = $v['page'] > ($limit/2) ? |
|
18 | + ($v['page'] - $limit/2) : 1; |
|
20 | 19 | |
21 | - if ($v['page'] > ($v['pages'] - ($limit / 2))) { |
|
20 | + if ($v['page'] > ($v['pages'] - ($limit/2))) { |
|
22 | 21 | $v['final'] = $v['pages']; |
23 | - } else if ($v['page'] > ($limit / 2)) { |
|
22 | + } else if ($v['page'] > ($limit/2)) { |
|
24 | 23 | $v['final'] = $v['start'] + $limit; |
25 | 24 | } else { |
26 | 25 | $v['final'] = $limit; |
@@ -44,12 +43,11 @@ discard block |
||
44 | 43 | $add = '<li class="jump"><a>' . self::jumps($m, $direction) . '</a></li>'; |
45 | 44 | |
46 | 45 | $jump_exists = $direction === '-' ? |
47 | - (self::$t['page'] - $m) > 0 : |
|
48 | - (self::$t['page'] + $m) <= self::$t['pages']; |
|
46 | + (self::$t['page'] - $m) > 0 : (self::$t['page'] + $m) <= self::$t['pages']; |
|
49 | 47 | |
50 | 48 | if ($jump_exists) { |
51 | 49 | $html = $direction === '-' ? $add . $html : $html . $add; |
52 | - return self::pagingJumps($html, ($m * 10)); |
|
50 | + return self::pagingJumps($html, ($m*10)); |
|
53 | 51 | } |
54 | 52 | |
55 | 53 | return $html; |
@@ -58,9 +56,9 @@ discard block |
||
58 | 56 | private static function jumps($m, $direction) |
59 | 57 | { |
60 | 58 | if ($m >= 1000000) { |
61 | - return ($direction . ($m / 1000000) . "M"); |
|
59 | + return ($direction . ($m/1000000) . "M"); |
|
62 | 60 | } else if ($m >= 1000) { |
63 | - return ($direction . ($m / 1000) . "K"); |
|
61 | + return ($direction . ($m/1000) . "K"); |
|
64 | 62 | } else { |
65 | 63 | return ($direction . $m); |
66 | 64 | } |
@@ -48,16 +48,14 @@ discard block |
||
48 | 48 | $rows = [$header]; |
49 | 49 | |
50 | 50 | $data = self::$exportDataAsDisplayed ? |
51 | - self::$data : |
|
52 | - self::select(self::$t['q']); |
|
51 | + self::$data : self::select(self::$t['q']); |
|
53 | 52 | |
54 | 53 | if (count($data) > 0) { |
55 | 54 | foreach ($data as $row) { |
56 | 55 | $cells = []; |
57 | - foreach($columns as $column){ |
|
56 | + foreach ($columns as $column) { |
|
58 | 57 | $cells[] = is_array($row[$column]) ? |
59 | - $row[$column][0] : |
|
60 | - $row[$column]; |
|
58 | + $row[$column][0] : $row[$column]; |
|
61 | 59 | } |
62 | 60 | $rows[] = $cells; |
63 | 61 | } |
@@ -95,8 +93,7 @@ discard block |
||
95 | 93 | if (($output = fopen('php://output', 'w'))) { |
96 | 94 | foreach ($eData as $v) { |
97 | 95 | self::$export === 'CSV' ? |
98 | - fputcsv($output, $v) : |
|
99 | - fputs($output, implode("\t", array_map($escape, $v)) . "\r\n"); |
|
96 | + fputcsv($output, $v) : fputs($output, implode("\t", array_map($escape, $v)) . "\r\n"); |
|
100 | 97 | } |
101 | 98 | fclose($output); |
102 | 99 | } |
@@ -38,12 +38,11 @@ discard block |
||
38 | 38 | $q = 'SELECT COUNT(*) FROM (' . self::$t['qAll'] . ') AS dt'; |
39 | 39 | self::$t['rows'] = self::select($q); |
40 | 40 | } |
41 | - self::$t['pages'] = ceil(self::$t['rows'] / self::$t['paging']); |
|
41 | + self::$t['pages'] = ceil(self::$t['rows']/self::$t['paging']); |
|
42 | 42 | |
43 | - $v['from'] = ($pageNo - 1) * self::$t['paging'] + 1; |
|
44 | - $v['upto'] = ($pageNo * self::$t['paging'] < self::$t['rows']) ? |
|
45 | - $pageNo * self::$t['paging'] : |
|
46 | - self::$t['rows']; |
|
43 | + $v['from'] = ($pageNo - 1)*self::$t['paging'] + 1; |
|
44 | + $v['upto'] = ($pageNo*self::$t['paging'] < self::$t['rows']) ? |
|
45 | + $pageNo*self::$t['paging'] : self::$t['rows']; |
|
47 | 46 | |
48 | 47 | $v["total"] = self::$t['rows']; |
49 | 48 | $v["items"] = self::$t['items']; |
@@ -69,9 +68,8 @@ discard block |
||
69 | 68 | $select = static::$select; |
70 | 69 | $res = $select($expression, $bindings); |
71 | 70 | //if result is single cell value ($res[0]->value), return the value |
72 | - return (count($res) === 1 && count((array) $res[0]) === 1) ? |
|
73 | - reset($res[0]) : |
|
74 | - $res; |
|
71 | + return (count($res) === 1 && count((array)$res[0]) === 1) ? |
|
72 | + reset($res[0]) : $res; |
|
75 | 73 | } else { |
76 | 74 | throw new Exception('ERROR: table::$select is not a closure. '); |
77 | 75 | } |
@@ -25,8 +25,7 @@ discard block |
||
25 | 25 | public static function prepare($setOrCheck = false) |
26 | 26 | { |
27 | 27 | //@see http://php.net/manual/es/function.filter-input.php#77307 |
28 | - $uri = filter_input(INPUT_SERVER, 'REQUEST_URI', FILTER_SANITIZE_URL) ?: |
|
29 | - filter_var($_SERVER['REQUEST_URI'], FILTER_SANITIZE_URL); |
|
28 | + $uri = filter_input(INPUT_SERVER, 'REQUEST_URI', FILTER_SANITIZE_URL) ?: filter_var($_SERVER['REQUEST_URI'], FILTER_SANITIZE_URL); |
|
30 | 29 | |
31 | 30 | $extension = pathinfo(strtok($uri, '?'), PATHINFO_EXTENSION); |
32 | 31 | |
@@ -80,7 +79,7 @@ discard block |
||
80 | 79 | |
81 | 80 | $filter = self::$t['filter']; //self::requestFilter(); |
82 | 81 | $order = [self::$t['order']['col'] => self::$t['order']['dir']]; |
83 | - $offset = (self::$t['page'] - 1) * self::$t['paging']; |
|
82 | + $offset = (self::$t['page'] - 1)*self::$t['paging']; |
|
84 | 83 | $limit = [$offset, self::$t['paging']]; |
85 | 84 | self::$t['q'] = self::q($q, $filter, $order, $limit, true); |
86 | 85 |
@@ -46,8 +46,7 @@ discard block |
||
46 | 46 | private static function tagAttributes($tag, $items) |
47 | 47 | { |
48 | 48 | $attr = $tag === 'div' ? |
49 | - ['id' => $items . '-list', 'class' => 'table'] : |
|
50 | - ['id' => $items . '-table', 'data-table' => 'js', |
|
49 | + ['id' => $items . '-list', 'class' => 'table'] : ['id' => $items . '-table', 'data-table' => 'js', |
|
51 | 50 | 'data-sort-a' => self::config('UTF8_ASC_SYMBOL'), |
52 | 51 | 'data-sort-d' => self::config('UTF8_DESC_SYMBOL')]; |
53 | 52 | if (array_key_exists($tag, self::$attributes)) { |
@@ -84,8 +83,7 @@ discard block |
||
84 | 83 | if (isset($arg['width'])) { // Width attribute -> style |
85 | 84 | $width = 'width:' . $arg['width'] . ';'; |
86 | 85 | $arg['style'] = isset($arg['style']) ? |
87 | - $width . $arg['style'] : |
|
88 | - $width; |
|
86 | + $width . $arg['style'] : $width; |
|
89 | 87 | } |
90 | 88 | |
91 | 89 | if (($del = isset($arg['type']) && $arg['type'] == 'delete')) { |
@@ -94,7 +92,7 @@ discard block |
||
94 | 92 | $sort = isset($arg['sort']) ? $arg['sort'] : $col; |
95 | 93 | } |
96 | 94 | |
97 | - return array_diff_key((array) $arg, ['sort', 'type', 'width']); |
|
95 | + return array_diff_key((array)$arg, ['sort', 'type', 'width']); |
|
98 | 96 | } |
99 | 97 | |
100 | 98 | private static function th($i, $attr, $sort, $del, $lbl) |
@@ -106,8 +104,7 @@ discard block |
||
106 | 104 | if (!$del) { |
107 | 105 | if ($sort == self::$t['order']['col']) { |
108 | 106 | $span = self::$t['order']['dir'] === 'desc' ? |
109 | - self::config('UTF8_DESC_SYMBOL') : |
|
110 | - self::config('UTF8_ASC_SYMBOL'); |
|
107 | + self::config('UTF8_DESC_SYMBOL') : self::config('UTF8_ASC_SYMBOL'); |
|
111 | 108 | } else { |
112 | 109 | $span = ""; |
113 | 110 | } |
@@ -126,27 +123,25 @@ discard block |
||
126 | 123 | |
127 | 124 | protected static function request() |
128 | 125 | { |
129 | - $export = function(){ |
|
126 | + $export = function() { |
|
130 | 127 | $exp = filter_input(INPUT_GET, 'export', FILTER_SANITIZE_STRING); |
131 | 128 | return in_array($exp, self::config('SAVES')) ? $exp : false; |
132 | 129 | }; |
133 | - $order_dir = function(){ |
|
130 | + $order_dir = function() { |
|
134 | 131 | $reset = filter_has_var(INPUT_GET, 'col') ? 'asc' : null; |
135 | 132 | return |
136 | 133 | in_array(filter_input(INPUT_GET, 'ord'), ['asc', 'desc']) ? |
137 | - filter_input(INPUT_GET, 'ord') : |
|
138 | - ($reset ?: self::$t['order']['dir']); |
|
134 | + filter_input(INPUT_GET, 'ord') : ($reset ?: self::$t['order']['dir']); |
|
139 | 135 | }; |
140 | - $order_col = function(){ |
|
136 | + $order_col = function() { |
|
141 | 137 | $col = filter_input(INPUT_GET, 'col', FILTER_VALIDATE_INT); |
142 | 138 | if ($col) { |
143 | 139 | return isset(self::$cols[$col][2]['sort']) ? |
144 | - self::$cols[$col][2]['sort'] : |
|
145 | - self::$cols[$col][1]; |
|
140 | + self::$cols[$col][2]['sort'] : self::$cols[$col][1]; |
|
146 | 141 | } |
147 | 142 | return self::$t['order']['col']; |
148 | 143 | }; |
149 | - $filter = function(){ |
|
144 | + $filter = function() { |
|
150 | 145 | $filter = filter_input(INPUT_GET, 'filter') ?: false; |
151 | 146 | if ($filter) { |
152 | 147 | $by = filter_input(INPUT_GET, 'filter-by', FILTER_VALIDATE_INT); |
@@ -163,10 +158,9 @@ discard block |
||
163 | 158 | } |
164 | 159 | return $filter; |
165 | 160 | }; |
166 | - $page = function(){ |
|
161 | + $page = function() { |
|
167 | 162 | return filter_has_var(INPUT_GET, 'pg') && self::$export == false ? |
168 | - (int)filter_input(INPUT_GET, 'pg', FILTER_SANITIZE_NUMBER_INT) : |
|
169 | - self::$t['page']; |
|
163 | + (int)filter_input(INPUT_GET, 'pg', FILTER_SANITIZE_NUMBER_INT) : self::$t['page']; |
|
170 | 164 | }; |
171 | 165 | |
172 | 166 | self::$export = $export(); |