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

contributte / datagrid / 8416932662

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

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/DibiFluentMssqlDataSource.php
1
<?php declare(strict_types = 1);
2

3
namespace Contributte\Datagrid\DataSource;
4

5
use Contributte\Datagrid\Exception\DatagridDateTimeHelperException;
6
use Contributte\Datagrid\Filter\FilterDate;
7
use Contributte\Datagrid\Filter\FilterDateRange;
8
use Contributte\Datagrid\Filter\FilterText;
9
use Contributte\Datagrid\Utils\DateTimeHelper;
10
use dibi;
11
use Dibi\Fluent;
12
use Dibi\Helpers;
13
use Dibi\Result;
14
use UnexpectedValueException;
15

16
class DibiFluentMssqlDataSource extends DibiFluentDataSource
17
{
18

19
        protected array $data = [];
20

21
        public function __construct(Fluent $dataSource, string $primaryKey)
22
        {
23
                parent::__construct($dataSource, $primaryKey);
×
24
        }
25

26
        public function getCount(): int
27
        {
28
                $clone = clone $this->dataSource;
×
UNCOV
29
                $clone->removeClause('ORDER BY');
×
30

UNCOV
31
                return $clone->count();
×
32
        }
33

34
        /**
35
         * {@inheritDoc}
36
         */
37
        public function filterOne(array $condition): IDataSource
38
        {
39
                $this->dataSource->where($condition);
×
40

UNCOV
41
                return $this;
×
42
        }
43

44
        public function limit(int $offset, int $limit): IDataSource
45
        {
UNCOV
46
                $sql = (string) $this->dataSource;
×
47

UNCOV
48
                $result = $this->dataSource->getConnection()
×
49
                        ->query('%sql OFFSET ? ROWS FETCH NEXT ? ROWS ONLY', $sql, $offset, $limit);
×
50

UNCOV
51
                if (!$result instanceof Result) {
×
52
                        throw new UnexpectedValueException();
×
53
                }
54

UNCOV
55
                $this->data = $result->fetchAll();
×
56

57
                return $this;
×
58
        }
59

60
        protected function applyFilterDate(FilterDate $filter): void
61
        {
UNCOV
62
                $conditions = $filter->getCondition();
×
63

64
                try {
UNCOV
65
                        $date = DateTimeHelper::tryConvertToDateTime(
×
UNCOV
66
                                $conditions[$filter->getColumn()],
×
UNCOV
67
                                [$filter->getPhpFormat()]
×
68
                        );
69

70
                        $this->dataSource->where(
×
71
                                'CONVERT(varchar(10), %n, 112) = ?',
×
UNCOV
72
                                $filter->getColumn(),
×
73
                                $date->format('Ymd')
×
74
                        );
NEW
75
                } catch (DatagridDateTimeHelperException) {
×
76
                        // ignore the invalid filter value
77
                }
78
        }
79

80
        protected function applyFilterDateRange(FilterDateRange $filter): void
81
        {
82
                $conditions = $filter->getCondition();
×
83

UNCOV
84
                $valueFrom = $conditions[$filter->getColumn()]['from'];
×
UNCOV
85
                $valueTo = $conditions[$filter->getColumn()]['to'];
×
86

UNCOV
87
                if ($valueFrom) {
×
UNCOV
88
                        $this->dataSource->where(
×
UNCOV
89
                                'CONVERT(varchar(10), %n, 112) >= ?',
×
UNCOV
90
                                $filter->getColumn(),
×
91
                                $valueFrom
92
                        );
93
                }
94

95
                if ($valueTo) {
×
96
                        $this->dataSource->where(
×
UNCOV
97
                                'CONVERT(varchar(10), %n, 112) <= ?',
×
98
                                $filter->getColumn(),
×
99
                                $valueTo
100
                        );
101
                }
102
        }
103

104
        protected function applyFilterText(FilterText $filter): void
105
        {
106
                $condition = $filter->getCondition();
×
107
                $driver = $this->dataSource->getConnection()->getDriver();
×
UNCOV
108
                $or = [];
×
109

UNCOV
110
                foreach ($condition as $column => $value) {
×
NEW
111
                        $column = Helpers::escape($driver, $column, dibi::IDENTIFIER);
×
112

UNCOV
113
                        if ($filter->isExactSearch()) {
×
NEW
114
                                $this->dataSource->where(sprintf('%s = %%s', $column), $value);
×
115

UNCOV
116
                                continue;
×
117
                        }
118

NEW
119
                        $or[] = sprintf('%s LIKE "%%%s%%"', $column, $value);
×
120
                }
121

NEW
122
                if (count($or) > 1) {
×
UNCOV
123
                        $this->dataSource->where('(%or)', $or);
×
124
                } else {
UNCOV
125
                        $this->dataSource->where($or);
×
126
                }
127
        }
128

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