1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
trait TraitHelper |
4
|
|
|
{ |
5
|
|
|
/** @param array Columns (config) */ |
6
|
|
|
public static $cols; |
7
|
|
|
/** @param array Query result, allows altering before table::load() */ |
8
|
|
|
public static $data = []; |
9
|
|
|
/** @param bool Export flag (for current request) */ |
10
|
|
|
public static $export; |
11
|
|
|
/** @param bool Export is allowed (shows buttons in the tfoot) */ |
12
|
|
|
public static $exportActive = true; |
13
|
|
|
/** @param bool Export data altered (use false for pure result) */ |
14
|
|
|
public static $exportDataAsDisplayed = true; |
15
|
|
|
/** @param array Collector (values for current table call) */ |
16
|
|
|
protected static $t = ['page' => 1, 'tables' => []]; |
17
|
|
|
|
18
|
|
|
public static function assets($path = "/public/table") |
19
|
|
|
{ |
20
|
|
|
return "<script src=\"{$path}/table_helper.js\" defer></script>\n\t" . |
21
|
|
|
"<script src=\"{$path}/table.js\" defer></script>\n\t" . |
22
|
|
|
"<link href=\"{$path}/table.css\" rel=\"stylesheet\">\n"; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** Array to space separated key value list |
26
|
|
|
* @param array $attributes |
27
|
|
|
* @return string */ |
28
|
|
|
protected static function attributes(array $attributes) |
29
|
|
|
{ |
30
|
|
|
$list = [' ']; |
31
|
|
|
foreach ($attributes as $key => $value) { |
32
|
|
|
if ($value === true || (empty($value) && $value != 0)) { |
33
|
|
|
$list[] = $key; |
34
|
|
|
} else { |
35
|
|
|
$list[] = $key . '="' . $value . '"'; |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
return rtrim(implode(' ', $list)); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** Parses view to string |
42
|
|
|
* @param string $template |
43
|
|
|
* @param array $vars |
44
|
|
|
* @return string */ |
45
|
|
|
protected static function view($template, $vars = []) |
46
|
|
|
{ |
47
|
|
|
extract($vars); |
48
|
|
|
ob_start(); |
49
|
|
|
require $template; |
50
|
|
|
return (string) ob_get_clean(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** Needed for more than one table on page |
54
|
|
|
* @param string $items */ |
55
|
|
|
protected static function reset($items) |
56
|
|
|
{ |
57
|
|
|
if (!in_array($items, self::$t["tables"])) { |
58
|
|
|
self::$t["tables"][] = $items; |
59
|
|
|
self::$cols = []; |
60
|
|
|
self::$t['rows'] = null; |
61
|
|
|
} else { |
62
|
|
|
echo 'Existing table-id used in table::create(): ' . $items; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|