ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
Rule.php
Go to the documentation of this file.
1 <?php
37 {
38  const AUTOFILTER_RULETYPE_FILTER = 'filter';
39  const AUTOFILTER_RULETYPE_DATEGROUP = 'dateGroupItem';
40  const AUTOFILTER_RULETYPE_CUSTOMFILTER = 'customFilter';
41  const AUTOFILTER_RULETYPE_DYNAMICFILTER = 'dynamicFilter';
42  const AUTOFILTER_RULETYPE_TOPTENFILTER = 'top10Filter';
43 
44  private static $_ruleTypes = array(
45  // Currently we're not handling
46  // colorFilter
47  // extLst
48  // iconFilter
49  self::AUTOFILTER_RULETYPE_FILTER,
50  self::AUTOFILTER_RULETYPE_DATEGROUP,
51  self::AUTOFILTER_RULETYPE_CUSTOMFILTER,
52  self::AUTOFILTER_RULETYPE_DYNAMICFILTER,
53  self::AUTOFILTER_RULETYPE_TOPTENFILTER,
54  );
55 
62 
63  private static $_dateTimeGroups = array(
64  self::AUTOFILTER_RULETYPE_DATEGROUP_YEAR,
65  self::AUTOFILTER_RULETYPE_DATEGROUP_MONTH,
66  self::AUTOFILTER_RULETYPE_DATEGROUP_DAY,
67  self::AUTOFILTER_RULETYPE_DATEGROUP_HOUR,
68  self::AUTOFILTER_RULETYPE_DATEGROUP_MINUTE,
69  self::AUTOFILTER_RULETYPE_DATEGROUP_SECOND,
70  );
71 
89  const AUTOFILTER_RULETYPE_DYNAMIC_JANUARY = self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_1;
91  const AUTOFILTER_RULETYPE_DYNAMIC_FEBRUARY = self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_2;
93  const AUTOFILTER_RULETYPE_DYNAMIC_MARCH = self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_3;
95  const AUTOFILTER_RULETYPE_DYNAMIC_APRIL = self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_4;
97  const AUTOFILTER_RULETYPE_DYNAMIC_MAY = self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_5;
99  const AUTOFILTER_RULETYPE_DYNAMIC_JUNE = self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_6;
101  const AUTOFILTER_RULETYPE_DYNAMIC_JULY = self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_7;
103  const AUTOFILTER_RULETYPE_DYNAMIC_AUGUST = self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_8;
105  const AUTOFILTER_RULETYPE_DYNAMIC_SEPTEMBER = self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_9;
107  const AUTOFILTER_RULETYPE_DYNAMIC_OCTOBER = self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_10;
109  const AUTOFILTER_RULETYPE_DYNAMIC_NOVEMBER = self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_11;
111  const AUTOFILTER_RULETYPE_DYNAMIC_DECEMBER = self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_12;
118 
119  private static $_dynamicTypes = array(
120  self::AUTOFILTER_RULETYPE_DYNAMIC_YESTERDAY,
121  self::AUTOFILTER_RULETYPE_DYNAMIC_TODAY,
122  self::AUTOFILTER_RULETYPE_DYNAMIC_TOMORROW,
123  self::AUTOFILTER_RULETYPE_DYNAMIC_YEARTODATE,
124  self::AUTOFILTER_RULETYPE_DYNAMIC_THISYEAR,
125  self::AUTOFILTER_RULETYPE_DYNAMIC_THISQUARTER,
126  self::AUTOFILTER_RULETYPE_DYNAMIC_THISMONTH,
127  self::AUTOFILTER_RULETYPE_DYNAMIC_THISWEEK,
128  self::AUTOFILTER_RULETYPE_DYNAMIC_LASTYEAR,
129  self::AUTOFILTER_RULETYPE_DYNAMIC_LASTQUARTER,
130  self::AUTOFILTER_RULETYPE_DYNAMIC_LASTMONTH,
131  self::AUTOFILTER_RULETYPE_DYNAMIC_LASTWEEK,
132  self::AUTOFILTER_RULETYPE_DYNAMIC_NEXTYEAR,
133  self::AUTOFILTER_RULETYPE_DYNAMIC_NEXTQUARTER,
134  self::AUTOFILTER_RULETYPE_DYNAMIC_NEXTMONTH,
135  self::AUTOFILTER_RULETYPE_DYNAMIC_NEXTWEEK,
136  self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_1,
137  self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_2,
138  self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_3,
139  self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_4,
140  self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_5,
141  self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_6,
142  self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_7,
143  self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_8,
144  self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_9,
145  self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_10,
146  self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_11,
147  self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_12,
148  self::AUTOFILTER_RULETYPE_DYNAMIC_QUARTER_1,
149  self::AUTOFILTER_RULETYPE_DYNAMIC_QUARTER_2,
150  self::AUTOFILTER_RULETYPE_DYNAMIC_QUARTER_3,
151  self::AUTOFILTER_RULETYPE_DYNAMIC_QUARTER_4,
152  self::AUTOFILTER_RULETYPE_DYNAMIC_ABOVEAVERAGE,
153  self::AUTOFILTER_RULETYPE_DYNAMIC_BELOWAVERAGE,
154  );
155 
156  /*
157  * The only valid filter rule operators for filter and customFilter types are:
158  * <xsd:enumeration value="equal"/>
159  * <xsd:enumeration value="lessThan"/>
160  * <xsd:enumeration value="lessThanOrEqual"/>
161  * <xsd:enumeration value="notEqual"/>
162  * <xsd:enumeration value="greaterThanOrEqual"/>
163  * <xsd:enumeration value="greaterThan"/>
164  */
167  const AUTOFILTER_COLUMN_RULE_GREATERTHAN = 'greaterThan';
168  const AUTOFILTER_COLUMN_RULE_GREATERTHANOREQUAL = 'greaterThanOrEqual';
170  const AUTOFILTER_COLUMN_RULE_LESSTHANOREQUAL = 'lessThanOrEqual';
171 
172  private static $_operators = array(
173  self::AUTOFILTER_COLUMN_RULE_EQUAL,
174  self::AUTOFILTER_COLUMN_RULE_NOTEQUAL,
175  self::AUTOFILTER_COLUMN_RULE_GREATERTHAN,
176  self::AUTOFILTER_COLUMN_RULE_GREATERTHANOREQUAL,
177  self::AUTOFILTER_COLUMN_RULE_LESSTHAN,
178  self::AUTOFILTER_COLUMN_RULE_LESSTHANOREQUAL,
179  );
180 
183 
184  private static $_topTenValue = array(
185  self::AUTOFILTER_COLUMN_RULE_TOPTEN_BY_VALUE,
186  self::AUTOFILTER_COLUMN_RULE_TOPTEN_PERCENT,
187  );
188 
191 
192  private static $_topTenType = array(
193  self::AUTOFILTER_COLUMN_RULE_TOPTEN_TOP,
194  self::AUTOFILTER_COLUMN_RULE_TOPTEN_BOTTOM,
195  );
196 
197 
198  /* Rule Operators (Numeric, Boolean etc) */
199 // const AUTOFILTER_COLUMN_RULE_BETWEEN = 'between'; // greaterThanOrEqual 1 && lessThanOrEqual 2
200  /* Rule Operators (Numeric Special) which are translated to standard numeric operators with calculated values */
201 // const AUTOFILTER_COLUMN_RULE_TOPTEN = 'topTen'; // greaterThan calculated value
202 // const AUTOFILTER_COLUMN_RULE_TOPTENPERCENT = 'topTenPercent'; // greaterThan calculated value
203 // const AUTOFILTER_COLUMN_RULE_ABOVEAVERAGE = 'aboveAverage'; // Value is calculated as the average
204 // const AUTOFILTER_COLUMN_RULE_BELOWAVERAGE = 'belowAverage'; // Value is calculated as the average
205  /* Rule Operators (String) which are set as wild-carded values */
206 // const AUTOFILTER_COLUMN_RULE_BEGINSWITH = 'beginsWith'; // A*
207 // const AUTOFILTER_COLUMN_RULE_ENDSWITH = 'endsWith'; // *Z
208 // const AUTOFILTER_COLUMN_RULE_CONTAINS = 'contains'; // *B*
209 // const AUTOFILTER_COLUMN_RULE_DOESNTCONTAIN = 'notEqual'; // notEqual *B*
210  /* Rule Operators (Date Special) which are translated to standard numeric operators with calculated values */
211 // const AUTOFILTER_COLUMN_RULE_BEFORE = 'lessThan';
212 // const AUTOFILTER_COLUMN_RULE_AFTER = 'greaterThan';
213 // const AUTOFILTER_COLUMN_RULE_YESTERDAY = 'yesterday';
214 // const AUTOFILTER_COLUMN_RULE_TODAY = 'today';
215 // const AUTOFILTER_COLUMN_RULE_TOMORROW = 'tomorrow';
216 // const AUTOFILTER_COLUMN_RULE_LASTWEEK = 'lastWeek';
217 // const AUTOFILTER_COLUMN_RULE_THISWEEK = 'thisWeek';
218 // const AUTOFILTER_COLUMN_RULE_NEXTWEEK = 'nextWeek';
219 // const AUTOFILTER_COLUMN_RULE_LASTMONTH = 'lastMonth';
220 // const AUTOFILTER_COLUMN_RULE_THISMONTH = 'thisMonth';
221 // const AUTOFILTER_COLUMN_RULE_NEXTMONTH = 'nextMonth';
222 // const AUTOFILTER_COLUMN_RULE_LASTQUARTER = 'lastQuarter';
223 // const AUTOFILTER_COLUMN_RULE_THISQUARTER = 'thisQuarter';
224 // const AUTOFILTER_COLUMN_RULE_NEXTQUARTER = 'nextQuarter';
225 // const AUTOFILTER_COLUMN_RULE_LASTYEAR = 'lastYear';
226 // const AUTOFILTER_COLUMN_RULE_THISYEAR = 'thisYear';
227 // const AUTOFILTER_COLUMN_RULE_NEXTYEAR = 'nextYear';
228 // const AUTOFILTER_COLUMN_RULE_YEARTODATE = 'yearToDate'; // <dynamicFilter val="40909" type="yearToDate" maxVal="41113"/>
229 // const AUTOFILTER_COLUMN_RULE_ALLDATESINMONTH = 'allDatesInMonth'; // <dynamicFilter type="M2"/> for Month/February
230 // const AUTOFILTER_COLUMN_RULE_ALLDATESINQUARTER = 'allDatesInQuarter'; // <dynamicFilter type="Q2"/> for Quarter 2
231 
237  private $_parent = NULL;
238 
239 
245  private $_ruleType = self::AUTOFILTER_RULETYPE_FILTER;
246 
247 
253  private $_value = '';
254 
260  private $_operator = self::AUTOFILTER_COLUMN_RULE_EQUAL;
261 
267  private $_grouping = '';
268 
269 
275  public function __construct(PHPExcel_Worksheet_AutoFilter_Column $pParent = NULL)
276  {
277  $this->_parent = $pParent;
278  }
279 
285  public function getRuleType() {
286  return $this->_ruleType;
287  }
288 
296  public function setRuleType($pRuleType = self::AUTOFILTER_RULETYPE_FILTER) {
297  if (!in_array($pRuleType,self::$_ruleTypes)) {
298  throw new PHPExcel_Exception('Invalid rule type for column AutoFilter Rule.');
299  }
300 
301  $this->_ruleType = $pRuleType;
302 
303  return $this;
304  }
305 
311  public function getValue() {
312  return $this->_value;
313  }
314 
322  public function setValue($pValue = '') {
323  if (is_array($pValue)) {
324  $grouping = -1;
325  foreach($pValue as $key => $value) {
326  // Validate array entries
327  if (!in_array($key,self::$_dateTimeGroups)) {
328  // Remove any invalid entries from the value array
329  unset($pValue[$key]);
330  } else {
331  // Work out what the dateTime grouping will be
332  $grouping = max($grouping,array_search($key,self::$_dateTimeGroups));
333  }
334  }
335  if (count($pValue) == 0) {
336  throw new PHPExcel_Exception('Invalid rule value for column AutoFilter Rule.');
337  }
338  // Set the dateTime grouping that we've anticipated
339  $this->setGrouping(self::$_dateTimeGroups[$grouping]);
340  }
341  $this->_value = $pValue;
342 
343  return $this;
344  }
345 
351  public function getOperator() {
352  return $this->_operator;
353  }
354 
362  public function setOperator($pOperator = self::AUTOFILTER_COLUMN_RULE_EQUAL) {
363  if (empty($pOperator))
364  $pOperator = self::AUTOFILTER_COLUMN_RULE_EQUAL;
365  if ((!in_array($pOperator,self::$_operators)) &&
366  (!in_array($pOperator,self::$_topTenValue))) {
367  throw new PHPExcel_Exception('Invalid operator for column AutoFilter Rule.');
368  }
369  $this->_operator = $pOperator;
370 
371  return $this;
372  }
373 
379  public function getGrouping() {
380  return $this->_grouping;
381  }
382 
390  public function setGrouping($pGrouping = NULL) {
391  if (($pGrouping !== NULL) &&
392  (!in_array($pGrouping,self::$_dateTimeGroups)) &&
393  (!in_array($pGrouping,self::$_dynamicTypes)) &&
394  (!in_array($pGrouping,self::$_topTenType))) {
395  throw new PHPExcel_Exception('Invalid rule type for column AutoFilter Rule.');
396  }
397 
398  $this->_grouping = $pGrouping;
399 
400  return $this;
401  }
402 
412  public function setRule($pOperator = self::AUTOFILTER_COLUMN_RULE_EQUAL, $pValue = '', $pGrouping = NULL) {
413  $this->setOperator($pOperator);
414  $this->setValue($pValue);
415  // Only set grouping if it's been passed in as a user-supplied argument,
416  // otherwise we're calculating it when we setValue() and don't want to overwrite that
417  // If the user supplies an argumnet for grouping, then on their own head be it
418  if ($pGrouping !== NULL)
419  $this->setGrouping($pGrouping);
420 
421  return $this;
422  }
423 
429  public function getParent() {
430  return $this->_parent;
431  }
432 
439  public function setParent(PHPExcel_Worksheet_AutoFilter_Column $pParent = NULL) {
440  $this->_parent = $pParent;
441 
442  return $this;
443  }
444 
448  public function __clone() {
449  $vars = get_object_vars($this);
450  foreach ($vars as $key => $value) {
451  if (is_object($value)) {
452  if ($key == '_parent') {
453  // Detach from autofilter column parent
454  $this->$key = NULL;
455  } else {
456  $this->$key = clone $value;
457  }
458  } else {
459  $this->$key = $value;
460  }
461  }
462  }
463 
464 }
getGrouping()
Get AutoFilter Rule Grouping.
Definition: Rule.php:379
setParent(PHPExcel_Worksheet_AutoFilter_Column $pParent=NULL)
Set this Rule&#39;s AutoFilter Column Parent.
Definition: Rule.php:439
getOperator()
Get AutoFilter Rule Operator.
Definition: Rule.php:351
getRuleType()
Get AutoFilter Rule Type.
Definition: Rule.php:285
setRule($pOperator=self::AUTOFILTER_COLUMN_RULE_EQUAL, $pValue='', $pGrouping=NULL)
Set AutoFilter Rule.
Definition: Rule.php:412
setValue($pValue='')
Set AutoFilter Rule Value.
Definition: Rule.php:322
__clone()
Implement PHP __clone to create a deep clone, not just a shallow copy.
Definition: Rule.php:448
setRuleType($pRuleType=self::AUTOFILTER_RULETYPE_FILTER)
Set AutoFilter Rule Type.
Definition: Rule.php:296
__construct(PHPExcel_Worksheet_AutoFilter_Column $pParent=NULL)
Create a new PHPExcel_Worksheet_AutoFilter_Column_Rule.
Definition: Rule.php:275
Create styles array
The data for the language used.
setGrouping($pGrouping=NULL)
Set AutoFilter Rule Grouping.
Definition: Rule.php:390
getParent()
Get this Rule&#39;s AutoFilter Column Parent.
Definition: Rule.php:429
getValue()
Get AutoFilter Rule Value.
Definition: Rule.php:311
setOperator($pOperator=self::AUTOFILTER_COLUMN_RULE_EQUAL)
Set AutoFilter Rule Operator.
Definition: Rule.php:362