Passed
Push — master ( 74b95b...af185e )
by Plamen
01:33
created

trait_helper::assets()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
trait trait_helper
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 Errors collector */
16
    protected static $errors = [];
17
    /** @param array Collector (values for current table call) */
18
    protected static $t = ['page' => 1, 'tables' => []];
19
20
    public static function assets($path = "/public/table")
21
    {
22
        return "<script src=\"{$path}/table_helper.js\" defer></script>\n\t" .
23
            "<script src=\"{$path}/table.js\" defer></script>\n\t" .
24
            "<link href=\"{$path}/table.css\" rel=\"stylesheet\">\n";
25
    }
26
27
    /** Array to space separated key value list
28
     * @param array $attributes
29
     * @return string */
30
    protected static function attributes(array $attributes)
31
    {
32
        $list = [' '];
33
        foreach ($attributes as $key => $value) {
34
            if ($value === true || (empty($value) && $value != 0)) {
35
                $list[] = $key;
36
            } else {
37
                $list[] = $key . '="' . $value . '"';
38
            }
39
        }
40
        return rtrim(implode(' ', $list));
41
    }
42
43
    protected static function error($message = null)
44
    {
45
        if (isset($message)) {
46
            self::$errors[] = $message;
47
        } else {
48
            return empty(self::$errors) ? null :
49
                '<p class="tbl-err">' . implode('</br>', self::$errors) . '</p>';
50
        }
51
    }
52
53
    /** Parses view to string
54
     * @param string    $template
55
     * @param array     $vars
56
     * @return string */
57
    protected static function view($template, $vars = [])
58
    {
59
        extract($vars);
60
        ob_start();
61
        require $template;
62
        return (string) ob_get_clean();
63
    }
64
65
    /** Needed for more than one table on page
66
     * @param strings $items */
0 ignored issues
show
Bug introduced by
The type strings was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
67
    protected static function reset($items)
68
    {
69
        if (!in_array($items, self::$t["tables"])) {
70
            self::$t["tables"][] = $items;
71
            self::$cols = [];
72
            self::$t['rows'] = null;
73
        } else {
74
            echo 'Existing table-id used in table::create(): ' . $items;
75
        }
76
    }
77
}
78