• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

contributte / datagrid / 8685602316

13 Mar 2024 12:24PM UTC coverage: 34.102%. Remained the same
8685602316

push

github

web-flow
[7.x] Next (#1060)

* PHP 8.0

* Translator: switch from ITranslator to Translator (#973)

* [7.x] Bootstrap 5 + PHP 8 + vanilla javascript (#1021)

* Bootstrap 5

* Bootstrap 5 (docs)

* Bootstrap 5

* form-control -> form-select

* Bump bootstrap-select for Bootstrap 5 support

* Removed `input-sm` from Bootstrap 3

See https://getbootstrap.com/docs/4.0/migration/#forms-1

* Bootstrap 5: When selectpicker, replace form-select classes with form-control and refresh it

* Hide `underline` also for `dropdown-item`. And merged into one CSS rule.

* Update the filterMultiSelect initialization

* Text-align: left -> start

Co-authored-by: Radim Vaculík <radim.vaculik@gmail.com>
Co-authored-by: Jaroslav Líbal <jaroslav.libal@neatous.cz>

* [7.x] phpstan-deprecation-rules (#1061)

* Fix sort

* Add method for setting custom Action href, v6.x (#853)

* [7.x] Nextras ORM 4 support, closes #984

* Fix ElasticsearchDataSource.php data source (#1041)

* Error: Typed property Ublaboo\DataGrid\InlineEdit\InlineEdit::$itemID must not be accessed before initialization

* composer: allow-plugins: php-http/discovery

* ItemDetailForm: $httpPost: Typed property must not be accessed...

* phpstan: revert  --memory-limit=4G

* NetteDatabaseSelectionHelper: Context -> Explorer, getSupplementalDriver -> getDriver

* Update README.md

* Templates: fix variables

* data-bs-toggle attribute for multiaction button (#1072)

* dependabot.yml (#1078)

* Allow nette/utils:4.0 (#1077)

* Add onColumnShow and onColumnHide event methods (#1076)

* Add onColumnShow and onColumnHide event methods

* Add native type array

* Removed duplicity

* Return value of BackedEnum when reading Doctrine entity property. (#1081)

* Return value of BackedEnum when reading array value (#1083)

* Added method to check if filter is on default values; Closes #1082 (#1084)

* ublaboo -> contributte (#1067) (#1075)

* Delete depe... (continued)

117 of 435 new or added lines in 54 files covered. (26.9%)

1455 existing lines in 67 files now uncovered.

1124 of 3296 relevant lines covered (34.1%)

0.34 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.4
/src/DataSource/SearchParamsBuilder.php
1
<?php declare(strict_types = 1);
2

3
namespace Contributte\Datagrid\DataSource;
4

5
final class SearchParamsBuilder
6
{
7

8
        private array $sort = [];
9

10
        private ?int $from = null;
11

12
        private ?int $size = null;
13

14
        private array $phrasePrefixQueries = [];
15

16
        private array $matchQueries = [];
17

18
        private array $booleanMatchQueries = [];
19

20
        private array $rangeQueries = [];
21

22
        private array $idsQueries = [];
23

24
        public function __construct(private string $indexName)
1✔
25
        {
26
        }
1✔
27

28
        public function addPhrasePrefixQuery(string $field, string $query): void
1✔
29
        {
30
                $this->phrasePrefixQueries[] = [$field => $query];
1✔
31
        }
1✔
32

33
        public function addMatchQuery(string $field, mixed $query): void
1✔
34
        {
35
                $this->matchQueries[] = [$field => $query];
1✔
36
        }
1✔
37

38
        public function addBooleanMatchQuery(string $field, array $queries): void
1✔
39
        {
40
                $this->booleanMatchQueries[] = [$field => $queries];
1✔
41
        }
1✔
42

43
        public function addRangeQuery(string $field, ?int $from, ?int $to): void
1✔
44
        {
45
                $this->rangeQueries[] = [$field => ['from' => $from, 'to' => $to]];
1✔
46
        }
1✔
47

48
        public function addIdsQuery(array $ids): void
1✔
49
        {
50
                $this->idsQueries[] = $ids;
1✔
51
        }
1✔
52

53
        public function setSort(array $sort): void
1✔
54
        {
55
                $this->sort = $sort;
1✔
56
        }
1✔
57

58
        public function setFrom(int $from): void
1✔
59
        {
60
                $this->from = $from;
1✔
61
        }
1✔
62

63
        public function setSize(int $size): void
1✔
64
        {
65
                $this->size = $size;
1✔
66
        }
1✔
67

68
        public function buildParams(): array
69
        {
70
                $return = [
1✔
71
                        'index' => $this->indexName,
1✔
72
                ];
73

74
                if ($this->sort !== [] || ($this->from !== null) || ($this->size !== null)) {
1✔
75
                        $return['body'] = [];
1✔
76
                }
77

78
                if ($this->sort !== []) {
1✔
79
                        $return['body']['sort'] = $this->sort;
1✔
80
                }
81

82
                if ($this->from !== null) {
1✔
83
                        $return['body']['from'] = $this->from;
1✔
84
                }
85

86
                if ($this->size !== null) {
1✔
87
                        $return['body']['size'] = $this->size;
1✔
88
                }
89

90
                if ($this->phrasePrefixQueries === []
1✔
91
                        && $this->matchQueries === []
1✔
92
                        && $this->booleanMatchQueries === []
1✔
93
                        && $this->rangeQueries === []
1✔
94
                        && $this->idsQueries === []) {
1✔
95
                        return $return;
1✔
96
                }
97

98
                $return['body']['query'] = [
1✔
99
                        'bool' => [
100
                                'must' => [],
101
                        ],
102
                ];
103

104
                foreach ($this->phrasePrefixQueries as $phrasePrefixQuery) {
1✔
105
                        foreach ($phrasePrefixQuery as $field => $query) {
1✔
106
                                $return['body']['query']['bool']['must'][] = [
1✔
107
                                        'multi_match' => [
108
                                                'query' => $query,
1✔
109
                                                'type' => 'phrase_prefix',
1✔
110
                                                'fields' => [$field],
1✔
111
                                        ],
112
                                ];
113
                        }
114
                }
115

116
                foreach ($this->matchQueries as $matchQuery) {
1✔
117
                        foreach ($matchQuery as $field => $query) {
1✔
118
                                $return['body']['query']['bool']['must'][] = [
1✔
119
                                        'match' => [
120
                                                $field => [
121
                                                        'query' => $query,
1✔
122
                                                ],
123
                                        ],
124
                                ];
125
                        }
126
                }
127

128
                foreach ($this->booleanMatchQueries as $booleanMatchQuery) {
1✔
129
                        foreach ($booleanMatchQuery as $field => $queries) {
1✔
130
                                if ($queries === []) {
1✔
UNCOV
131
                                        continue;
×
132
                                }
133

134
                                $boolFilter = [];
1✔
135

136
                                foreach ($queries as $query) {
1✔
137
                                        $boolFilter[] = [
1✔
138
                                                'match' => [
139
                                                        $field => [
140
                                                                'query' => $query,
1✔
141
                                                        ],
142
                                                ],
143
                                        ];
144
                                }
145

146
                                $return['body']['query']['bool']['must'][] = [
1✔
147
                                        'bool' => [
148
                                                'should' => [$boolFilter],
1✔
149
                                        ],
150
                                ];
151
                        }
152
                }
153

154
                foreach ($this->rangeQueries as $rangeQuery) {
1✔
155
                        foreach ($rangeQuery as $field => $range) {
1✔
156
                                if ($range['from'] === null && $range['to'] === null) {
1✔
UNCOV
157
                                        continue;
×
158
                                }
159

160
                                $rangeFilter = ['range' => [$field => []]];
1✔
161

162
                                if ($range['from'] !== null) {
1✔
163
                                        $rangeFilter['range'][$field]['gte'] = $range['from'];
1✔
164
                                }
165

166
                                if ($range['to'] !== null) {
1✔
167
                                        $rangeFilter['range'][$field]['lte'] = $range['to'];
1✔
168
                                }
169

170
                                $return['body']['query']['bool']['must'][] = $rangeFilter;
1✔
171
                        }
172
                }
173

174
                foreach ($this->idsQueries as $ids) {
1✔
175
                        $return['body']['query']['bool']['must'][] = [
1✔
176
                                'ids' => [
177
                                        'values' => $ids,
1✔
178
                                ],
179
                        ];
180
                }
181

182
                return $return;
1✔
183
        }
184

185
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc