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

contributte / datagrid / 8875337512

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

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

12.73
/src/AggregationFunction/TDatagridAggregationFunction.php
1
<?php declare(strict_types = 1);
2

3
namespace Contributte\Datagrid\AggregationFunction;
4

5
use Contributte\Datagrid\DataModel;
6
use Contributte\Datagrid\DataSource\IDataSource;
7
use Contributte\Datagrid\Exception\DatagridException;
8

9
trait TDatagridAggregationFunction
10
{
11

12
        /** @var array|ISingleColumnAggregationFunction[] */
13
        private array $aggregationFunctions = [];
14

15
        private ?IMultipleAggregationFunction $multipleAggregationFunction = null;
16

17
        /**
18
         * @return static
19
         * @throws DatagridException
20
         */
21
        public function addAggregationFunction(
22
                string $key,
23
                ISingleColumnAggregationFunction $aggregationFunction
24
        ): self
25
        {
UNCOV
26
                if ($this->hasColumnsSummary()) {
×
NEW
27
                        throw new DatagridException('You can use either ColumnsSummary or AggregationFunctions');
×
28
                }
29

UNCOV
30
                if (!$this->dataModel instanceof DataModel) {
×
NEW
31
                        throw new DatagridException('You have to set a data source first.');
×
32
                }
33

UNCOV
34
                if (isset($this->aggregationFunctions[$key])) {
×
NEW
35
                        throw new DatagridException('There is already a AggregationFunction defined on column ' . $key);
×
36
                }
37

UNCOV
38
                if ($this->multipleAggregationFunction instanceof IMultipleAggregationFunction) {
×
NEW
39
                        throw new DatagridException('You can not use both AggregationFunctions and MultipleAggregationFunction');
×
40
                }
41

UNCOV
42
                $this->aggregationFunctions[$key] = $aggregationFunction;
×
43

UNCOV
44
                return $this;
×
45
        }
46

47
        /**
48
         * @return static
49
         * @throws DatagridException
50
         */
51
        public function setMultipleAggregationFunction(
52
                IMultipleAggregationFunction $multipleAggregationFunction
53
        ): self
54
        {
55
                if ($this->hasColumnsSummary()) {
×
NEW
56
                        throw new DatagridException('You can use either ColumnsSummary or AggregationFunctions');
×
57
                }
58

UNCOV
59
                if ($this->aggregationFunctions !== []) {
×
NEW
60
                        throw new DatagridException('You can not use both AggregationFunctions and MultipleAggregationFunction');
×
61
                }
62

UNCOV
63
                $this->multipleAggregationFunction = $multipleAggregationFunction;
×
64

UNCOV
65
                return $this;
×
66
        }
67

68
        /**
69
         * @throws DatagridException
70
         */
71
        public function beforeDataModelFilter(IDataSource $dataSource): void
1✔
72
        {
73
                if (!$this->hasSomeAggregationFunction()) {
1✔
74
                        return;
1✔
75
                }
76

UNCOV
77
                if (!$dataSource instanceof IAggregatable) {
×
NEW
78
                        throw new DatagridException('Used DataSource has to implement IAggregatable for aggegations to work');
×
79
                }
80

UNCOV
81
                if ($this->multipleAggregationFunction !== null) {
×
82
                        $type = $this->multipleAggregationFunction->getFilterDataType();
×
83

84
                        if ($type === IAggregationFunction::DATA_TYPE_ALL) {
×
UNCOV
85
                                $dataSource->processAggregation($this->multipleAggregationFunction);
×
86
                        }
87

UNCOV
88
                        return;
×
89
                }
90

UNCOV
91
                foreach ($this->aggregationFunctions as $aggregationFunction) {
×
UNCOV
92
                        if ($aggregationFunction->getFilterDataType() === IAggregationFunction::DATA_TYPE_ALL) {
×
UNCOV
93
                                $dataSource->processAggregation($aggregationFunction);
×
94
                        }
95
                }
96
        }
97

98
        /**
99
         * @throws DatagridException
100
         */
101
        public function afterDataModelFilter(IDataSource $dataSource): void
1✔
102
        {
103
                if (!$this->hasSomeAggregationFunction()) {
1✔
104
                        return;
1✔
105
                }
106

UNCOV
107
                if (!$dataSource instanceof IAggregatable) {
×
NEW
108
                        throw new DatagridException('Used DataSource has to implement IAggregatable for aggegations to work');
×
109
                }
110

111
                if ($this->multipleAggregationFunction !== null) {
×
UNCOV
112
                        if ($this->multipleAggregationFunction->getFilterDataType() === IAggregationFunction::DATA_TYPE_FILTERED) {
×
UNCOV
113
                                $dataSource->processAggregation($this->multipleAggregationFunction);
×
114
                        }
115

UNCOV
116
                        return;
×
117
                }
118

UNCOV
119
                foreach ($this->aggregationFunctions as $aggregationFunction) {
×
UNCOV
120
                        if ($aggregationFunction->getFilterDataType() === IAggregationFunction::DATA_TYPE_FILTERED) {
×
121
                                $dataSource->processAggregation($aggregationFunction);
×
122
                        }
123
                }
124
        }
125

126
        /**
127
         * @throws DatagridException
128
         */
129
        public function afterDataModelPaginated(IDataSource $dataSource): void
130
        {
UNCOV
131
                if (!$this->hasSomeAggregationFunction()) {
×
UNCOV
132
                        return;
×
133
                }
134

UNCOV
135
                if (!$dataSource instanceof IAggregatable) {
×
NEW
136
                        throw new DatagridException('Used DataSource has to implement IAggregatable for aggegations to work');
×
137
                }
138

UNCOV
139
                if ($this->multipleAggregationFunction !== null) {
×
UNCOV
140
                        if ($this->multipleAggregationFunction->getFilterDataType() === IAggregationFunction::DATA_TYPE_PAGINATED) {
×
UNCOV
141
                                $dataSource->processAggregation($this->multipleAggregationFunction);
×
142
                        }
143

UNCOV
144
                        return;
×
145
                }
146

UNCOV
147
                foreach ($this->aggregationFunctions as $aggregationFunction) {
×
UNCOV
148
                        if ($aggregationFunction->getFilterDataType() === IAggregationFunction::DATA_TYPE_PAGINATED) {
×
UNCOV
149
                                $dataSource->processAggregation($aggregationFunction);
×
150
                        }
151
                }
152
        }
153

154
        public function hasSomeAggregationFunction(): bool
155
        {
156
                return $this->aggregationFunctions !== [] || $this->multipleAggregationFunction !== null;
1✔
157
        }
158

159
        /**
160
         * @return array<ISingleColumnAggregationFunction>
161
         */
162
        public function getAggregationFunctions(): array
163
        {
UNCOV
164
                return $this->aggregationFunctions;
×
165
        }
166

167
        public function getMultipleAggregationFunction(): ?IMultipleAggregationFunction
168
        {
UNCOV
169
                return $this->multipleAggregationFunction;
×
170
        }
171

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