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

contributte / datagrid / 8264560336

13 Mar 2024 12:24PM UTC coverage: 34.102% (-10.4%) from 44.533%
8264560336

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

613 existing lines in 31 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/AggregationFunction/FunctionSum.php
1
<?php declare(strict_types = 1);
2

3
namespace Contributte\Datagrid\AggregationFunction;
4

5
use Contributte\Datagrid\Utils\PropertyAccessHelper;
6
use Dibi\Fluent;
7
use Doctrine\Common\Collections\Collection;
8
use Doctrine\ORM\QueryBuilder;
9
use Nette\Database\Table\Selection;
10
use Nextras\Orm\Collection\DbalCollection;
11
use Nextras\Orm\Collection\ICollection;
12

13
class FunctionSum implements ISingleColumnAggregationFunction
14
{
15

16
        protected int $result = 0;
17

18
        /** @var callable|null */
19
        protected $renderer = null;
20

NEW
21
        public function __construct(protected string $column, protected string $dataType = IAggregationFunction::DATA_TYPE_PAGINATED)
×
22
        {
23
        }
24

25
        public function getFilterDataType(): string
26
        {
UNCOV
27
                return $this->dataType;
×
28
        }
29

30
        public function processDataSource(Fluent|QueryBuilder|Collection|Selection|ICollection $dataSource): void
31
        {
UNCOV
32
                if ($dataSource instanceof Fluent) {
×
UNCOV
33
                        $connection = $dataSource->getConnection();
×
UNCOV
34
                        $this->result = (int) $connection->select('SUM(%n)', $this->column)
×
UNCOV
35
                                ->from($dataSource, 's')
×
UNCOV
36
                                ->fetchSingle();
×
37
                }
38

UNCOV
39
                if ($dataSource instanceof QueryBuilder) {
×
NEW
40
                        $column = str_contains($this->column, '.')
×
UNCOV
41
                                ? $this->column
×
UNCOV
42
                                : current($dataSource->getRootAliases()) . '.' . $this->column;
×
43

NEW
44
                        $this->result = (int) $dataSource
×
UNCOV
45
                                ->select(sprintf('SUM(%s)', $column))
×
UNCOV
46
                                ->setMaxResults(1)
×
UNCOV
47
                                ->setFirstResult(0)
×
UNCOV
48
                                ->getQuery()
×
UNCOV
49
                                ->getSingleScalarResult();
×
50
                }
51

UNCOV
52
                if ($dataSource instanceof Collection) {
×
UNCOV
53
                        $dataSource->forAll(function ($key, $value): bool {
×
54
                                $this->result += PropertyAccessHelper::getValue($value, $this->column);
55

56
                                return true;
UNCOV
57
                        });
×
58
                }
59

NEW
60
                if ($dataSource instanceof DbalCollection) {
×
NEW
61
                        foreach ($dataSource->fetchAll() as $item)
×
NEW
62
                                $this->result += $item->getValue($this->column);
×
63
                }
64
        }
65

66
        public function renderResult(): mixed
67
        {
UNCOV
68
                $result = $this->result;
×
69

UNCOV
70
                if (isset($this->renderer)) {
×
UNCOV
71
                        $result = call_user_func($this->renderer, $result);
×
72
                }
73

UNCOV
74
                return $result;
×
75
        }
76

77
        /**
78
         * @return static
79
         */
80
        public function setRenderer(?callable $callback = null): self
81
        {
UNCOV
82
                $this->renderer = $callback;
×
83

UNCOV
84
                return $this;
×
85
        }
86

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