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

contributte / datagrid / 8230157862

11 Mar 2024 09:02AM UTC coverage: 34.102%. First build
8230157862

Pull #1060

github

radimvaculik
Fix failing tests
Pull Request #1060: [7.x] Next

117 of 435 new or added lines in 54 files covered. (26.9%)

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

26.47
/src/Filter/Filter.php
1
<?php declare(strict_types = 1);
2

3
namespace Contributte\Datagrid\Filter;
4

5
use Contributte\Datagrid\Datagrid;
6
use Nette\Forms\Container;
7
use Nette\Forms\Controls\BaseControl;
8

9
/**
10
 * @method void addToFormContainer(Container $container)
11
 */
12
abstract class Filter
13
{
14

15
        protected mixed $value;
16

17
        protected bool $valueSet = false;
18

19
        /** @var callable|null */
20
        protected $conditionCallback;
21

22
        protected ?string $template = null;
23

24
        protected ?string $type = null;
25

26
        protected array $attributes = [
27
                'class' => ['form-control', 'form-control-sm'],
28
        ];
29

30
        private ?string $placeholder = null;
31

32
        public function __construct(protected Datagrid $grid, protected string $key, protected string $name)
1✔
33
        {
34
        }
1✔
35

36
        abstract public function getCondition(): array;
37

38
        /**
39
         * Get filter key
40
         */
41
        public function getKey(): string
42
        {
43
                return $this->key;
×
44
        }
45

46
        /**
47
         * Get filter name
48
         */
49
        public function getName(): string
50
        {
51
                return $this->name;
×
52
        }
53

54
        /**
55
         * Tell whether value has been set in this fitler
56
         */
57
        public function isValueSet(): bool
58
        {
59
                return $this->valueSet;
1✔
60
        }
61

62
        /**
63
         * @return static
64
         */
65
        public function setValue(mixed $value): self
1✔
66
        {
67
                $this->value = $value;
1✔
68
                $this->valueSet = true;
1✔
69

70
                return $this;
1✔
71
        }
72

73
        public function getValue(): mixed
74
        {
75
                return $this->value;
1✔
76
        }
77

78
        /**
79
         * Set HTML attribute "placeholder"
80
         *
81
         * @return static
82
         */
83
        public function setPlaceholder(string $placeholder): self
84
        {
85
                $this->placeholder = $placeholder;
×
86

87
                return $this;
×
88
        }
89

90
        public function getPlaceholder(): ?string
91
        {
92
                return $this->placeholder;
×
93
        }
94

95
        /**
96
         * Set custom condition on filter
97
         *
98
         * @return static
99
         */
100
        public function setCondition(callable $conditionCallback): self
101
        {
102
                $this->conditionCallback = $conditionCallback;
×
103

104
                return $this;
×
105
        }
106

107
        public function getConditionCallback(): ?callable
108
        {
109
                return $this->conditionCallback;
1✔
110
        }
111

112
        /**
113
         * @return static
114
         */
115
        public function setTemplate(string $template): self
116
        {
117
                $this->template = $template;
×
118

119
                return $this;
×
120
        }
121

122
        public function getTemplate(): ?string
123
        {
124
                return $this->template;
×
125
        }
126

127
        public function getType(): ?string
128
        {
129
                return $this->type;
×
130
        }
131

132
        /**
133
         * @return static
134
         */
135
        public function addAttribute(string $name, mixed $value): self
136
        {
137
                $this->attributes[$name][] = $value;
×
138

139
                return $this;
×
140
        }
141

142
        /**
143
         * @return static
144
         */
145
        public function setAttribute(string $name, mixed $value): self
146
        {
147
                $this->attributes[$name] = (array) $value;
×
148

149
                return $this;
×
150
        }
151

152
        public function getAttributes(): array
153
        {
154
                return $this->attributes;
×
155
        }
156

157
        protected function addAttributes(BaseControl $input): BaseControl
158
        {
159
                if ($this->grid->hasAutoSubmit()) {
×
NEW
160
                        $input->setHtmlAttribute('data-autosubmit', true);
×
161
                } else {
NEW
162
                        $input->setHtmlAttribute('data-datagrid-manualsubmit', true);
×
163
                }
164

165
                foreach ($this->attributes as $key => $value) {
×
166
                        if (is_array($value)) {
×
167
                                $value = array_unique($value);
×
168
                                $value = implode(' ', $value);
×
169
                        }
170

NEW
171
                        $input->setHtmlAttribute($key, $value);
×
172
                }
173

174
                return $input;
×
175
        }
176

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

© 2026 Coveralls, Inc