OSDN Git Service

Добавлены некоторые тесты сайта. Доавлен, но не подключён модуль импорта из .xls...
[invent/invent.git] / vendor / phpoffice / phpexcel / Classes / PHPExcel / Worksheet / AutoFilter / Column.php
1 <?php
2
3 /**
4  * PHPExcel_Worksheet_AutoFilter_Column
5  *
6  * Copyright (c) 2006 - 2015 PHPExcel
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    PHPExcel
23  * @package        PHPExcel_Worksheet
24  * @copyright    Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
25  * @license        http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
26  * @version        ##VERSION##, ##DATE##
27  */
28 class PHPExcel_Worksheet_AutoFilter_Column
29 {
30     const AUTOFILTER_FILTERTYPE_FILTER         = 'filters';
31     const AUTOFILTER_FILTERTYPE_CUSTOMFILTER   = 'customFilters';
32     //    Supports no more than 2 rules, with an And/Or join criteria
33     //        if more than 1 rule is defined
34     const AUTOFILTER_FILTERTYPE_DYNAMICFILTER  = 'dynamicFilter';
35     //    Even though the filter rule is constant, the filtered data can vary
36     //        e.g. filtered by date = TODAY
37     const AUTOFILTER_FILTERTYPE_TOPTENFILTER   = 'top10';
38
39     /**
40      * Types of autofilter rules
41      *
42      * @var string[]
43      */
44     private static $filterTypes = array(
45         //    Currently we're not handling
46         //        colorFilter
47         //        extLst
48         //        iconFilter
49         self::AUTOFILTER_FILTERTYPE_FILTER,
50         self::AUTOFILTER_FILTERTYPE_CUSTOMFILTER,
51         self::AUTOFILTER_FILTERTYPE_DYNAMICFILTER,
52         self::AUTOFILTER_FILTERTYPE_TOPTENFILTER,
53     );
54
55     /* Multiple Rule Connections */
56     const AUTOFILTER_COLUMN_JOIN_AND = 'and';
57     const AUTOFILTER_COLUMN_JOIN_OR  = 'or';
58
59     /**
60      * Join options for autofilter rules
61      *
62      * @var string[]
63      */
64     private static $ruleJoins = array(
65         self::AUTOFILTER_COLUMN_JOIN_AND,
66         self::AUTOFILTER_COLUMN_JOIN_OR,
67     );
68
69     /**
70      * Autofilter
71      *
72      * @var PHPExcel_Worksheet_AutoFilter
73      */
74     private $parent;
75
76
77     /**
78      * Autofilter Column Index
79      *
80      * @var string
81      */
82     private $columnIndex = '';
83
84
85     /**
86      * Autofilter Column Filter Type
87      *
88      * @var string
89      */
90     private $filterType = self::AUTOFILTER_FILTERTYPE_FILTER;
91
92
93     /**
94      * Autofilter Multiple Rules And/Or
95      *
96      * @var string
97      */
98     private $join = self::AUTOFILTER_COLUMN_JOIN_OR;
99
100
101     /**
102      * Autofilter Column Rules
103      *
104      * @var array of PHPExcel_Worksheet_AutoFilter_Column_Rule
105      */
106     private $ruleset = array();
107
108
109     /**
110      * Autofilter Column Dynamic Attributes
111      *
112      * @var array of mixed
113      */
114     private $attributes = array();
115
116
117     /**
118      * Create a new PHPExcel_Worksheet_AutoFilter_Column
119      *
120      *    @param    string                           $pColumn        Column (e.g. A)
121      *    @param    PHPExcel_Worksheet_AutoFilter  $pParent        Autofilter for this column
122      */
123     public function __construct($pColumn, PHPExcel_Worksheet_AutoFilter $pParent = null)
124     {
125         $this->columnIndex = $pColumn;
126         $this->parent = $pParent;
127     }
128
129     /**
130      * Get AutoFilter Column Index
131      *
132      * @return string
133      */
134     public function getColumnIndex()
135     {
136         return $this->columnIndex;
137     }
138
139     /**
140      *    Set AutoFilter Column Index
141      *
142      *    @param    string        $pColumn        Column (e.g. A)
143      *    @throws    PHPExcel_Exception
144      *    @return PHPExcel_Worksheet_AutoFilter_Column
145      */
146     public function setColumnIndex($pColumn)
147     {
148         // Uppercase coordinate
149         $pColumn = strtoupper($pColumn);
150         if ($this->parent !== null) {
151             $this->parent->testColumnInRange($pColumn);
152         }
153
154         $this->columnIndex = $pColumn;
155
156         return $this;
157     }
158
159     /**
160      * Get this Column's AutoFilter Parent
161      *
162      * @return PHPExcel_Worksheet_AutoFilter
163      */
164     public function getParent()
165     {
166         return $this->parent;
167     }
168
169     /**
170      * Set this Column's AutoFilter Parent
171      *
172      * @param PHPExcel_Worksheet_AutoFilter
173      * @return PHPExcel_Worksheet_AutoFilter_Column
174      */
175     public function setParent(PHPExcel_Worksheet_AutoFilter $pParent = null)
176     {
177         $this->parent = $pParent;
178
179         return $this;
180     }
181
182     /**
183      * Get AutoFilter Type
184      *
185      * @return string
186      */
187     public function getFilterType()
188     {
189         return $this->filterType;
190     }
191
192     /**
193      *    Set AutoFilter Type
194      *
195      *    @param    string        $pFilterType
196      *    @throws    PHPExcel_Exception
197      *    @return PHPExcel_Worksheet_AutoFilter_Column
198      */
199     public function setFilterType($pFilterType = self::AUTOFILTER_FILTERTYPE_FILTER)
200     {
201         if (!in_array($pFilterType, self::$filterTypes)) {
202             throw new PHPExcel_Exception('Invalid filter type for column AutoFilter.');
203         }
204
205         $this->filterType = $pFilterType;
206
207         return $this;
208     }
209
210     /**
211      * Get AutoFilter Multiple Rules And/Or Join
212      *
213      * @return string
214      */
215     public function getJoin()
216     {
217         return $this->join;
218     }
219
220     /**
221      *    Set AutoFilter Multiple Rules And/Or
222      *
223      *    @param    string        $pJoin        And/Or
224      *    @throws    PHPExcel_Exception
225      *    @return PHPExcel_Worksheet_AutoFilter_Column
226      */
227     public function setJoin($pJoin = self::AUTOFILTER_COLUMN_JOIN_OR)
228     {
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
240     /**
241      *    Set AutoFilter Attributes
242      *
243      *    @param    string[]        $pAttributes
244      *    @throws    PHPExcel_Exception
245      *    @return PHPExcel_Worksheet_AutoFilter_Column
246      */
247     public function setAttributes($pAttributes = array())
248     {
249         $this->attributes = $pAttributes;
250
251         return $this;
252     }
253
254     /**
255      *    Set An AutoFilter Attribute
256      *
257      *    @param    string        $pName        Attribute Name
258      *    @param    string        $pValue        Attribute Value
259      *    @throws    PHPExcel_Exception
260      *    @return PHPExcel_Worksheet_AutoFilter_Column
261      */
262     public function setAttribute($pName, $pValue)
263     {
264         $this->attributes[$pName] = $pValue;
265
266         return $this;
267     }
268
269     /**
270      * Get AutoFilter Column Attributes
271      *
272      * @return string
273      */
274     public function getAttributes()
275     {
276         return $this->attributes;
277     }
278
279     /**
280      * Get specific AutoFilter Column Attribute
281      *
282      *    @param    string        $pName        Attribute Name
283      * @return string
284      */
285     public function getAttribute($pName)
286     {
287         if (isset($this->attributes[$pName])) {
288             return $this->attributes[$pName];
289         }
290         return null;
291     }
292
293     /**
294      * Get all AutoFilter Column Rules
295      *
296      * @throws    PHPExcel_Exception
297      * @return array of PHPExcel_Worksheet_AutoFilter_Column_Rule
298      */
299     public function getRules()
300     {
301         return $this->ruleset;
302     }
303
304     /**
305      * Get a specified AutoFilter Column Rule
306      *
307      * @param    integer    $pIndex        Rule index in the ruleset array
308      * @return    PHPExcel_Worksheet_AutoFilter_Column_Rule
309      */
310     public function getRule($pIndex)
311     {
312         if (!isset($this->ruleset[$pIndex])) {
313             $this->ruleset[$pIndex] = new PHPExcel_Worksheet_AutoFilter_Column_Rule($this);
314         }
315         return $this->ruleset[$pIndex];
316     }
317
318     /**
319      * Create a new AutoFilter Column Rule in the ruleset
320      *
321      * @return    PHPExcel_Worksheet_AutoFilter_Column_Rule
322      */
323     public function createRule()
324     {
325         $this->ruleset[] = new PHPExcel_Worksheet_AutoFilter_Column_Rule($this);
326
327         return end($this->ruleset);
328     }
329
330     /**
331      * Add a new AutoFilter Column Rule to the ruleset
332      *
333      * @param    PHPExcel_Worksheet_AutoFilter_Column_Rule    $pRule
334      * @param    boolean    $returnRule     Flag indicating whether the rule object or the column object should be returned
335      * @return    PHPExcel_Worksheet_AutoFilter_Column|PHPExcel_Worksheet_AutoFilter_Column_Rule
336      */
337     public function addRule(PHPExcel_Worksheet_AutoFilter_Column_Rule $pRule, $returnRule = true)
338     {
339         $pRule->setParent($this);
340         $this->ruleset[] = $pRule;
341
342         return ($returnRule) ? $pRule : $this;
343     }
344
345     /**
346      * Delete a specified AutoFilter Column Rule
347      *    If the number of rules is reduced to 1, then we reset And/Or logic to Or
348      *
349      * @param    integer    $pIndex        Rule index in the ruleset array
350      * @return    PHPExcel_Worksheet_AutoFilter_Column
351      */
352     public function deleteRule($pIndex)
353     {
354         if (isset($this->ruleset[$pIndex])) {
355             unset($this->ruleset[$pIndex]);
356             //    If we've just deleted down to a single rule, then reset And/Or joining to Or
357             if (count($this->ruleset) <= 1) {
358                 $this->setJoin(self::AUTOFILTER_COLUMN_JOIN_OR);
359             }
360         }
361
362         return $this;
363     }
364
365     /**
366      * Delete all AutoFilter Column Rules
367      *
368      * @return    PHPExcel_Worksheet_AutoFilter_Column
369      */
370     public function clearRules()
371     {
372         $this->ruleset = array();
373         $this->setJoin(self::AUTOFILTER_COLUMN_JOIN_OR);
374
375         return $this;
376     }
377
378     /**
379      * Implement PHP __clone to create a deep clone, not just a shallow copy.
380      */
381     public function __clone()
382     {
383         $vars = get_object_vars($this);
384         foreach ($vars as $key => $value) {
385             if (is_object($value)) {
386                 if ($key == 'parent') {
387                     //    Detach from autofilter parent
388                     $this->$key = null;
389                 } else {
390                     $this->$key = clone $value;
391                 }
392             } elseif ((is_array($value)) && ($key == 'ruleset')) {
393                 //    The columns array of PHPExcel_Worksheet_AutoFilter objects
394                 $this->$key = array();
395                 foreach ($value as $k => $v) {
396                     $this->$key[$k] = clone $v;
397                     // attach the new cloned Rule to this new cloned Autofilter Cloned object
398                     $this->$key[$k]->setParent($this);
399                 }
400             } else {
401                 $this->$key = $value;
402             }
403         }
404     }
405 }