1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheet\Cell; |
4
|
|
|
|
5
|
|
|
class DataValidation |
6
|
|
|
{ |
7
|
|
|
// Data validation types |
8
|
|
|
const TYPE_NONE = 'none'; |
9
|
|
|
const TYPE_CUSTOM = 'custom'; |
10
|
|
|
const TYPE_DATE = 'date'; |
11
|
|
|
const TYPE_DECIMAL = 'decimal'; |
12
|
|
|
const TYPE_LIST = 'list'; |
13
|
|
|
const TYPE_TEXTLENGTH = 'textLength'; |
14
|
|
|
const TYPE_TIME = 'time'; |
15
|
|
|
const TYPE_WHOLE = 'whole'; |
16
|
|
|
|
17
|
|
|
// Data validation error styles |
18
|
|
|
const STYLE_STOP = 'stop'; |
19
|
|
|
const STYLE_WARNING = 'warning'; |
20
|
|
|
const STYLE_INFORMATION = 'information'; |
21
|
|
|
|
22
|
|
|
// Data validation operators |
23
|
|
|
const OPERATOR_BETWEEN = 'between'; |
24
|
|
|
const OPERATOR_EQUAL = 'equal'; |
25
|
|
|
const OPERATOR_GREATERTHAN = 'greaterThan'; |
26
|
|
|
const OPERATOR_GREATERTHANOREQUAL = 'greaterThanOrEqual'; |
27
|
|
|
const OPERATOR_LESSTHAN = 'lessThan'; |
28
|
|
|
const OPERATOR_LESSTHANOREQUAL = 'lessThanOrEqual'; |
29
|
|
|
const OPERATOR_NOTBETWEEN = 'notBetween'; |
30
|
|
|
const OPERATOR_NOTEQUAL = 'notEqual'; |
31
|
|
|
private const DEFAULT_OPERATOR = self::OPERATOR_BETWEEN; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Formula 1. |
35
|
|
|
*/ |
36
|
|
|
private string $formula1 = ''; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Formula 2. |
40
|
|
|
*/ |
41
|
|
|
private string $formula2 = ''; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Type. |
45
|
|
|
*/ |
46
|
|
|
private string $type = self::TYPE_NONE; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Error style. |
50
|
|
|
*/ |
51
|
|
|
private string $errorStyle = self::STYLE_STOP; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Operator. |
55
|
|
|
*/ |
56
|
|
|
private string $operator = self::DEFAULT_OPERATOR; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Allow Blank. |
60
|
|
|
*/ |
61
|
|
|
private bool $allowBlank = false; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Show DropDown. |
65
|
|
|
*/ |
66
|
|
|
private bool $showDropDown = false; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Show InputMessage. |
70
|
|
|
*/ |
71
|
|
|
private bool $showInputMessage = false; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Show ErrorMessage. |
75
|
|
|
*/ |
76
|
|
|
private bool $showErrorMessage = false; |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Error title. |
80
|
|
|
*/ |
81
|
|
|
private string $errorTitle = ''; |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Error. |
85
|
|
|
*/ |
86
|
|
|
private string $error = ''; |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Prompt title. |
90
|
|
|
*/ |
91
|
|
|
private string $promptTitle = ''; |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Prompt. |
95
|
|
|
*/ |
96
|
|
|
private string $prompt = ''; |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Get Formula 1. |
100
|
|
|
*/ |
101
|
32 |
|
public function getFormula1(): string |
102
|
|
|
{ |
103
|
32 |
|
return $this->formula1; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Set Formula 1. |
108
|
21 |
|
* |
109
|
|
|
* @return $this |
110
|
21 |
|
*/ |
111
|
|
|
public function setFormula1(string $formula): static |
112
|
|
|
{ |
113
|
|
|
$this->formula1 = $formula; |
114
|
|
|
|
115
|
|
|
return $this; |
116
|
|
|
} |
117
|
|
|
|
118
|
30 |
|
/** |
119
|
|
|
* Get Formula 2. |
120
|
30 |
|
*/ |
121
|
|
|
public function getFormula2(): string |
122
|
30 |
|
{ |
123
|
|
|
return $this->formula2; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Set Formula 2. |
128
|
14 |
|
* |
129
|
|
|
* @return $this |
130
|
14 |
|
*/ |
131
|
|
|
public function setFormula2(string $formula): static |
132
|
|
|
{ |
133
|
|
|
$this->formula2 = $formula; |
134
|
|
|
|
135
|
|
|
return $this; |
136
|
|
|
} |
137
|
|
|
|
138
|
22 |
|
/** |
139
|
|
|
* Get Type. |
140
|
22 |
|
*/ |
141
|
|
|
public function getType(): string |
142
|
22 |
|
{ |
143
|
|
|
return $this->type; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Set Type. |
148
|
21 |
|
* |
149
|
|
|
* @return $this |
150
|
21 |
|
*/ |
151
|
|
|
public function setType(string $type): static |
152
|
|
|
{ |
153
|
|
|
$this->type = $type; |
154
|
|
|
|
155
|
|
|
return $this; |
156
|
|
|
} |
157
|
|
|
|
158
|
32 |
|
/** |
159
|
|
|
* Get Error style. |
160
|
32 |
|
*/ |
161
|
|
|
public function getErrorStyle(): string |
162
|
32 |
|
{ |
163
|
|
|
return $this->errorStyle; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Set Error style. |
168
|
12 |
|
* |
169
|
|
|
* @param string $errorStyle see self::STYLE_* |
170
|
12 |
|
* |
171
|
|
|
* @return $this |
172
|
|
|
*/ |
173
|
|
|
public function setErrorStyle(string $errorStyle): static |
174
|
|
|
{ |
175
|
|
|
$this->errorStyle = $errorStyle; |
176
|
|
|
|
177
|
|
|
return $this; |
178
|
|
|
} |
179
|
|
|
|
180
|
27 |
|
/** |
181
|
|
|
* Get Operator. |
182
|
27 |
|
*/ |
183
|
|
|
public function getOperator(): string |
184
|
27 |
|
{ |
185
|
|
|
return $this->operator; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* Set Operator. |
190
|
16 |
|
* |
191
|
|
|
* @return $this |
192
|
16 |
|
*/ |
193
|
|
|
public function setOperator(string $operator): static |
194
|
|
|
{ |
195
|
|
|
$this->operator = ($operator === '') ? self::DEFAULT_OPERATOR : $operator; |
196
|
|
|
|
197
|
|
|
return $this; |
198
|
|
|
} |
199
|
|
|
|
200
|
21 |
|
/** |
201
|
|
|
* Get Allow Blank. |
202
|
21 |
|
*/ |
203
|
|
|
public function getAllowBlank(): bool |
204
|
21 |
|
{ |
205
|
|
|
return $this->allowBlank; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* Set Allow Blank. |
210
|
16 |
|
* |
211
|
|
|
* @return $this |
212
|
16 |
|
*/ |
213
|
|
|
public function setAllowBlank(bool $allowBlank): static |
214
|
|
|
{ |
215
|
|
|
$this->allowBlank = $allowBlank; |
216
|
|
|
|
217
|
|
|
return $this; |
218
|
|
|
} |
219
|
|
|
|
220
|
30 |
|
/** |
221
|
|
|
* Get Show DropDown. |
222
|
30 |
|
*/ |
223
|
|
|
public function getShowDropDown(): bool |
224
|
30 |
|
{ |
225
|
|
|
return $this->showDropDown; |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* Set Show DropDown. |
230
|
12 |
|
* |
231
|
|
|
* @return $this |
232
|
12 |
|
*/ |
233
|
|
|
public function setShowDropDown(bool $showDropDown): static |
234
|
|
|
{ |
235
|
|
|
$this->showDropDown = $showDropDown; |
236
|
|
|
|
237
|
|
|
return $this; |
238
|
|
|
} |
239
|
|
|
|
240
|
29 |
|
/** |
241
|
|
|
* Get Show InputMessage. |
242
|
29 |
|
*/ |
243
|
|
|
public function getShowInputMessage(): bool |
244
|
29 |
|
{ |
245
|
|
|
return $this->showInputMessage; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* Set Show InputMessage. |
250
|
12 |
|
* |
251
|
|
|
* @return $this |
252
|
12 |
|
*/ |
253
|
|
|
public function setShowInputMessage(bool $showInputMessage): static |
254
|
|
|
{ |
255
|
|
|
$this->showInputMessage = $showInputMessage; |
256
|
|
|
|
257
|
|
|
return $this; |
258
|
|
|
} |
259
|
|
|
|
260
|
28 |
|
/** |
261
|
|
|
* Get Show ErrorMessage. |
262
|
28 |
|
*/ |
263
|
|
|
public function getShowErrorMessage(): bool |
264
|
28 |
|
{ |
265
|
|
|
return $this->showErrorMessage; |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
/** |
269
|
|
|
* Set Show ErrorMessage. |
270
|
12 |
|
* |
271
|
|
|
* @return $this |
272
|
12 |
|
*/ |
273
|
|
|
public function setShowErrorMessage(bool $showErrorMessage): static |
274
|
|
|
{ |
275
|
|
|
$this->showErrorMessage = $showErrorMessage; |
276
|
|
|
|
277
|
|
|
return $this; |
278
|
|
|
} |
279
|
|
|
|
280
|
28 |
|
/** |
281
|
|
|
* Get Error title. |
282
|
28 |
|
*/ |
283
|
|
|
public function getErrorTitle(): string |
284
|
28 |
|
{ |
285
|
|
|
return $this->errorTitle; |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
/** |
289
|
|
|
* Set Error title. |
290
|
12 |
|
* |
291
|
|
|
* @return $this |
292
|
12 |
|
*/ |
293
|
|
|
public function setErrorTitle(string $errorTitle): static |
294
|
|
|
{ |
295
|
|
|
$this->errorTitle = $errorTitle; |
296
|
|
|
|
297
|
|
|
return $this; |
298
|
|
|
} |
299
|
|
|
|
300
|
27 |
|
/** |
301
|
|
|
* Get Error. |
302
|
27 |
|
*/ |
303
|
|
|
public function getError(): string |
304
|
27 |
|
{ |
305
|
|
|
return $this->error; |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
/** |
309
|
|
|
* Set Error. |
310
|
12 |
|
* |
311
|
|
|
* @return $this |
312
|
12 |
|
*/ |
313
|
|
|
public function setError(string $error): static |
314
|
|
|
{ |
315
|
|
|
$this->error = $error; |
316
|
|
|
|
317
|
|
|
return $this; |
318
|
|
|
} |
319
|
|
|
|
320
|
27 |
|
/** |
321
|
|
|
* Get Prompt title. |
322
|
27 |
|
*/ |
323
|
|
|
public function getPromptTitle(): string |
324
|
27 |
|
{ |
325
|
|
|
return $this->promptTitle; |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
/** |
329
|
|
|
* Set Prompt title. |
330
|
12 |
|
* |
331
|
|
|
* @return $this |
332
|
12 |
|
*/ |
333
|
|
|
public function setPromptTitle(string $promptTitle): static |
334
|
|
|
{ |
335
|
|
|
$this->promptTitle = $promptTitle; |
336
|
|
|
|
337
|
|
|
return $this; |
338
|
|
|
} |
339
|
|
|
|
340
|
27 |
|
/** |
341
|
|
|
* Get Prompt. |
342
|
27 |
|
*/ |
343
|
|
|
public function getPrompt(): string |
344
|
27 |
|
{ |
345
|
|
|
return $this->prompt; |
346
|
|
|
} |
347
|
|
|
|
348
|
|
|
/** |
349
|
|
|
* Set Prompt. |
350
|
12 |
|
* |
351
|
|
|
* @return $this |
352
|
12 |
|
*/ |
353
|
|
|
public function setPrompt(string $prompt): static |
354
|
|
|
{ |
355
|
|
|
$this->prompt = $prompt; |
356
|
|
|
|
357
|
|
|
return $this; |
358
|
|
|
} |
359
|
|
|
|
360
|
27 |
|
/** |
361
|
|
|
* Get hash code. |
362
|
27 |
|
* |
363
|
|
|
* @return string Hash code |
364
|
27 |
|
*/ |
365
|
|
|
public function getHashCode(): string |
366
|
|
|
{ |
367
|
|
|
return md5( |
368
|
|
|
$this->formula1 |
369
|
|
|
. $this->formula2 |
370
|
|
|
. $this->type |
371
|
|
|
. $this->errorStyle |
372
|
11 |
|
. $this->operator |
373
|
|
|
. ($this->allowBlank ? 't' : 'f') |
374
|
11 |
|
. ($this->showDropDown ? 't' : 'f') |
375
|
11 |
|
. ($this->showInputMessage ? 't' : 'f') |
376
|
11 |
|
. ($this->showErrorMessage ? 't' : 'f') |
377
|
11 |
|
. $this->errorTitle |
378
|
11 |
|
. $this->error |
379
|
11 |
|
. $this->promptTitle |
380
|
11 |
|
. $this->prompt |
381
|
11 |
|
. $this->sqref |
382
|
11 |
|
. __CLASS__ |
383
|
11 |
|
); |
384
|
11 |
|
} |
385
|
11 |
|
|
386
|
11 |
|
private ?string $sqref = null; |
387
|
11 |
|
|
388
|
11 |
|
public function getSqref(): ?string |
389
|
11 |
|
{ |
390
|
11 |
|
return $this->sqref; |
391
|
|
|
} |
392
|
|
|
|
393
|
|
|
public function setSqref(?string $str): self |
394
|
|
|
{ |
395
|
|
|
$this->sqref = $str; |
396
|
3 |
|
|
397
|
|
|
return $this; |
398
|
3 |
|
} |
399
|
|
|
} |
400
|
|
|
|