ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Rule.php
Go to the documentation of this file.
1<?php
2
4
5use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;
7
8class Rule
9{
11 const AUTOFILTER_RULETYPE_DATEGROUP = 'dateGroupItem';
12 const AUTOFILTER_RULETYPE_CUSTOMFILTER = 'customFilter';
13 const AUTOFILTER_RULETYPE_DYNAMICFILTER = 'dynamicFilter';
14 const AUTOFILTER_RULETYPE_TOPTENFILTER = 'top10Filter';
15
16 private static $ruleTypes = [
17 // Currently we're not handling
18 // colorFilter
19 // extLst
20 // iconFilter
26 ];
27
34
35 private static $dateTimeGroups = [
42 ];
43
90
91 private static $dynamicTypes = [
126 ];
127
128 /*
129 * The only valid filter rule operators for filter and customFilter types are:
130 * <xsd:enumeration value="equal"/>
131 * <xsd:enumeration value="lessThan"/>
132 * <xsd:enumeration value="lessThanOrEqual"/>
133 * <xsd:enumeration value="notEqual"/>
134 * <xsd:enumeration value="greaterThanOrEqual"/>
135 * <xsd:enumeration value="greaterThan"/>
136 */
140 const AUTOFILTER_COLUMN_RULE_GREATERTHANOREQUAL = 'greaterThanOrEqual';
142 const AUTOFILTER_COLUMN_RULE_LESSTHANOREQUAL = 'lessThanOrEqual';
143
144 private static $operators = [
151 ];
152
155
156 private static $topTenValue = [
159 ];
160
163
164 private static $topTenType = [
167 ];
168
169 // Rule Operators (Numeric, Boolean etc)
170// const AUTOFILTER_COLUMN_RULE_BETWEEN = 'between'; // greaterThanOrEqual 1 && lessThanOrEqual 2
171 // Rule Operators (Numeric Special) which are translated to standard numeric operators with calculated values
172// const AUTOFILTER_COLUMN_RULE_TOPTEN = 'topTen'; // greaterThan calculated value
173// const AUTOFILTER_COLUMN_RULE_TOPTENPERCENT = 'topTenPercent'; // greaterThan calculated value
174// const AUTOFILTER_COLUMN_RULE_ABOVEAVERAGE = 'aboveAverage'; // Value is calculated as the average
175// const AUTOFILTER_COLUMN_RULE_BELOWAVERAGE = 'belowAverage'; // Value is calculated as the average
176 // Rule Operators (String) which are set as wild-carded values
177// const AUTOFILTER_COLUMN_RULE_BEGINSWITH = 'beginsWith'; // A*
178// const AUTOFILTER_COLUMN_RULE_ENDSWITH = 'endsWith'; // *Z
179// const AUTOFILTER_COLUMN_RULE_CONTAINS = 'contains'; // *B*
180// const AUTOFILTER_COLUMN_RULE_DOESNTCONTAIN = 'notEqual'; // notEqual *B*
181 // Rule Operators (Date Special) which are translated to standard numeric operators with calculated values
182// const AUTOFILTER_COLUMN_RULE_BEFORE = 'lessThan';
183// const AUTOFILTER_COLUMN_RULE_AFTER = 'greaterThan';
184// const AUTOFILTER_COLUMN_RULE_YESTERDAY = 'yesterday';
185// const AUTOFILTER_COLUMN_RULE_TODAY = 'today';
186// const AUTOFILTER_COLUMN_RULE_TOMORROW = 'tomorrow';
187// const AUTOFILTER_COLUMN_RULE_LASTWEEK = 'lastWeek';
188// const AUTOFILTER_COLUMN_RULE_THISWEEK = 'thisWeek';
189// const AUTOFILTER_COLUMN_RULE_NEXTWEEK = 'nextWeek';
190// const AUTOFILTER_COLUMN_RULE_LASTMONTH = 'lastMonth';
191// const AUTOFILTER_COLUMN_RULE_THISMONTH = 'thisMonth';
192// const AUTOFILTER_COLUMN_RULE_NEXTMONTH = 'nextMonth';
193// const AUTOFILTER_COLUMN_RULE_LASTQUARTER = 'lastQuarter';
194// const AUTOFILTER_COLUMN_RULE_THISQUARTER = 'thisQuarter';
195// const AUTOFILTER_COLUMN_RULE_NEXTQUARTER = 'nextQuarter';
196// const AUTOFILTER_COLUMN_RULE_LASTYEAR = 'lastYear';
197// const AUTOFILTER_COLUMN_RULE_THISYEAR = 'thisYear';
198// const AUTOFILTER_COLUMN_RULE_NEXTYEAR = 'nextYear';
199// const AUTOFILTER_COLUMN_RULE_YEARTODATE = 'yearToDate'; // <dynamicFilter val="40909" type="yearToDate" maxVal="41113"/>
200// const AUTOFILTER_COLUMN_RULE_ALLDATESINMONTH = 'allDatesInMonth'; // <dynamicFilter type="M2"/> for Month/February
201// const AUTOFILTER_COLUMN_RULE_ALLDATESINQUARTER = 'allDatesInQuarter'; // <dynamicFilter type="Q2"/> for Quarter 2
202
208 private $parent;
209
216
222 private $value = '';
223
230
236 private $grouping = '';
237
243 public function __construct(?Column $pParent = null)
244 {
245 $this->parent = $pParent;
246 }
247
253 public function getRuleType()
254 {
255 return $this->ruleType;
256 }
257
265 public function setRuleType($pRuleType)
266 {
267 if (!in_array($pRuleType, self::$ruleTypes)) {
268 throw new PhpSpreadsheetException('Invalid rule type for column AutoFilter Rule.');
269 }
270
271 $this->ruleType = $pRuleType;
272
273 return $this;
274 }
275
281 public function getValue()
282 {
283 return $this->value;
284 }
285
293 public function setValue($pValue)
294 {
295 if (is_array($pValue)) {
296 $grouping = -1;
297 foreach ($pValue as $key => $value) {
298 // Validate array entries
299 if (!in_array($key, self::$dateTimeGroups)) {
300 // Remove any invalid entries from the value array
301 unset($pValue[$key]);
302 } else {
303 // Work out what the dateTime grouping will be
304 $grouping = max($grouping, array_search($key, self::$dateTimeGroups));
305 }
306 }
307 if (count($pValue) == 0) {
308 throw new PhpSpreadsheetException('Invalid rule value for column AutoFilter Rule.');
309 }
310 // Set the dateTime grouping that we've anticipated
311 $this->setGrouping(self::$dateTimeGroups[$grouping]);
312 }
313 $this->value = $pValue;
314
315 return $this;
316 }
317
323 public function getOperator()
324 {
325 return $this->operator;
326 }
327
335 public function setOperator($pOperator)
336 {
337 if (empty($pOperator)) {
339 }
340 if (
341 (!in_array($pOperator, self::$operators)) &&
342 (!in_array($pOperator, self::$topTenValue))
343 ) {
344 throw new PhpSpreadsheetException('Invalid operator for column AutoFilter Rule.');
345 }
346 $this->operator = $pOperator;
347
348 return $this;
349 }
350
356 public function getGrouping()
357 {
358 return $this->grouping;
359 }
360
368 public function setGrouping($pGrouping)
369 {
370 if (
371 ($pGrouping !== null) &&
372 (!in_array($pGrouping, self::$dateTimeGroups)) &&
373 (!in_array($pGrouping, self::$dynamicTypes)) &&
374 (!in_array($pGrouping, self::$topTenType))
375 ) {
376 throw new PhpSpreadsheetException('Invalid rule type for column AutoFilter Rule.');
377 }
378 $this->grouping = $pGrouping;
379
380 return $this;
381 }
382
392 public function setRule($pOperator, $pValue, $pGrouping = null)
393 {
394 $this->setOperator($pOperator);
395 $this->setValue($pValue);
396 // Only set grouping if it's been passed in as a user-supplied argument,
397 // otherwise we're calculating it when we setValue() and don't want to overwrite that
398 // If the user supplies an argumnet for grouping, then on their own head be it
399 if ($pGrouping !== null) {
400 $this->setGrouping($pGrouping);
401 }
402
403 return $this;
404 }
405
411 public function getParent()
412 {
413 return $this->parent;
414 }
415
423 public function setParent(?Column $pParent = null)
424 {
425 $this->parent = $pParent;
426
427 return $this;
428 }
429
433 public function __clone()
434 {
435 $vars = get_object_vars($this);
436 foreach ($vars as $key => $value) {
437 if (is_object($value)) {
438 if ($key == 'parent') {
439 // Detach from autofilter column parent
440 $this->$key = null;
441 } else {
442 $this->$key = clone $value;
443 }
444 } else {
445 $this->$key = $value;
446 }
447 }
448 }
449}
An exception for terminatinating execution or to throw for unit testing.
__clone()
Implement PHP __clone to create a deep clone, not just a shallow copy.
Definition: Rule.php:433
setOperator($pOperator)
Set AutoFilter Rule Operator.
Definition: Rule.php:335
setRule($pOperator, $pValue, $pGrouping=null)
Set AutoFilter Rule.
Definition: Rule.php:392
getOperator()
Get AutoFilter Rule Operator.
Definition: Rule.php:323
getParent()
Get this Rule's AutoFilter Column Parent.
Definition: Rule.php:411
setRuleType($pRuleType)
Set AutoFilter Rule Type.
Definition: Rule.php:265
setParent(?Column $pParent=null)
Set this Rule's AutoFilter Column Parent.
Definition: Rule.php:423
getGrouping()
Get AutoFilter Rule Grouping.
Definition: Rule.php:356
__construct(?Column $pParent=null)
Create a new Rule.
Definition: Rule.php:243
setValue($pValue)
Set AutoFilter Rule Value.
Definition: Rule.php:293
setGrouping($pGrouping)
Set AutoFilter Rule Grouping.
Definition: Rule.php:368
$key
Definition: croninfo.php:18