1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheet\Cell; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Copyright (c) 2006 - 2016 PhpSpreadsheet. |
7
|
|
|
* |
8
|
|
|
* This library is free software; you can redistribute it and/or |
9
|
|
|
* modify it under the terms of the GNU Lesser General Public |
10
|
|
|
* License as published by the Free Software Foundation; either |
11
|
|
|
* version 2.1 of the License, or (at your option) any later version. |
12
|
|
|
* |
13
|
|
|
* This library is distributed in the hope that it will be useful, |
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16
|
|
|
* Lesser General Public License for more details. |
17
|
|
|
* |
18
|
|
|
* You should have received a copy of the GNU Lesser General Public |
19
|
|
|
* License along with this library; if not, write to the Free Software |
20
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
21
|
|
|
* |
22
|
|
|
* @category PhpSpreadsheet |
23
|
|
|
* |
24
|
|
|
* @copyright Copyright (c) 2006 - 2016 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet) |
25
|
|
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
26
|
|
|
*/ |
27
|
|
|
class DataValidation |
28
|
|
|
{ |
29
|
|
|
/* Data validation types */ |
30
|
|
|
const TYPE_NONE = 'none'; |
31
|
|
|
const TYPE_CUSTOM = 'custom'; |
32
|
|
|
const TYPE_DATE = 'date'; |
33
|
|
|
const TYPE_DECIMAL = 'decimal'; |
34
|
|
|
const TYPE_LIST = 'list'; |
35
|
|
|
const TYPE_TEXTLENGTH = 'textLength'; |
36
|
|
|
const TYPE_TIME = 'time'; |
37
|
|
|
const TYPE_WHOLE = 'whole'; |
38
|
|
|
|
39
|
|
|
/* Data validation error styles */ |
40
|
|
|
const STYLE_STOP = 'stop'; |
41
|
|
|
const STYLE_WARNING = 'warning'; |
42
|
|
|
const STYLE_INFORMATION = 'information'; |
43
|
|
|
|
44
|
|
|
/* Data validation operators */ |
45
|
|
|
const OPERATOR_BETWEEN = 'between'; |
46
|
|
|
const OPERATOR_EQUAL = 'equal'; |
47
|
|
|
const OPERATOR_GREATERTHAN = 'greaterThan'; |
48
|
|
|
const OPERATOR_GREATERTHANOREQUAL = 'greaterThanOrEqual'; |
49
|
|
|
const OPERATOR_LESSTHAN = 'lessThan'; |
50
|
|
|
const OPERATOR_LESSTHANOREQUAL = 'lessThanOrEqual'; |
51
|
|
|
const OPERATOR_NOTBETWEEN = 'notBetween'; |
52
|
|
|
const OPERATOR_NOTEQUAL = 'notEqual'; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Formula 1. |
56
|
|
|
* |
57
|
|
|
* @var string |
58
|
|
|
*/ |
59
|
|
|
private $formula1 = ''; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Formula 2. |
63
|
|
|
* |
64
|
|
|
* @var string |
65
|
|
|
*/ |
66
|
|
|
private $formula2 = ''; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Type. |
70
|
|
|
* |
71
|
|
|
* @var string |
72
|
|
|
*/ |
73
|
|
|
private $type = self::TYPE_NONE; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Error style. |
77
|
|
|
* |
78
|
|
|
* @var string |
79
|
|
|
*/ |
80
|
|
|
private $errorStyle = self::STYLE_STOP; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Operator. |
84
|
|
|
* |
85
|
|
|
* @var string |
86
|
|
|
*/ |
87
|
|
|
private $operator = self::OPERATOR_BETWEEN; |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Allow Blank. |
91
|
|
|
* |
92
|
|
|
* @var bool |
93
|
|
|
*/ |
94
|
|
|
private $allowBlank = false; |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Show DropDown. |
98
|
|
|
* |
99
|
|
|
* @var bool |
100
|
|
|
*/ |
101
|
|
|
private $showDropDown = false; |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Show InputMessage. |
105
|
|
|
* |
106
|
|
|
* @var bool |
107
|
|
|
*/ |
108
|
|
|
private $showInputMessage = false; |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Show ErrorMessage. |
112
|
|
|
* |
113
|
|
|
* @var bool |
114
|
|
|
*/ |
115
|
|
|
private $showErrorMessage = false; |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Error title. |
119
|
|
|
* |
120
|
|
|
* @var string |
121
|
|
|
*/ |
122
|
|
|
private $errorTitle = ''; |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Error. |
126
|
|
|
* |
127
|
|
|
* @var string |
128
|
|
|
*/ |
129
|
|
|
private $error = ''; |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Prompt title. |
133
|
|
|
* |
134
|
|
|
* @var string |
135
|
|
|
*/ |
136
|
|
|
private $promptTitle = ''; |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Prompt. |
140
|
|
|
* |
141
|
|
|
* @var string |
142
|
|
|
*/ |
143
|
|
|
private $prompt = ''; |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Create a new DataValidation. |
147
|
|
|
*/ |
148
|
2 |
|
public function __construct() |
149
|
|
|
{ |
150
|
2 |
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Get Formula 1. |
154
|
|
|
* |
155
|
|
|
* @return string |
156
|
|
|
*/ |
157
|
2 |
|
public function getFormula1() |
158
|
|
|
{ |
159
|
2 |
|
return $this->formula1; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Set Formula 1. |
164
|
|
|
* |
165
|
|
|
* @param string $value |
166
|
|
|
* |
167
|
|
|
* @return DataValidation |
168
|
|
|
*/ |
169
|
2 |
|
public function setFormula1($value) |
170
|
|
|
{ |
171
|
2 |
|
$this->formula1 = $value; |
172
|
|
|
|
173
|
2 |
|
return $this; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* Get Formula 2. |
178
|
|
|
* |
179
|
|
|
* @return string |
180
|
|
|
*/ |
181
|
2 |
|
public function getFormula2() |
182
|
|
|
{ |
183
|
2 |
|
return $this->formula2; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Set Formula 2. |
188
|
|
|
* |
189
|
|
|
* @param string $value |
190
|
|
|
* |
191
|
|
|
* @return DataValidation |
192
|
|
|
*/ |
193
|
1 |
|
public function setFormula2($value) |
194
|
|
|
{ |
195
|
1 |
|
$this->formula2 = $value; |
196
|
|
|
|
197
|
1 |
|
return $this; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* Get Type. |
202
|
|
|
* |
203
|
|
|
* @return string |
204
|
|
|
*/ |
205
|
2 |
|
public function getType() |
206
|
|
|
{ |
207
|
2 |
|
return $this->type; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* Set Type. |
212
|
|
|
* |
213
|
|
|
* @param string $value |
214
|
|
|
* |
215
|
|
|
* @return DataValidation |
216
|
|
|
*/ |
217
|
2 |
|
public function setType($value) |
218
|
|
|
{ |
219
|
2 |
|
$this->type = $value; |
220
|
|
|
|
221
|
2 |
|
return $this; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* Get Error style. |
226
|
|
|
* |
227
|
|
|
* @return string |
228
|
|
|
*/ |
229
|
2 |
|
public function getErrorStyle() |
230
|
|
|
{ |
231
|
2 |
|
return $this->errorStyle; |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
/** |
235
|
|
|
* Set Error style. |
236
|
|
|
* |
237
|
|
|
* @param string $value see self::STYLE_* |
238
|
|
|
* |
239
|
|
|
* @return DataValidation |
240
|
|
|
*/ |
241
|
2 |
|
public function setErrorStyle($value) |
242
|
|
|
{ |
243
|
2 |
|
$this->errorStyle = $value; |
244
|
|
|
|
245
|
2 |
|
return $this; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* Get Operator. |
250
|
|
|
* |
251
|
|
|
* @return string |
252
|
|
|
*/ |
253
|
2 |
|
public function getOperator() |
254
|
|
|
{ |
255
|
2 |
|
return $this->operator; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* Set Operator. |
260
|
|
|
* |
261
|
|
|
* @param string $value |
262
|
|
|
* |
263
|
|
|
* @return DataValidation |
264
|
|
|
*/ |
265
|
|
|
public function setOperator($value) |
266
|
|
|
{ |
267
|
|
|
$this->operator = $value; |
268
|
|
|
|
269
|
|
|
return $this; |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
/** |
273
|
|
|
* Get Allow Blank. |
274
|
|
|
* |
275
|
|
|
* @return bool |
276
|
|
|
*/ |
277
|
2 |
|
public function getAllowBlank() |
278
|
|
|
{ |
279
|
2 |
|
return $this->allowBlank; |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
/** |
283
|
|
|
* Set Allow Blank. |
284
|
|
|
* |
285
|
|
|
* @param bool $value |
286
|
|
|
* |
287
|
|
|
* @return DataValidation |
288
|
|
|
*/ |
289
|
2 |
|
public function setAllowBlank($value) |
290
|
|
|
{ |
291
|
2 |
|
$this->allowBlank = $value; |
292
|
|
|
|
293
|
2 |
|
return $this; |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
/** |
297
|
|
|
* Get Show DropDown. |
298
|
|
|
* |
299
|
|
|
* @return bool |
300
|
|
|
*/ |
301
|
2 |
|
public function getShowDropDown() |
302
|
|
|
{ |
303
|
2 |
|
return $this->showDropDown; |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* Set Show DropDown. |
308
|
|
|
* |
309
|
|
|
* @param bool $value |
310
|
|
|
* |
311
|
|
|
* @return DataValidation |
312
|
|
|
*/ |
313
|
2 |
|
public function setShowDropDown($value) |
314
|
|
|
{ |
315
|
2 |
|
$this->showDropDown = $value; |
316
|
|
|
|
317
|
2 |
|
return $this; |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
/** |
321
|
|
|
* Get Show InputMessage. |
322
|
|
|
* |
323
|
|
|
* @return bool |
324
|
|
|
*/ |
325
|
2 |
|
public function getShowInputMessage() |
326
|
|
|
{ |
327
|
2 |
|
return $this->showInputMessage; |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
/** |
331
|
|
|
* Set Show InputMessage. |
332
|
|
|
* |
333
|
|
|
* @param bool $value |
334
|
|
|
* |
335
|
|
|
* @return DataValidation |
336
|
|
|
*/ |
337
|
2 |
|
public function setShowInputMessage($value) |
338
|
|
|
{ |
339
|
2 |
|
$this->showInputMessage = $value; |
340
|
|
|
|
341
|
2 |
|
return $this; |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
/** |
345
|
|
|
* Get Show ErrorMessage. |
346
|
|
|
* |
347
|
|
|
* @return bool |
348
|
|
|
*/ |
349
|
2 |
|
public function getShowErrorMessage() |
350
|
|
|
{ |
351
|
2 |
|
return $this->showErrorMessage; |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
/** |
355
|
|
|
* Set Show ErrorMessage. |
356
|
|
|
* |
357
|
|
|
* @param bool $value |
358
|
|
|
* |
359
|
|
|
* @return DataValidation |
360
|
|
|
*/ |
361
|
2 |
|
public function setShowErrorMessage($value) |
362
|
|
|
{ |
363
|
2 |
|
$this->showErrorMessage = $value; |
364
|
|
|
|
365
|
2 |
|
return $this; |
366
|
|
|
} |
367
|
|
|
|
368
|
|
|
/** |
369
|
|
|
* Get Error title. |
370
|
|
|
* |
371
|
|
|
* @return string |
372
|
|
|
*/ |
373
|
2 |
|
public function getErrorTitle() |
374
|
|
|
{ |
375
|
2 |
|
return $this->errorTitle; |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
/** |
379
|
|
|
* Set Error title. |
380
|
|
|
* |
381
|
|
|
* @param string $value |
382
|
|
|
* |
383
|
|
|
* @return DataValidation |
384
|
|
|
*/ |
385
|
2 |
|
public function setErrorTitle($value) |
386
|
|
|
{ |
387
|
2 |
|
$this->errorTitle = $value; |
388
|
|
|
|
389
|
2 |
|
return $this; |
390
|
|
|
} |
391
|
|
|
|
392
|
|
|
/** |
393
|
|
|
* Get Error. |
394
|
|
|
* |
395
|
|
|
* @return string |
396
|
|
|
*/ |
397
|
2 |
|
public function getError() |
398
|
|
|
{ |
399
|
2 |
|
return $this->error; |
400
|
|
|
} |
401
|
|
|
|
402
|
|
|
/** |
403
|
|
|
* Set Error. |
404
|
|
|
* |
405
|
|
|
* @param string $value |
406
|
|
|
* |
407
|
|
|
* @return DataValidation |
408
|
|
|
*/ |
409
|
2 |
|
public function setError($value) |
410
|
|
|
{ |
411
|
2 |
|
$this->error = $value; |
412
|
|
|
|
413
|
2 |
|
return $this; |
414
|
|
|
} |
415
|
|
|
|
416
|
|
|
/** |
417
|
|
|
* Get Prompt title. |
418
|
|
|
* |
419
|
|
|
* @return string |
420
|
|
|
*/ |
421
|
2 |
|
public function getPromptTitle() |
422
|
|
|
{ |
423
|
2 |
|
return $this->promptTitle; |
424
|
|
|
} |
425
|
|
|
|
426
|
|
|
/** |
427
|
|
|
* Set Prompt title. |
428
|
|
|
* |
429
|
|
|
* @param string $value |
430
|
|
|
* |
431
|
|
|
* @return DataValidation |
432
|
|
|
*/ |
433
|
2 |
|
public function setPromptTitle($value) |
434
|
|
|
{ |
435
|
2 |
|
$this->promptTitle = $value; |
436
|
|
|
|
437
|
2 |
|
return $this; |
438
|
|
|
} |
439
|
|
|
|
440
|
|
|
/** |
441
|
|
|
* Get Prompt. |
442
|
|
|
* |
443
|
|
|
* @return string |
444
|
|
|
*/ |
445
|
2 |
|
public function getPrompt() |
446
|
|
|
{ |
447
|
2 |
|
return $this->prompt; |
448
|
|
|
} |
449
|
|
|
|
450
|
|
|
/** |
451
|
|
|
* Set Prompt. |
452
|
|
|
* |
453
|
|
|
* @param string $value |
454
|
|
|
* |
455
|
|
|
* @return DataValidation |
456
|
|
|
*/ |
457
|
2 |
|
public function setPrompt($value) |
458
|
|
|
{ |
459
|
2 |
|
$this->prompt = $value; |
460
|
|
|
|
461
|
2 |
|
return $this; |
462
|
|
|
} |
463
|
|
|
|
464
|
|
|
/** |
465
|
|
|
* Get hash code. |
466
|
|
|
* |
467
|
|
|
* @return string Hash code |
468
|
|
|
*/ |
469
|
2 |
|
public function getHashCode() |
470
|
|
|
{ |
471
|
2 |
|
return md5( |
472
|
2 |
|
$this->formula1 . |
473
|
2 |
|
$this->formula2 . |
474
|
2 |
|
$this->type = self::TYPE_NONE . |
475
|
2 |
|
$this->errorStyle = self::STYLE_STOP . |
476
|
2 |
|
$this->operator . |
477
|
2 |
|
($this->allowBlank ? 't' : 'f') . |
478
|
2 |
|
($this->showDropDown ? 't' : 'f') . |
479
|
2 |
|
($this->showInputMessage ? 't' : 'f') . |
480
|
2 |
|
($this->showErrorMessage ? 't' : 'f') . |
481
|
2 |
|
$this->errorTitle . |
482
|
2 |
|
$this->error . |
483
|
2 |
|
$this->promptTitle . |
484
|
2 |
|
$this->prompt . |
485
|
2 |
|
__CLASS__ |
486
|
|
|
); |
487
|
|
|
} |
488
|
|
|
|
489
|
|
|
/** |
490
|
|
|
* Implement PHP __clone to create a deep clone, not just a shallow copy. |
491
|
|
|
*/ |
492
|
|
View Code Duplication |
public function __clone() |
|
|
|
|
493
|
|
|
{ |
494
|
|
|
$vars = get_object_vars($this); |
495
|
|
|
foreach ($vars as $key => $value) { |
496
|
|
|
if (is_object($value)) { |
497
|
|
|
$this->$key = clone $value; |
498
|
|
|
} else { |
499
|
|
|
$this->$key = $value; |
500
|
|
|
} |
501
|
|
|
} |
502
|
|
|
} |
503
|
|
|
} |
504
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.