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