Passed
Push — main ( 65d634...249587 )
by Thierry
19:37 queued 17:18
created

SelectTrait   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 27
c 1
b 0
f 0
dl 0
loc 93
rs 10
wmc 9

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getSortingOptions() 0 14 2
A getLengthOptions() 0 3 2
A getColumnsOptions() 0 8 1
A getLimitOptions() 0 3 1
A getFiltersOptions() 0 13 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" ? $this->utils->str->html($options["fulltext"][$i]) : '';
40
        }
41
        return [
42
            // 'where' => $where,
43
            'values' => (array)$options["where"],
44
            'columns' => $columns,
45
            'indexes' => $indexes,
46
            'operators' => $this->driver->operators(),
47
            'fulltexts' => $fulltexts,
48
        ];
49
    }
50
51
    /**
52
     * Print order box in select
53
     *
54
     * @param array $columns Selectable columns
55
     * @param array $options
56
     *
57
     * @return array
58
     */
59
    private function getSortingOptions(array $columns, array $options): array
60
    {
61
        $values = [];
62
        $descs = (array)$options["desc"];
63
        foreach ((array)$options["order"] as $key => $value) {
64
            $values[] = [
65
                'col' => $value,
66
                'desc' => $descs[$key] ?? 0,
67
            ];
68
        }
69
        return [
70
            // 'order' => $order,
71
            'values' => $values,
72
            'columns' => $columns,
73
        ];
74
    }
75
76
    /**
77
     * Print limit box in select
78
     *
79
     * @param string $limit Result of processSelectLimit()
80
     *
81
     * @return array
82
     */
83
    private function getLimitOptions(string $limit): array
84
    {
85
        return ['value' => $this->utils->str->html($limit)];
86
    }
87
88
    /**
89
     * Print text length box in select
90
     *
91
     * @param int $textLength Result of processSelectLength()
92
     *
93
     * @return array
94
     */
95
    private function getLengthOptions(int $textLength): array
96
    {
97
        return ['value' => $textLength === 0 ? 0 : $this->utils->str->html($textLength)];
98
    }
99
}
100