SelectTrait   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 28
c 2
b 0
f 0
dl 0
loc 94
rs 10
wmc 9

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getColumnsOptions() 0 8 1
A getSortingOptions() 0 14 2
A getLengthOptions() 0 3 2
A getLimitOptions() 0 3 1
A getFiltersOptions() 0 14 3
1
<?php
2
3
namespace Lagdo\DbAdmin\Db\Facades\Select;
4
5
trait SelectTrait
6
{
7
    /**
8
     * Print columns box in select
9
     *
10
     * @param array $select Result of processSelectColumns()[0]
11
     * @param array $columns Selectable columns
12
     * @param array $options
13
     * @return array
14
     */
15
    private function getColumnsOptions(array $select, array $columns, array $options): array
16
    {
17
        return [
18
            'select' => $select,
19
            'values' => (array)$options["columns"],
20
            'columns' => $columns,
21
            'functions' => $this->driver->functions(),
22
            'grouping' => $this->driver->grouping(),
23
        ];
24
    }
25
26
    /**
27
     * Print search box in select
28
     *
29
     * @param array $columns Selectable columns
30
     * @param array $indexes
31
     * @param array $options
32
     *
33
     * @return array
34
     */
35
    private function getFiltersOptions(array $columns, array $indexes, array $options): array
36
    {
37
        $fulltexts = [];
38
        foreach ($indexes as $i => $index) {
39
            $fulltexts[$i] = $index->type == "FULLTEXT" ?
40
                $this->utils->str->html($options["fulltext"][$i] ?? '') : '';
41
        }
42
        return [
43
            // 'where' => $where,
44
            'values' => (array)$options["where"],
45
            'columns' => $columns,
46
            'indexes' => $indexes,
47
            'operators' => $this->driver->operators(),
48
            'fulltexts' => $fulltexts,
49
        ];
50
    }
51
52
    /**
53
     * Print order box in select
54
     *
55
     * @param array $columns Selectable columns
56
     * @param array $options
57
     *
58
     * @return array
59
     */
60
    private function getSortingOptions(array $columns, array $options): array
61
    {
62
        $values = [];
63
        $descs = (array)$options["desc"];
64
        foreach ((array)$options["order"] as $key => $value) {
65
            $values[] = [
66
                'col' => $value,
67
                'desc' => $descs[$key] ?? 0,
68
            ];
69
        }
70
        return [
71
            // 'order' => $order,
72
            'values' => $values,
73
            'columns' => $columns,
74
        ];
75
    }
76
77
    /**
78
     * Print limit box in select
79
     *
80
     * @param string $limit Result of processSelectLimit()
81
     *
82
     * @return array
83
     */
84
    private function getLimitOptions(string $limit): array
85
    {
86
        return ['value' => $this->utils->str->html($limit)];
87
    }
88
89
    /**
90
     * Print text length box in select
91
     *
92
     * @param int $textLength Result of processSelectLength()
93
     *
94
     * @return array
95
     */
96
    private function getLengthOptions(int $textLength): array
97
    {
98
        return ['value' => $textLength === 0 ? 0 : $this->utils->str->html($textLength)];
99
    }
100
}
101