Passed
Push — master ( 87f610...286eca )
by Plamen
02:07
created

trait_table_request::requestExport()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
trait trait_table_request
4
{
5
6
    private static function requestFilter()
7
    {
8
        $filter = filter_input(INPUT_GET, 'filter') ?: false;
9
        if ($filter) {
10
            $by = filter_input(INPUT_GET, 'filter-by', FILTER_VALIDATE_INT);
11
            if ($by === false || is_null($by)) {
12
                $by = self::requestFilterByAll();
13
            } else {
14
                $by = self::$cols[$by][1];
15
            }
16
            $by = 'CONCAT(" ",' . $by . ', " ")';
17
            if (self::config('FILTER_CASE_SENSITIVE') !== true) {
18
                $by .= ' COLLATE ' . self::config('DB_COLLATION_CI');
19
            }
20
            $filter = $by . ' LIKE ' . '"%' . $filter . '%"';
21
        }
22
        return $filter;
23
    }
24
25
    private static function requestFilterByAll()
26
    {
27
        $by = [];
28
        foreach (self::$cols as $v) {
29
            if (isset($v[2]['sort']) && $v[2]['sort'] === false) {
30
                continue;
31
            }
32
            $by[] = 'IFNULL(' . $v[1] . ', "")';
33
        }
34
        return 'CONCAT(' . implode(',', $by) . ')';
35
    }
36
37
    private static function requestOrderCol()
38
    {
39
        if (($col = filter_input(INPUT_GET, 'col', FILTER_VALIDATE_INT))) {
40
            return isset(self::$cols[$col][2]['sort']) ?
41
                    self::$cols[$col][2]['sort'] :
42
                    self::$cols[$col][1];
43
        }
44
        return self::$t['order']['col'];
45
    }
46
47
    private static function requestOrderDir()
48
    {
49
        $reset = filter_has_var(INPUT_GET, 'col') ? 'asc' : null;
50
        return in_array(filter_input(INPUT_GET, 'ord'), ['asc', 'desc']) ?
51
                filter_input(INPUT_GET, 'ord') :
52
                ($reset ?: self::$t['order']['dir']);
53
    }
54
55
    private static function requestExport()
56
    {
57
        $exp = filter_input(INPUT_GET, 'export', FILTER_SANITIZE_STRING);
58
        return in_array($exp, self::config('SAVES')) ? $exp : false;
59
    }
60
61
    private static function requestPage()
62
    {
63
        return filter_has_var(INPUT_GET, 'pg') && self::$export == false ?
64
                (int)filter_input(INPUT_GET, 'pg', FILTER_SANITIZE_NUMBER_INT) :
65
                self::$t['page'];
66
    }
67
}
68