1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheet\Style; |
4
|
|
|
|
5
|
|
|
use PhpOffice\PhpSpreadsheet\IComparable; |
6
|
|
|
|
7
|
|
|
class Conditional implements IComparable |
8
|
|
|
{ |
9
|
|
|
// Condition types |
10
|
|
|
const CONDITION_NONE = 'none'; |
11
|
|
|
const CONDITION_CELLIS = 'cellIs'; |
12
|
|
|
const CONDITION_CONTAINSTEXT = 'containsText'; |
13
|
|
|
const CONDITION_EXPRESSION = 'expression'; |
14
|
|
|
const CONDITION_CONTAINSBLANKS = 'containsBlanks'; |
15
|
|
|
|
16
|
|
|
// Operator types |
17
|
|
|
const OPERATOR_NONE = ''; |
18
|
|
|
const OPERATOR_BEGINSWITH = 'beginsWith'; |
19
|
|
|
const OPERATOR_ENDSWITH = 'endsWith'; |
20
|
|
|
const OPERATOR_EQUAL = 'equal'; |
21
|
|
|
const OPERATOR_GREATERTHAN = 'greaterThan'; |
22
|
|
|
const OPERATOR_GREATERTHANOREQUAL = 'greaterThanOrEqual'; |
23
|
|
|
const OPERATOR_LESSTHAN = 'lessThan'; |
24
|
|
|
const OPERATOR_LESSTHANOREQUAL = 'lessThanOrEqual'; |
25
|
|
|
const OPERATOR_NOTEQUAL = 'notEqual'; |
26
|
|
|
const OPERATOR_CONTAINSTEXT = 'containsText'; |
27
|
|
|
const OPERATOR_NOTCONTAINS = 'notContains'; |
28
|
|
|
const OPERATOR_BETWEEN = 'between'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Condition type. |
32
|
|
|
* |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
private $conditionType = self::CONDITION_NONE; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Operator type. |
39
|
|
|
* |
40
|
|
|
* @var string |
41
|
|
|
*/ |
42
|
|
|
private $operatorType = self::OPERATOR_NONE; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Text. |
46
|
|
|
* |
47
|
|
|
* @var string |
48
|
|
|
*/ |
49
|
|
|
private $text; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Stop on this condition, if it matches. |
53
|
|
|
* |
54
|
|
|
* @var bool |
55
|
|
|
*/ |
56
|
|
|
private $stopIfTrue = false; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Condition. |
60
|
|
|
* |
61
|
|
|
* @var string[] |
62
|
|
|
*/ |
63
|
|
|
private $condition = []; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Style. |
67
|
|
|
* |
68
|
|
|
* @var Style |
69
|
|
|
*/ |
70
|
|
|
private $style; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Create a new Conditional. |
74
|
|
|
*/ |
75
|
3 |
|
public function __construct() |
76
|
|
|
{ |
77
|
|
|
// Initialise values |
78
|
3 |
|
$this->style = new Style(false, true); |
79
|
3 |
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Get Condition type. |
83
|
|
|
* |
84
|
|
|
* @return string |
85
|
|
|
*/ |
86
|
3 |
|
public function getConditionType() |
87
|
|
|
{ |
88
|
3 |
|
return $this->conditionType; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Set Condition type. |
93
|
|
|
* |
94
|
|
|
* @param string $pValue Condition type, see self::CONDITION_* |
95
|
|
|
* |
96
|
|
|
* @return Conditional |
97
|
|
|
*/ |
98
|
3 |
|
public function setConditionType($pValue) |
99
|
|
|
{ |
100
|
3 |
|
$this->conditionType = $pValue; |
101
|
|
|
|
102
|
3 |
|
return $this; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Get Operator type. |
107
|
|
|
* |
108
|
|
|
* @return string |
109
|
|
|
*/ |
110
|
3 |
|
public function getOperatorType() |
111
|
|
|
{ |
112
|
3 |
|
return $this->operatorType; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Set Operator type. |
117
|
|
|
* |
118
|
|
|
* @param string $pValue Conditional operator type, see self::OPERATOR_* |
119
|
|
|
* |
120
|
|
|
* @return Conditional |
121
|
|
|
*/ |
122
|
3 |
|
public function setOperatorType($pValue) |
123
|
|
|
{ |
124
|
3 |
|
$this->operatorType = $pValue; |
125
|
|
|
|
126
|
3 |
|
return $this; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Get text. |
131
|
|
|
* |
132
|
|
|
* @return string |
133
|
|
|
*/ |
134
|
|
|
public function getText() |
135
|
|
|
{ |
136
|
|
|
return $this->text; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Set text. |
141
|
|
|
* |
142
|
|
|
* @param string $value |
143
|
|
|
* |
144
|
|
|
* @return Conditional |
145
|
|
|
*/ |
146
|
|
|
public function setText($value) |
147
|
|
|
{ |
148
|
|
|
$this->text = $value; |
149
|
|
|
|
150
|
|
|
return $this; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Get StopIfTrue. |
155
|
|
|
* |
156
|
|
|
* @return bool |
157
|
|
|
*/ |
158
|
3 |
|
public function getStopIfTrue() |
159
|
|
|
{ |
160
|
3 |
|
return $this->stopIfTrue; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* Set StopIfTrue. |
165
|
|
|
* |
166
|
|
|
* @param bool $value |
167
|
|
|
* |
168
|
|
|
* @return Conditional |
169
|
|
|
*/ |
170
|
1 |
|
public function setStopIfTrue($value) |
171
|
|
|
{ |
172
|
1 |
|
$this->stopIfTrue = $value; |
173
|
|
|
|
174
|
1 |
|
return $this; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* Get Conditions. |
179
|
|
|
* |
180
|
|
|
* @return string[] |
181
|
|
|
*/ |
182
|
3 |
|
public function getConditions() |
183
|
|
|
{ |
184
|
3 |
|
return $this->condition; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* Set Conditions. |
189
|
|
|
* |
190
|
|
|
* @param string[] $pValue Condition |
191
|
|
|
* |
192
|
|
|
* @return Conditional |
193
|
|
|
*/ |
194
|
|
|
public function setConditions($pValue) |
195
|
|
|
{ |
196
|
|
|
if (!is_array($pValue)) { |
197
|
|
|
$pValue = [$pValue]; |
198
|
|
|
} |
199
|
|
|
$this->condition = $pValue; |
200
|
|
|
|
201
|
|
|
return $this; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* Add Condition. |
206
|
|
|
* |
207
|
|
|
* @param string $pValue Condition |
208
|
|
|
* |
209
|
|
|
* @return Conditional |
210
|
|
|
*/ |
211
|
3 |
|
public function addCondition($pValue) |
212
|
|
|
{ |
213
|
3 |
|
$this->condition[] = $pValue; |
214
|
|
|
|
215
|
3 |
|
return $this; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* Get Style. |
220
|
|
|
* |
221
|
|
|
* @return Style |
222
|
|
|
*/ |
223
|
3 |
|
public function getStyle() |
224
|
|
|
{ |
225
|
3 |
|
return $this->style; |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* Set Style. |
230
|
|
|
* |
231
|
|
|
* @param Style $pValue |
232
|
|
|
* |
233
|
|
|
* @return Conditional |
234
|
|
|
*/ |
235
|
1 |
|
public function setStyle(Style $pValue = null) |
236
|
|
|
{ |
237
|
1 |
|
$this->style = $pValue; |
238
|
|
|
|
239
|
1 |
|
return $this; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* Get hash code. |
244
|
|
|
* |
245
|
|
|
* @return string Hash code |
246
|
|
|
*/ |
247
|
3 |
|
public function getHashCode() |
248
|
|
|
{ |
249
|
3 |
|
return md5( |
250
|
3 |
|
$this->conditionType . |
251
|
3 |
|
$this->operatorType . |
252
|
3 |
|
implode(';', $this->condition) . |
253
|
3 |
|
$this->style->getHashCode() . |
254
|
3 |
|
__CLASS__ |
255
|
|
|
); |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* Implement PHP __clone to create a deep clone, not just a shallow copy. |
260
|
|
|
*/ |
261
|
|
|
public function __clone() |
262
|
|
|
{ |
263
|
|
|
$vars = get_object_vars($this); |
264
|
|
|
foreach ($vars as $key => $value) { |
265
|
|
|
if (is_object($value)) { |
266
|
|
|
$this->$key = clone $value; |
267
|
|
|
} else { |
268
|
|
|
$this->$key = $value; |
269
|
|
|
} |
270
|
|
|
} |
271
|
|
|
} |
272
|
|
|
} |
273
|
|
|
|