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

contributte / datagrid / 11630384001

01 Nov 2024 01:47PM UTC coverage: 34.009%. Remained the same
11630384001

Pull #1153

github

web-flow
Merge 6f44dbf50 into 0105ca358
Pull Request #1153: fix: adding multiple listeners to the same element

1 of 2 new or added lines in 2 files covered. (50.0%)

1124 of 3305 relevant lines covered (34.01%)

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\Fluent;
11
use Dibi\Helpers;
12
use Dibi\Result;
13
use UnexpectedValueException;
14

15
class DibiFluentMssqlDataSource extends DibiFluentDataSource
16
{
17

18
        protected array $data = [];
19

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

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

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

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

40
                return $this;
×
41
        }
42

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

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

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

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

56
                return $this;
×
57
        }
58

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

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

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

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

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

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

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

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

109
                foreach ($condition as $column => $value) {
×
NEW
110
                        $column = Helpers::escape($driver, $column, Fluent::Identifier);
×
111

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

115
                                continue;
×
116
                        }
117

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

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

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