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
|
|
|
* Create a new DataValidation. |
100
|
|
|
*/ |
101
|
41 |
|
public function __construct() |
102
|
|
|
{ |
103
|
41 |
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Get Formula 1. |
107
|
|
|
*/ |
108
|
32 |
|
public function getFormula1(): string |
109
|
|
|
{ |
110
|
32 |
|
return $this->formula1; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Set Formula 1. |
115
|
|
|
* |
116
|
|
|
* @return $this |
117
|
|
|
*/ |
118
|
39 |
|
public function setFormula1(string $formula): static |
119
|
|
|
{ |
120
|
39 |
|
$this->formula1 = $formula; |
121
|
|
|
|
122
|
39 |
|
return $this; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Get Formula 2. |
127
|
|
|
*/ |
128
|
24 |
|
public function getFormula2(): string |
129
|
|
|
{ |
130
|
24 |
|
return $this->formula2; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Set Formula 2. |
135
|
|
|
* |
136
|
|
|
* @return $this |
137
|
|
|
*/ |
138
|
26 |
|
public function setFormula2(string $formula): static |
139
|
|
|
{ |
140
|
26 |
|
$this->formula2 = $formula; |
141
|
|
|
|
142
|
26 |
|
return $this; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Get Type. |
147
|
|
|
*/ |
148
|
28 |
|
public function getType(): string |
149
|
|
|
{ |
150
|
28 |
|
return $this->type; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Set Type. |
155
|
|
|
* |
156
|
|
|
* @return $this |
157
|
|
|
*/ |
158
|
41 |
|
public function setType(string $type): static |
159
|
|
|
{ |
160
|
41 |
|
$this->type = $type; |
161
|
|
|
|
162
|
41 |
|
return $this; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* Get Error style. |
167
|
|
|
*/ |
168
|
17 |
|
public function getErrorStyle(): string |
169
|
|
|
{ |
170
|
17 |
|
return $this->errorStyle; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* Set Error style. |
175
|
|
|
* |
176
|
|
|
* @param string $errorStyle see self::STYLE_* |
177
|
|
|
* |
178
|
|
|
* @return $this |
179
|
|
|
*/ |
180
|
36 |
|
public function setErrorStyle(string $errorStyle): static |
181
|
|
|
{ |
182
|
36 |
|
$this->errorStyle = $errorStyle; |
183
|
|
|
|
184
|
36 |
|
return $this; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* Get Operator. |
189
|
|
|
*/ |
190
|
20 |
|
public function getOperator(): string |
191
|
|
|
{ |
192
|
20 |
|
return $this->operator; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* Set Operator. |
197
|
|
|
* |
198
|
|
|
* @return $this |
199
|
|
|
*/ |
200
|
25 |
|
public function setOperator(string $operator): static |
201
|
|
|
{ |
202
|
25 |
|
$this->operator = ($operator === '') ? self::DEFAULT_OPERATOR : $operator; |
203
|
|
|
|
204
|
25 |
|
return $this; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* Get Allow Blank. |
209
|
|
|
*/ |
210
|
21 |
|
public function getAllowBlank(): bool |
211
|
|
|
{ |
212
|
21 |
|
return $this->allowBlank; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* Set Allow Blank. |
217
|
|
|
* |
218
|
|
|
* @return $this |
219
|
|
|
*/ |
220
|
36 |
|
public function setAllowBlank(bool $allowBlank): static |
221
|
|
|
{ |
222
|
36 |
|
$this->allowBlank = $allowBlank; |
223
|
|
|
|
224
|
36 |
|
return $this; |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* Get Show DropDown. |
229
|
|
|
*/ |
230
|
17 |
|
public function getShowDropDown(): bool |
231
|
|
|
{ |
232
|
17 |
|
return $this->showDropDown; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* Set Show DropDown. |
237
|
|
|
* |
238
|
|
|
* @return $this |
239
|
|
|
*/ |
240
|
38 |
|
public function setShowDropDown(bool $showDropDown): static |
241
|
|
|
{ |
242
|
38 |
|
$this->showDropDown = $showDropDown; |
243
|
|
|
|
244
|
38 |
|
return $this; |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* Get Show InputMessage. |
249
|
|
|
*/ |
250
|
16 |
|
public function getShowInputMessage(): bool |
251
|
|
|
{ |
252
|
16 |
|
return $this->showInputMessage; |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
/** |
256
|
|
|
* Set Show InputMessage. |
257
|
|
|
* |
258
|
|
|
* @return $this |
259
|
|
|
*/ |
260
|
34 |
|
public function setShowInputMessage(bool $showInputMessage): static |
261
|
|
|
{ |
262
|
34 |
|
$this->showInputMessage = $showInputMessage; |
263
|
|
|
|
264
|
34 |
|
return $this; |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
/** |
268
|
|
|
* Get Show ErrorMessage. |
269
|
|
|
*/ |
270
|
17 |
|
public function getShowErrorMessage(): bool |
271
|
|
|
{ |
272
|
17 |
|
return $this->showErrorMessage; |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
/** |
276
|
|
|
* Set Show ErrorMessage. |
277
|
|
|
* |
278
|
|
|
* @return $this |
279
|
|
|
*/ |
280
|
37 |
|
public function setShowErrorMessage(bool $showErrorMessage): static |
281
|
|
|
{ |
282
|
37 |
|
$this->showErrorMessage = $showErrorMessage; |
283
|
|
|
|
284
|
37 |
|
return $this; |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* Get Error title. |
289
|
|
|
*/ |
290
|
16 |
|
public function getErrorTitle(): string |
291
|
|
|
{ |
292
|
16 |
|
return $this->errorTitle; |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
/** |
296
|
|
|
* Set Error title. |
297
|
|
|
* |
298
|
|
|
* @return $this |
299
|
|
|
*/ |
300
|
36 |
|
public function setErrorTitle(string $errorTitle): static |
301
|
|
|
{ |
302
|
36 |
|
$this->errorTitle = $errorTitle; |
303
|
|
|
|
304
|
36 |
|
return $this; |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
/** |
308
|
|
|
* Get Error. |
309
|
|
|
*/ |
310
|
16 |
|
public function getError(): string |
311
|
|
|
{ |
312
|
16 |
|
return $this->error; |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
/** |
316
|
|
|
* Set Error. |
317
|
|
|
* |
318
|
|
|
* @return $this |
319
|
|
|
*/ |
320
|
36 |
|
public function setError(string $error): static |
321
|
|
|
{ |
322
|
36 |
|
$this->error = $error; |
323
|
|
|
|
324
|
36 |
|
return $this; |
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
/** |
328
|
|
|
* Get Prompt title. |
329
|
|
|
*/ |
330
|
16 |
|
public function getPromptTitle(): string |
331
|
|
|
{ |
332
|
16 |
|
return $this->promptTitle; |
333
|
|
|
} |
334
|
|
|
|
335
|
|
|
/** |
336
|
|
|
* Set Prompt title. |
337
|
|
|
* |
338
|
|
|
* @return $this |
339
|
|
|
*/ |
340
|
32 |
|
public function setPromptTitle(string $promptTitle): static |
341
|
|
|
{ |
342
|
32 |
|
$this->promptTitle = $promptTitle; |
343
|
|
|
|
344
|
32 |
|
return $this; |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
/** |
348
|
|
|
* Get Prompt. |
349
|
|
|
*/ |
350
|
16 |
|
public function getPrompt(): string |
351
|
|
|
{ |
352
|
16 |
|
return $this->prompt; |
353
|
|
|
} |
354
|
|
|
|
355
|
|
|
/** |
356
|
|
|
* Set Prompt. |
357
|
|
|
* |
358
|
|
|
* @return $this |
359
|
|
|
*/ |
360
|
32 |
|
public function setPrompt(string $prompt): static |
361
|
|
|
{ |
362
|
32 |
|
$this->prompt = $prompt; |
363
|
|
|
|
364
|
32 |
|
return $this; |
365
|
|
|
} |
366
|
|
|
|
367
|
|
|
/** |
368
|
|
|
* Get hash code. |
369
|
|
|
* |
370
|
|
|
* @return string Hash code |
371
|
|
|
*/ |
372
|
1 |
|
public function getHashCode(): string |
373
|
|
|
{ |
374
|
1 |
|
return md5( |
375
|
1 |
|
$this->formula1 |
376
|
1 |
|
. $this->formula2 |
377
|
1 |
|
. $this->type |
378
|
1 |
|
. $this->errorStyle |
379
|
1 |
|
. $this->operator |
380
|
1 |
|
. ($this->allowBlank ? 't' : 'f') |
381
|
1 |
|
. ($this->showDropDown ? 't' : 'f') |
382
|
1 |
|
. ($this->showInputMessage ? 't' : 'f') |
383
|
1 |
|
. ($this->showErrorMessage ? 't' : 'f') |
384
|
1 |
|
. $this->errorTitle |
385
|
1 |
|
. $this->error |
386
|
1 |
|
. $this->promptTitle |
387
|
1 |
|
. $this->prompt |
388
|
1 |
|
. $this->sqref |
389
|
1 |
|
. __CLASS__ |
390
|
1 |
|
); |
391
|
|
|
} |
392
|
|
|
|
393
|
|
|
/** |
394
|
|
|
* Implement PHP __clone to create a deep clone, not just a shallow copy. |
395
|
|
|
*/ |
396
|
|
|
public function __clone() |
397
|
|
|
{ |
398
|
|
|
$vars = get_object_vars($this); |
399
|
|
|
foreach ($vars as $key => $value) { |
400
|
|
|
if (is_object($value)) { |
401
|
|
|
$this->$key = clone $value; |
402
|
|
|
} else { |
403
|
|
|
$this->$key = $value; |
404
|
|
|
} |
405
|
|
|
} |
406
|
|
|
} |
407
|
|
|
|
408
|
|
|
private ?string $sqref = null; |
409
|
|
|
|
410
|
22 |
|
public function getSqref(): ?string |
411
|
|
|
{ |
412
|
22 |
|
return $this->sqref; |
413
|
|
|
} |
414
|
|
|
|
415
|
40 |
|
public function setSqref(?string $str): self |
416
|
|
|
{ |
417
|
40 |
|
$this->sqref = $str; |
418
|
|
|
|
419
|
40 |
|
return $this; |
420
|
|
|
} |
421
|
|
|
} |
422
|
|
|
|