• 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

0.0
/src/DataSource/ApiDataSource.php
1
<?php declare(strict_types = 1);
2

3
namespace Contributte\Datagrid\DataSource;
4

5
use Contributte\Datagrid\Utils\Sorting;
6
use UnexpectedValueException;
7

8
class ApiDataSource implements IDataSource
9
{
10

11
        protected array $data = [];
12

13
        protected ?string $sortColumn = null;
14

15
        protected ?string $orderColumn = null;
16

17
        protected ?int $limit = null;
18

19
        protected ?int $offset = null;
20

21
        protected int $filterOne = 0;
22

23
        protected array $filter = [];
24

NEW
25
        public function __construct(protected string $url, protected array $queryParams = [])
×
26
        {
27
        }
28

29
        public function getCount(): int
30
        {
31
                return $this->getResponse(['count' => '']);
×
32
        }
33

34
        /**
35
         * {@inheritDoc}
36
         */
37
        public function getData(): array
38
        {
UNCOV
39
                return $this->data !== [] ? $this->data : $this->getResponse([
×
UNCOV
40
                        'sort' => $this->sortColumn,
×
UNCOV
41
                        'order' => $this->orderColumn,
×
UNCOV
42
                        'limit' => $this->limit,
×
43
                        'offset' => $this->offset,
×
44
                        'filter' => $this->filter,
×
UNCOV
45
                        'one' => $this->filterOne,
×
46
                ]);
47
        }
48

49
        /**
50
         * {@inheritDoc}
51
         */
52
        public function filter(array $filters): void
53
        {
54
                /**
55
                 * First, save all filter values to array
56
                 */
UNCOV
57
                foreach ($filters as $filter) {
×
UNCOV
58
                        if ($filter->isValueSet() && $filter->getConditionCallback() === null) {
×
UNCOV
59
                                $this->filter[$filter->getKey()] = $filter->getCondition();
×
60
                        }
61
                }
62

63
                /**
64
                 * Download filtered data
65
                 */
66
                $this->data = $this->getData();
×
67

68
                /**
69
                 * Apply possible user filter callbacks
70
                 */
UNCOV
71
                foreach ($filters as $filter) {
×
UNCOV
72
                        if ($filter->isValueSet() && $filter->getConditionCallback() !== null) {
×
UNCOV
73
                                $this->data = (array) call_user_func_array(
×
74
                                        $filter->getConditionCallback(),
×
75
                                        [$this->data, $filter->getValue()]
×
76
                                );
77
                        }
78
                }
79
        }
80

81
        /**
82
         * {@inheritDoc}
83
         */
84
        public function filterOne(array $condition): IDataSource
85
        {
UNCOV
86
                $this->filter = $condition;
×
UNCOV
87
                $this->filterOne = 1;
×
88

UNCOV
89
                return $this;
×
90
        }
91

92
        public function limit(int $offset, int $limit): IDataSource
93
        {
UNCOV
94
                $this->offset = $offset;
×
UNCOV
95
                $this->limit = $limit;
×
96

UNCOV
97
                return $this;
×
98
        }
99

100
        public function sort(Sorting $sorting): IDataSource
101
        {
102
                /**
103
                 * there is only one iteration
104
                 */
UNCOV
105
                foreach ($sorting->getSort() as $column => $order) {
×
UNCOV
106
                        $this->sortColumn = $column;
×
UNCOV
107
                        $this->orderColumn = $order;
×
108
                }
109

UNCOV
110
                return $this;
×
111
        }
112

113
        /**
114
         * Get data of remote source
115
         */
116
        protected function getResponse(array $params = []): mixed
117
        {
UNCOV
118
                $queryString = http_build_query($params + $this->queryParams);
×
UNCOV
119
                $url = sprintf('%s?%s', $this->url, $queryString);
×
120

UNCOV
121
                $content = file_get_contents($url);
×
122

UNCOV
123
                if ($content === false) {
×
UNCOV
124
                        throw new UnexpectedValueException(sprintf('Could not open URL %s', $url));
×
125
                }
126

NEW
127
                return json_decode($content, null, 512, JSON_THROW_ON_ERROR);
×
128
        }
129

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