ILIAS  release_5-2 Revision v5.2.25-18-g3f80b82851
Column.php
Go to the documentation of this file.
1 <?php
37 {
38  const AUTOFILTER_FILTERTYPE_FILTER = 'filters';
39  const AUTOFILTER_FILTERTYPE_CUSTOMFILTER = 'customFilters';
40  // Supports no more than 2 rules, with an And/Or join criteria
41  // if more than 1 rule is defined
42  const AUTOFILTER_FILTERTYPE_DYNAMICFILTER = 'dynamicFilter';
43  // Even though the filter rule is constant, the filtered data can vary
44  // e.g. filtered by date = TODAY
46 
52  private static $_filterTypes = array(
53  // Currently we're not handling
54  // colorFilter
55  // extLst
56  // iconFilter
57  self::AUTOFILTER_FILTERTYPE_FILTER,
58  self::AUTOFILTER_FILTERTYPE_CUSTOMFILTER,
59  self::AUTOFILTER_FILTERTYPE_DYNAMICFILTER,
60  self::AUTOFILTER_FILTERTYPE_TOPTENFILTER,
61  );
62 
63  /* Multiple Rule Connections */
66 
72  private static $_ruleJoins = array(
73  self::AUTOFILTER_COLUMN_JOIN_AND,
74  self::AUTOFILTER_COLUMN_JOIN_OR,
75  );
76 
82  private $_parent = NULL;
83 
84 
90  private $_columnIndex = '';
91 
92 
98  private $_filterType = self::AUTOFILTER_FILTERTYPE_FILTER;
99 
100 
106  private $_join = self::AUTOFILTER_COLUMN_JOIN_OR;
107 
108 
114  private $_ruleset = array();
115 
116 
122  private $_attributes = array();
123 
124 
131  public function __construct($pColumn, PHPExcel_Worksheet_AutoFilter $pParent = NULL)
132  {
133  $this->_columnIndex = $pColumn;
134  $this->_parent = $pParent;
135  }
136 
142  public function getColumnIndex() {
143  return $this->_columnIndex;
144  }
145 
153  public function setColumnIndex($pColumn) {
154  // Uppercase coordinate
155  $pColumn = strtoupper($pColumn);
156  if ($this->_parent !== NULL) {
157  $this->_parent->testColumnInRange($pColumn);
158  }
159 
160  $this->_columnIndex = $pColumn;
161 
162  return $this;
163  }
164 
170  public function getParent() {
171  return $this->_parent;
172  }
173 
180  public function setParent(PHPExcel_Worksheet_AutoFilter $pParent = NULL) {
181  $this->_parent = $pParent;
182 
183  return $this;
184  }
185 
191  public function getFilterType() {
192  return $this->_filterType;
193  }
194 
202  public function setFilterType($pFilterType = self::AUTOFILTER_FILTERTYPE_FILTER) {
203  if (!in_array($pFilterType,self::$_filterTypes)) {
204  throw new PHPExcel_Exception('Invalid filter type for column AutoFilter.');
205  }
206 
207  $this->_filterType = $pFilterType;
208 
209  return $this;
210  }
211 
217  public function getJoin() {
218  return $this->_join;
219  }
220 
228  public function setJoin($pJoin = self::AUTOFILTER_COLUMN_JOIN_OR) {
229  // Lowercase And/Or
230  $pJoin = strtolower($pJoin);
231  if (!in_array($pJoin,self::$_ruleJoins)) {
232  throw new PHPExcel_Exception('Invalid rule connection for column AutoFilter.');
233  }
234 
235  $this->_join = $pJoin;
236 
237  return $this;
238  }
239 
247  public function setAttributes($pAttributes = array()) {
248  $this->_attributes = $pAttributes;
249 
250  return $this;
251  }
252 
261  public function setAttribute($pName, $pValue) {
262  $this->_attributes[$pName] = $pValue;
263 
264  return $this;
265  }
266 
272  public function getAttributes() {
273  return $this->_attributes;
274  }
275 
282  public function getAttribute($pName) {
283  if (isset($this->_attributes[$pName]))
284  return $this->_attributes[$pName];
285  return NULL;
286  }
287 
294  public function getRules() {
295  return $this->_ruleset;
296  }
297 
304  public function getRule($pIndex) {
305  if (!isset($this->_ruleset[$pIndex])) {
306  $this->_ruleset[$pIndex] = new PHPExcel_Worksheet_AutoFilter_Column_Rule($this);
307  }
308  return $this->_ruleset[$pIndex];
309  }
310 
316  public function createRule() {
317  $this->_ruleset[] = new PHPExcel_Worksheet_AutoFilter_Column_Rule($this);
318 
319  return end($this->_ruleset);
320  }
321 
329  public function addRule(PHPExcel_Worksheet_AutoFilter_Column_Rule $pRule, $returnRule=TRUE) {
330  $pRule->setParent($this);
331  $this->_ruleset[] = $pRule;
332 
333  return ($returnRule) ? $pRule : $this;
334  }
335 
343  public function deleteRule($pIndex) {
344  if (isset($this->_ruleset[$pIndex])) {
345  unset($this->_ruleset[$pIndex]);
346  // If we've just deleted down to a single rule, then reset And/Or joining to Or
347  if (count($this->_ruleset) <= 1) {
348  $this->setJoin(self::AUTOFILTER_COLUMN_JOIN_OR);
349  }
350  }
351 
352  return $this;
353  }
354 
360  public function clearRules() {
361  $this->_ruleset = array();
362  $this->setJoin(self::AUTOFILTER_COLUMN_JOIN_OR);
363 
364  return $this;
365  }
366 
370  public function __clone() {
371  $vars = get_object_vars($this);
372  foreach ($vars as $key => $value) {
373  if (is_object($value)) {
374  if ($key == '_parent') {
375  // Detach from autofilter parent
376  $this->$key = NULL;
377  } else {
378  $this->$key = clone $value;
379  }
380  } elseif ((is_array($value)) && ($key == '_ruleset')) {
381  // The columns array of PHPExcel_Worksheet_AutoFilter objects
382  $this->$key = array();
383  foreach ($value as $k => $v) {
384  $this->$key[$k] = clone $v;
385  // attach the new cloned Rule to this new cloned Autofilter Cloned object
386  $this->$key[$k]->setParent($this);
387  }
388  } else {
389  $this->$key = $value;
390  }
391  }
392  }
393 
394 }
setAttributes($pAttributes=array())
Set AutoFilter Attributes.
Definition: Column.php:247
setFilterType($pFilterType=self::AUTOFILTER_FILTERTYPE_FILTER)
Set AutoFilter Type.
Definition: Column.php:202
getRule($pIndex)
Get a specified AutoFilter Column Rule.
Definition: Column.php:304
createRule()
Create a new AutoFilter Column Rule in the ruleset.
Definition: Column.php:316
setParent(PHPExcel_Worksheet_AutoFilter $pParent=NULL)
Set this Column&#39;s AutoFilter Parent.
Definition: Column.php:180
getAttributes()
Get AutoFilter Column Attributes.
Definition: Column.php:272
setParent(PHPExcel_Worksheet_AutoFilter_Column $pParent=NULL)
Set this Rule&#39;s AutoFilter Column Parent.
Definition: Rule.php:439
getFilterType()
Get AutoFilter Type.
Definition: Column.php:191
setJoin($pJoin=self::AUTOFILTER_COLUMN_JOIN_OR)
Set AutoFilter Multiple Rules And/Or.
Definition: Column.php:228
getParent()
Get this Column&#39;s AutoFilter Parent.
Definition: Column.php:170
__clone()
Implement PHP __clone to create a deep clone, not just a shallow copy.
Definition: Column.php:370
setColumnIndex($pColumn)
Set AutoFilter Column Index.
Definition: Column.php:153
clearRules()
Delete all AutoFilter Column Rules.
Definition: Column.php:360
deleteRule($pIndex)
Delete a specified AutoFilter Column Rule If the number of rules is reduced to 1, then we reset And/O...
Definition: Column.php:343
getRules()
Get all AutoFilter Column Rules.
Definition: Column.php:294
getColumnIndex()
Get AutoFilter Column Index.
Definition: Column.php:142
addRule(PHPExcel_Worksheet_AutoFilter_Column_Rule $pRule, $returnRule=TRUE)
Add a new AutoFilter Column Rule to the ruleset.
Definition: Column.php:329
getAttribute($pName)
Get specific AutoFilter Column Attribute.
Definition: Column.php:282
getJoin()
Get AutoFilter Multiple Rules And/Or Join.
Definition: Column.php:217
setAttribute($pName, $pValue)
Set An AutoFilter Attribute.
Definition: Column.php:261
Create styles array
The data for the language used.
__construct($pColumn, PHPExcel_Worksheet_AutoFilter $pParent=NULL)
Create a new PHPExcel_Worksheet_AutoFilter_Column.
Definition: Column.php:131