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
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Formula 1. |
34
|
|
|
* |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
private $formula1 = ''; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Formula 2. |
41
|
|
|
* |
42
|
|
|
* @var string |
43
|
|
|
*/ |
44
|
|
|
private $formula2 = ''; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Type. |
48
|
|
|
* |
49
|
|
|
* @var string |
50
|
|
|
*/ |
51
|
|
|
private $type = self::TYPE_NONE; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Error style. |
55
|
|
|
* |
56
|
|
|
* @var string |
57
|
|
|
*/ |
58
|
|
|
private $errorStyle = self::STYLE_STOP; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Operator. |
62
|
|
|
* |
63
|
|
|
* @var string |
64
|
|
|
*/ |
65
|
|
|
private $operator = self::OPERATOR_BETWEEN; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Allow Blank. |
69
|
|
|
* |
70
|
|
|
* @var bool |
71
|
|
|
*/ |
72
|
|
|
private $allowBlank = false; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Show DropDown. |
76
|
|
|
* |
77
|
|
|
* @var bool |
78
|
|
|
*/ |
79
|
|
|
private $showDropDown = false; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Show InputMessage. |
83
|
|
|
* |
84
|
|
|
* @var bool |
85
|
|
|
*/ |
86
|
|
|
private $showInputMessage = false; |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Show ErrorMessage. |
90
|
|
|
* |
91
|
|
|
* @var bool |
92
|
|
|
*/ |
93
|
|
|
private $showErrorMessage = false; |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Error title. |
97
|
|
|
* |
98
|
|
|
* @var string |
99
|
|
|
*/ |
100
|
|
|
private $errorTitle = ''; |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Error. |
104
|
|
|
* |
105
|
|
|
* @var string |
106
|
|
|
*/ |
107
|
|
|
private $error = ''; |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Prompt title. |
111
|
|
|
* |
112
|
|
|
* @var string |
113
|
|
|
*/ |
114
|
|
|
private $promptTitle = ''; |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Prompt. |
118
|
|
|
* |
119
|
|
|
* @var string |
120
|
|
|
*/ |
121
|
|
|
private $prompt = ''; |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Create a new DataValidation. |
125
|
|
|
*/ |
126
|
28 |
|
public function __construct() |
127
|
|
|
{ |
128
|
28 |
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Get Formula 1. |
132
|
|
|
* |
133
|
|
|
* @return string |
134
|
|
|
*/ |
135
|
18 |
|
public function getFormula1() |
136
|
|
|
{ |
137
|
18 |
|
return $this->formula1; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Set Formula 1. |
142
|
|
|
* |
143
|
|
|
* @param string $formula |
144
|
|
|
* |
145
|
|
|
* @return $this |
146
|
|
|
*/ |
147
|
26 |
|
public function setFormula1($formula) |
148
|
|
|
{ |
149
|
26 |
|
$this->formula1 = $formula; |
150
|
|
|
|
151
|
26 |
|
return $this; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Get Formula 2. |
156
|
|
|
* |
157
|
|
|
* @return string |
158
|
|
|
*/ |
159
|
11 |
|
public function getFormula2() |
160
|
|
|
{ |
161
|
11 |
|
return $this->formula2; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* Set Formula 2. |
166
|
|
|
* |
167
|
|
|
* @param string $formula |
168
|
|
|
* |
169
|
|
|
* @return $this |
170
|
|
|
*/ |
171
|
19 |
|
public function setFormula2($formula) |
172
|
|
|
{ |
173
|
19 |
|
$this->formula2 = $formula; |
174
|
|
|
|
175
|
19 |
|
return $this; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* Get Type. |
180
|
|
|
* |
181
|
|
|
* @return string |
182
|
|
|
*/ |
183
|
18 |
|
public function getType() |
184
|
|
|
{ |
185
|
18 |
|
return $this->type; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* Set Type. |
190
|
|
|
* |
191
|
|
|
* @param string $type |
192
|
|
|
* |
193
|
|
|
* @return $this |
194
|
|
|
*/ |
195
|
28 |
|
public function setType($type) |
196
|
|
|
{ |
197
|
28 |
|
$this->type = $type; |
198
|
|
|
|
199
|
28 |
|
return $this; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* Get Error style. |
204
|
|
|
* |
205
|
|
|
* @return string |
206
|
|
|
*/ |
207
|
10 |
|
public function getErrorStyle() |
208
|
|
|
{ |
209
|
10 |
|
return $this->errorStyle; |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* Set Error style. |
214
|
|
|
* |
215
|
|
|
* @param string $errorStyle see self::STYLE_* |
216
|
|
|
* |
217
|
|
|
* @return $this |
218
|
|
|
*/ |
219
|
23 |
|
public function setErrorStyle($errorStyle) |
220
|
|
|
{ |
221
|
23 |
|
$this->errorStyle = $errorStyle; |
222
|
|
|
|
223
|
23 |
|
return $this; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* Get Operator. |
228
|
|
|
* |
229
|
|
|
* @return string |
230
|
|
|
*/ |
231
|
13 |
|
public function getOperator() |
232
|
|
|
{ |
233
|
13 |
|
return $this->operator; |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* Set Operator. |
238
|
|
|
* |
239
|
|
|
* @param string $operator |
240
|
|
|
* |
241
|
|
|
* @return $this |
242
|
|
|
*/ |
243
|
18 |
|
public function setOperator($operator) |
244
|
|
|
{ |
245
|
18 |
|
$this->operator = $operator; |
246
|
|
|
|
247
|
18 |
|
return $this; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* Get Allow Blank. |
252
|
|
|
* |
253
|
|
|
* @return bool |
254
|
|
|
*/ |
255
|
13 |
|
public function getAllowBlank() |
256
|
|
|
{ |
257
|
13 |
|
return $this->allowBlank; |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* Set Allow Blank. |
262
|
|
|
* |
263
|
|
|
* @param bool $allowBlank |
264
|
|
|
* |
265
|
|
|
* @return $this |
266
|
|
|
*/ |
267
|
26 |
|
public function setAllowBlank($allowBlank) |
268
|
|
|
{ |
269
|
26 |
|
$this->allowBlank = $allowBlank; |
270
|
|
|
|
271
|
26 |
|
return $this; |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
* Get Show DropDown. |
276
|
|
|
* |
277
|
|
|
* @return bool |
278
|
|
|
*/ |
279
|
10 |
|
public function getShowDropDown() |
280
|
|
|
{ |
281
|
10 |
|
return $this->showDropDown; |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* Set Show DropDown. |
286
|
|
|
* |
287
|
|
|
* @param bool $showDropDown |
288
|
|
|
* |
289
|
|
|
* @return $this |
290
|
|
|
*/ |
291
|
25 |
|
public function setShowDropDown($showDropDown) |
292
|
|
|
{ |
293
|
25 |
|
$this->showDropDown = $showDropDown; |
294
|
|
|
|
295
|
25 |
|
return $this; |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
/** |
299
|
|
|
* Get Show InputMessage. |
300
|
|
|
* |
301
|
|
|
* @return bool |
302
|
|
|
*/ |
303
|
10 |
|
public function getShowInputMessage() |
304
|
|
|
{ |
305
|
10 |
|
return $this->showInputMessage; |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
/** |
309
|
|
|
* Set Show InputMessage. |
310
|
|
|
* |
311
|
|
|
* @param bool $showInputMessage |
312
|
|
|
* |
313
|
|
|
* @return $this |
314
|
|
|
*/ |
315
|
24 |
|
public function setShowInputMessage($showInputMessage) |
316
|
|
|
{ |
317
|
24 |
|
$this->showInputMessage = $showInputMessage; |
318
|
|
|
|
319
|
24 |
|
return $this; |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
/** |
323
|
|
|
* Get Show ErrorMessage. |
324
|
|
|
* |
325
|
|
|
* @return bool |
326
|
|
|
*/ |
327
|
10 |
|
public function getShowErrorMessage() |
328
|
|
|
{ |
329
|
10 |
|
return $this->showErrorMessage; |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
/** |
333
|
|
|
* Set Show ErrorMessage. |
334
|
|
|
* |
335
|
|
|
* @param bool $showErrorMessage |
336
|
|
|
* |
337
|
|
|
* @return $this |
338
|
|
|
*/ |
339
|
24 |
|
public function setShowErrorMessage($showErrorMessage) |
340
|
|
|
{ |
341
|
24 |
|
$this->showErrorMessage = $showErrorMessage; |
342
|
|
|
|
343
|
24 |
|
return $this; |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
/** |
347
|
|
|
* Get Error title. |
348
|
|
|
* |
349
|
|
|
* @return string |
350
|
|
|
*/ |
351
|
10 |
|
public function getErrorTitle() |
352
|
|
|
{ |
353
|
10 |
|
return $this->errorTitle; |
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
/** |
357
|
|
|
* Set Error title. |
358
|
|
|
* |
359
|
|
|
* @param string $errorTitle |
360
|
|
|
* |
361
|
|
|
* @return $this |
362
|
|
|
*/ |
363
|
24 |
|
public function setErrorTitle($errorTitle) |
364
|
|
|
{ |
365
|
24 |
|
$this->errorTitle = $errorTitle; |
366
|
|
|
|
367
|
24 |
|
return $this; |
368
|
|
|
} |
369
|
|
|
|
370
|
|
|
/** |
371
|
|
|
* Get Error. |
372
|
|
|
* |
373
|
|
|
* @return string |
374
|
|
|
*/ |
375
|
10 |
|
public function getError() |
376
|
|
|
{ |
377
|
10 |
|
return $this->error; |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
/** |
381
|
|
|
* Set Error. |
382
|
|
|
* |
383
|
|
|
* @param string $error |
384
|
|
|
* |
385
|
|
|
* @return $this |
386
|
|
|
*/ |
387
|
24 |
|
public function setError($error) |
388
|
|
|
{ |
389
|
24 |
|
$this->error = $error; |
390
|
|
|
|
391
|
24 |
|
return $this; |
392
|
|
|
} |
393
|
|
|
|
394
|
|
|
/** |
395
|
|
|
* Get Prompt title. |
396
|
|
|
* |
397
|
|
|
* @return string |
398
|
|
|
*/ |
399
|
10 |
|
public function getPromptTitle() |
400
|
|
|
{ |
401
|
10 |
|
return $this->promptTitle; |
402
|
|
|
} |
403
|
|
|
|
404
|
|
|
/** |
405
|
|
|
* Set Prompt title. |
406
|
|
|
* |
407
|
|
|
* @param string $promptTitle |
408
|
|
|
* |
409
|
|
|
* @return $this |
410
|
|
|
*/ |
411
|
24 |
|
public function setPromptTitle($promptTitle) |
412
|
|
|
{ |
413
|
24 |
|
$this->promptTitle = $promptTitle; |
414
|
|
|
|
415
|
24 |
|
return $this; |
416
|
|
|
} |
417
|
|
|
|
418
|
|
|
/** |
419
|
|
|
* Get Prompt. |
420
|
|
|
* |
421
|
|
|
* @return string |
422
|
|
|
*/ |
423
|
10 |
|
public function getPrompt() |
424
|
|
|
{ |
425
|
10 |
|
return $this->prompt; |
426
|
|
|
} |
427
|
|
|
|
428
|
|
|
/** |
429
|
|
|
* Set Prompt. |
430
|
|
|
* |
431
|
|
|
* @param string $prompt |
432
|
|
|
* |
433
|
|
|
* @return $this |
434
|
|
|
*/ |
435
|
24 |
|
public function setPrompt($prompt) |
436
|
|
|
{ |
437
|
24 |
|
$this->prompt = $prompt; |
438
|
|
|
|
439
|
24 |
|
return $this; |
440
|
|
|
} |
441
|
|
|
|
442
|
|
|
/** |
443
|
|
|
* Get hash code. |
444
|
|
|
* |
445
|
|
|
* @return string Hash code |
446
|
|
|
*/ |
447
|
9 |
|
public function getHashCode() |
448
|
|
|
{ |
449
|
9 |
|
return md5( |
450
|
9 |
|
$this->formula1 . |
451
|
9 |
|
$this->formula2 . |
452
|
9 |
|
$this->type . |
453
|
9 |
|
$this->errorStyle . |
454
|
9 |
|
$this->operator . |
455
|
9 |
|
($this->allowBlank ? 't' : 'f') . |
456
|
9 |
|
($this->showDropDown ? 't' : 'f') . |
457
|
9 |
|
($this->showInputMessage ? 't' : 'f') . |
458
|
9 |
|
($this->showErrorMessage ? 't' : 'f') . |
459
|
9 |
|
$this->errorTitle . |
460
|
9 |
|
$this->error . |
461
|
9 |
|
$this->promptTitle . |
462
|
9 |
|
$this->prompt . |
463
|
9 |
|
$this->sqref . |
464
|
9 |
|
__CLASS__ |
465
|
9 |
|
); |
466
|
|
|
} |
467
|
|
|
|
468
|
|
|
/** |
469
|
|
|
* Implement PHP __clone to create a deep clone, not just a shallow copy. |
470
|
|
|
*/ |
471
|
3 |
|
public function __clone() |
472
|
|
|
{ |
473
|
3 |
|
$vars = get_object_vars($this); |
474
|
3 |
|
foreach ($vars as $key => $value) { |
475
|
3 |
|
if (is_object($value)) { |
476
|
|
|
$this->$key = clone $value; |
477
|
|
|
} else { |
478
|
3 |
|
$this->$key = $value; |
479
|
|
|
} |
480
|
|
|
} |
481
|
|
|
} |
482
|
|
|
|
483
|
|
|
/** @var ?string */ |
484
|
|
|
private $sqref; |
485
|
|
|
|
486
|
14 |
|
public function getSqref(): ?string |
487
|
|
|
{ |
488
|
14 |
|
return $this->sqref; |
489
|
|
|
} |
490
|
|
|
|
491
|
20 |
|
public function setSqref(?string $str): self |
492
|
|
|
{ |
493
|
20 |
|
$this->sqref = $str; |
494
|
|
|
|
495
|
20 |
|
return $this; |
496
|
|
|
} |
497
|
|
|
} |
498
|
|
|
|