|
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
|
|
|
|