6865e568e2c65c90a3d24fb1e93e91083f3b58c7.svn-base 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2014 PHPExcel
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * @category PHPExcel
  22. * @package PHPExcel_Worksheet
  23. * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version ##VERSION##, ##DATE##
  26. */
  27. /**
  28. * PHPExcel_Worksheet_AutoFilter_Column_Rule
  29. *
  30. * @category PHPExcel
  31. * @package PHPExcel_Worksheet
  32. * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
  33. */
  34. class PHPExcel_Worksheet_AutoFilter_Column_Rule
  35. {
  36. const AUTOFILTER_RULETYPE_FILTER = 'filter';
  37. const AUTOFILTER_RULETYPE_DATEGROUP = 'dateGroupItem';
  38. const AUTOFILTER_RULETYPE_CUSTOMFILTER = 'customFilter';
  39. const AUTOFILTER_RULETYPE_DYNAMICFILTER = 'dynamicFilter';
  40. const AUTOFILTER_RULETYPE_TOPTENFILTER = 'top10Filter';
  41. private static $_ruleTypes = array(
  42. // Currently we're not handling
  43. // colorFilter
  44. // extLst
  45. // iconFilter
  46. self::AUTOFILTER_RULETYPE_FILTER,
  47. self::AUTOFILTER_RULETYPE_DATEGROUP,
  48. self::AUTOFILTER_RULETYPE_CUSTOMFILTER,
  49. self::AUTOFILTER_RULETYPE_DYNAMICFILTER,
  50. self::AUTOFILTER_RULETYPE_TOPTENFILTER,
  51. );
  52. const AUTOFILTER_RULETYPE_DATEGROUP_YEAR = 'year';
  53. const AUTOFILTER_RULETYPE_DATEGROUP_MONTH = 'month';
  54. const AUTOFILTER_RULETYPE_DATEGROUP_DAY = 'day';
  55. const AUTOFILTER_RULETYPE_DATEGROUP_HOUR = 'hour';
  56. const AUTOFILTER_RULETYPE_DATEGROUP_MINUTE = 'minute';
  57. const AUTOFILTER_RULETYPE_DATEGROUP_SECOND = 'second';
  58. private static $_dateTimeGroups = array(
  59. self::AUTOFILTER_RULETYPE_DATEGROUP_YEAR,
  60. self::AUTOFILTER_RULETYPE_DATEGROUP_MONTH,
  61. self::AUTOFILTER_RULETYPE_DATEGROUP_DAY,
  62. self::AUTOFILTER_RULETYPE_DATEGROUP_HOUR,
  63. self::AUTOFILTER_RULETYPE_DATEGROUP_MINUTE,
  64. self::AUTOFILTER_RULETYPE_DATEGROUP_SECOND,
  65. );
  66. const AUTOFILTER_RULETYPE_DYNAMIC_YESTERDAY = 'yesterday';
  67. const AUTOFILTER_RULETYPE_DYNAMIC_TODAY = 'today';
  68. const AUTOFILTER_RULETYPE_DYNAMIC_TOMORROW = 'tomorrow';
  69. const AUTOFILTER_RULETYPE_DYNAMIC_YEARTODATE = 'yearToDate';
  70. const AUTOFILTER_RULETYPE_DYNAMIC_THISYEAR = 'thisYear';
  71. const AUTOFILTER_RULETYPE_DYNAMIC_THISQUARTER = 'thisQuarter';
  72. const AUTOFILTER_RULETYPE_DYNAMIC_THISMONTH = 'thisMonth';
  73. const AUTOFILTER_RULETYPE_DYNAMIC_THISWEEK = 'thisWeek';
  74. const AUTOFILTER_RULETYPE_DYNAMIC_LASTYEAR = 'lastYear';
  75. const AUTOFILTER_RULETYPE_DYNAMIC_LASTQUARTER = 'lastQuarter';
  76. const AUTOFILTER_RULETYPE_DYNAMIC_LASTMONTH = 'lastMonth';
  77. const AUTOFILTER_RULETYPE_DYNAMIC_LASTWEEK = 'lastWeek';
  78. const AUTOFILTER_RULETYPE_DYNAMIC_NEXTYEAR = 'nextYear';
  79. const AUTOFILTER_RULETYPE_DYNAMIC_NEXTQUARTER = 'nextQuarter';
  80. const AUTOFILTER_RULETYPE_DYNAMIC_NEXTMONTH = 'nextMonth';
  81. const AUTOFILTER_RULETYPE_DYNAMIC_NEXTWEEK = 'nextWeek';
  82. const AUTOFILTER_RULETYPE_DYNAMIC_MONTH_1 = 'M1';
  83. const AUTOFILTER_RULETYPE_DYNAMIC_JANUARY = self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_1;
  84. const AUTOFILTER_RULETYPE_DYNAMIC_MONTH_2 = 'M2';
  85. const AUTOFILTER_RULETYPE_DYNAMIC_FEBRUARY = self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_2;
  86. const AUTOFILTER_RULETYPE_DYNAMIC_MONTH_3 = 'M3';
  87. const AUTOFILTER_RULETYPE_DYNAMIC_MARCH = self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_3;
  88. const AUTOFILTER_RULETYPE_DYNAMIC_MONTH_4 = 'M4';
  89. const AUTOFILTER_RULETYPE_DYNAMIC_APRIL = self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_4;
  90. const AUTOFILTER_RULETYPE_DYNAMIC_MONTH_5 = 'M5';
  91. const AUTOFILTER_RULETYPE_DYNAMIC_MAY = self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_5;
  92. const AUTOFILTER_RULETYPE_DYNAMIC_MONTH_6 = 'M6';
  93. const AUTOFILTER_RULETYPE_DYNAMIC_JUNE = self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_6;
  94. const AUTOFILTER_RULETYPE_DYNAMIC_MONTH_7 = 'M7';
  95. const AUTOFILTER_RULETYPE_DYNAMIC_JULY = self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_7;
  96. const AUTOFILTER_RULETYPE_DYNAMIC_MONTH_8 = 'M8';
  97. const AUTOFILTER_RULETYPE_DYNAMIC_AUGUST = self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_8;
  98. const AUTOFILTER_RULETYPE_DYNAMIC_MONTH_9 = 'M9';
  99. const AUTOFILTER_RULETYPE_DYNAMIC_SEPTEMBER = self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_9;
  100. const AUTOFILTER_RULETYPE_DYNAMIC_MONTH_10 = 'M10';
  101. const AUTOFILTER_RULETYPE_DYNAMIC_OCTOBER = self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_10;
  102. const AUTOFILTER_RULETYPE_DYNAMIC_MONTH_11 = 'M11';
  103. const AUTOFILTER_RULETYPE_DYNAMIC_NOVEMBER = self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_11;
  104. const AUTOFILTER_RULETYPE_DYNAMIC_MONTH_12 = 'M12';
  105. const AUTOFILTER_RULETYPE_DYNAMIC_DECEMBER = self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_12;
  106. const AUTOFILTER_RULETYPE_DYNAMIC_QUARTER_1 = 'Q1';
  107. const AUTOFILTER_RULETYPE_DYNAMIC_QUARTER_2 = 'Q2';
  108. const AUTOFILTER_RULETYPE_DYNAMIC_QUARTER_3 = 'Q3';
  109. const AUTOFILTER_RULETYPE_DYNAMIC_QUARTER_4 = 'Q4';
  110. const AUTOFILTER_RULETYPE_DYNAMIC_ABOVEAVERAGE = 'aboveAverage';
  111. const AUTOFILTER_RULETYPE_DYNAMIC_BELOWAVERAGE = 'belowAverage';
  112. private static $_dynamicTypes = array(
  113. self::AUTOFILTER_RULETYPE_DYNAMIC_YESTERDAY,
  114. self::AUTOFILTER_RULETYPE_DYNAMIC_TODAY,
  115. self::AUTOFILTER_RULETYPE_DYNAMIC_TOMORROW,
  116. self::AUTOFILTER_RULETYPE_DYNAMIC_YEARTODATE,
  117. self::AUTOFILTER_RULETYPE_DYNAMIC_THISYEAR,
  118. self::AUTOFILTER_RULETYPE_DYNAMIC_THISQUARTER,
  119. self::AUTOFILTER_RULETYPE_DYNAMIC_THISMONTH,
  120. self::AUTOFILTER_RULETYPE_DYNAMIC_THISWEEK,
  121. self::AUTOFILTER_RULETYPE_DYNAMIC_LASTYEAR,
  122. self::AUTOFILTER_RULETYPE_DYNAMIC_LASTQUARTER,
  123. self::AUTOFILTER_RULETYPE_DYNAMIC_LASTMONTH,
  124. self::AUTOFILTER_RULETYPE_DYNAMIC_LASTWEEK,
  125. self::AUTOFILTER_RULETYPE_DYNAMIC_NEXTYEAR,
  126. self::AUTOFILTER_RULETYPE_DYNAMIC_NEXTQUARTER,
  127. self::AUTOFILTER_RULETYPE_DYNAMIC_NEXTMONTH,
  128. self::AUTOFILTER_RULETYPE_DYNAMIC_NEXTWEEK,
  129. self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_1,
  130. self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_2,
  131. self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_3,
  132. self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_4,
  133. self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_5,
  134. self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_6,
  135. self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_7,
  136. self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_8,
  137. self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_9,
  138. self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_10,
  139. self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_11,
  140. self::AUTOFILTER_RULETYPE_DYNAMIC_MONTH_12,
  141. self::AUTOFILTER_RULETYPE_DYNAMIC_QUARTER_1,
  142. self::AUTOFILTER_RULETYPE_DYNAMIC_QUARTER_2,
  143. self::AUTOFILTER_RULETYPE_DYNAMIC_QUARTER_3,
  144. self::AUTOFILTER_RULETYPE_DYNAMIC_QUARTER_4,
  145. self::AUTOFILTER_RULETYPE_DYNAMIC_ABOVEAVERAGE,
  146. self::AUTOFILTER_RULETYPE_DYNAMIC_BELOWAVERAGE,
  147. );
  148. /*
  149. * The only valid filter rule operators for filter and customFilter types are:
  150. * <xsd:enumeration value="equal"/>
  151. * <xsd:enumeration value="lessThan"/>
  152. * <xsd:enumeration value="lessThanOrEqual"/>
  153. * <xsd:enumeration value="notEqual"/>
  154. * <xsd:enumeration value="greaterThanOrEqual"/>
  155. * <xsd:enumeration value="greaterThan"/>
  156. */
  157. const AUTOFILTER_COLUMN_RULE_EQUAL = 'equal';
  158. const AUTOFILTER_COLUMN_RULE_NOTEQUAL = 'notEqual';
  159. const AUTOFILTER_COLUMN_RULE_GREATERTHAN = 'greaterThan';
  160. const AUTOFILTER_COLUMN_RULE_GREATERTHANOREQUAL = 'greaterThanOrEqual';
  161. const AUTOFILTER_COLUMN_RULE_LESSTHAN = 'lessThan';
  162. const AUTOFILTER_COLUMN_RULE_LESSTHANOREQUAL = 'lessThanOrEqual';
  163. private static $_operators = array(
  164. self::AUTOFILTER_COLUMN_RULE_EQUAL,
  165. self::AUTOFILTER_COLUMN_RULE_NOTEQUAL,
  166. self::AUTOFILTER_COLUMN_RULE_GREATERTHAN,
  167. self::AUTOFILTER_COLUMN_RULE_GREATERTHANOREQUAL,
  168. self::AUTOFILTER_COLUMN_RULE_LESSTHAN,
  169. self::AUTOFILTER_COLUMN_RULE_LESSTHANOREQUAL,
  170. );
  171. const AUTOFILTER_COLUMN_RULE_TOPTEN_BY_VALUE = 'byValue';
  172. const AUTOFILTER_COLUMN_RULE_TOPTEN_PERCENT = 'byPercent';
  173. private static $_topTenValue = array(
  174. self::AUTOFILTER_COLUMN_RULE_TOPTEN_BY_VALUE,
  175. self::AUTOFILTER_COLUMN_RULE_TOPTEN_PERCENT,
  176. );
  177. const AUTOFILTER_COLUMN_RULE_TOPTEN_TOP = 'top';
  178. const AUTOFILTER_COLUMN_RULE_TOPTEN_BOTTOM = 'bottom';
  179. private static $_topTenType = array(
  180. self::AUTOFILTER_COLUMN_RULE_TOPTEN_TOP,
  181. self::AUTOFILTER_COLUMN_RULE_TOPTEN_BOTTOM,
  182. );
  183. /* Rule Operators (Numeric, Boolean etc) */
  184. // const AUTOFILTER_COLUMN_RULE_BETWEEN = 'between'; // greaterThanOrEqual 1 && lessThanOrEqual 2
  185. /* Rule Operators (Numeric Special) which are translated to standard numeric operators with calculated values */
  186. // const AUTOFILTER_COLUMN_RULE_TOPTEN = 'topTen'; // greaterThan calculated value
  187. // const AUTOFILTER_COLUMN_RULE_TOPTENPERCENT = 'topTenPercent'; // greaterThan calculated value
  188. // const AUTOFILTER_COLUMN_RULE_ABOVEAVERAGE = 'aboveAverage'; // Value is calculated as the average
  189. // const AUTOFILTER_COLUMN_RULE_BELOWAVERAGE = 'belowAverage'; // Value is calculated as the average
  190. /* Rule Operators (String) which are set as wild-carded values */
  191. // const AUTOFILTER_COLUMN_RULE_BEGINSWITH = 'beginsWith'; // A*
  192. // const AUTOFILTER_COLUMN_RULE_ENDSWITH = 'endsWith'; // *Z
  193. // const AUTOFILTER_COLUMN_RULE_CONTAINS = 'contains'; // *B*
  194. // const AUTOFILTER_COLUMN_RULE_DOESNTCONTAIN = 'notEqual'; // notEqual *B*
  195. /* Rule Operators (Date Special) which are translated to standard numeric operators with calculated values */
  196. // const AUTOFILTER_COLUMN_RULE_BEFORE = 'lessThan';
  197. // const AUTOFILTER_COLUMN_RULE_AFTER = 'greaterThan';
  198. // const AUTOFILTER_COLUMN_RULE_YESTERDAY = 'yesterday';
  199. // const AUTOFILTER_COLUMN_RULE_TODAY = 'today';
  200. // const AUTOFILTER_COLUMN_RULE_TOMORROW = 'tomorrow';
  201. // const AUTOFILTER_COLUMN_RULE_LASTWEEK = 'lastWeek';
  202. // const AUTOFILTER_COLUMN_RULE_THISWEEK = 'thisWeek';
  203. // const AUTOFILTER_COLUMN_RULE_NEXTWEEK = 'nextWeek';
  204. // const AUTOFILTER_COLUMN_RULE_LASTMONTH = 'lastMonth';
  205. // const AUTOFILTER_COLUMN_RULE_THISMONTH = 'thisMonth';
  206. // const AUTOFILTER_COLUMN_RULE_NEXTMONTH = 'nextMonth';
  207. // const AUTOFILTER_COLUMN_RULE_LASTQUARTER = 'lastQuarter';
  208. // const AUTOFILTER_COLUMN_RULE_THISQUARTER = 'thisQuarter';
  209. // const AUTOFILTER_COLUMN_RULE_NEXTQUARTER = 'nextQuarter';
  210. // const AUTOFILTER_COLUMN_RULE_LASTYEAR = 'lastYear';
  211. // const AUTOFILTER_COLUMN_RULE_THISYEAR = 'thisYear';
  212. // const AUTOFILTER_COLUMN_RULE_NEXTYEAR = 'nextYear';
  213. // const AUTOFILTER_COLUMN_RULE_YEARTODATE = 'yearToDate'; // <dynamicFilter val="40909" type="yearToDate" maxVal="41113"/>
  214. // const AUTOFILTER_COLUMN_RULE_ALLDATESINMONTH = 'allDatesInMonth'; // <dynamicFilter type="M2"/> for Month/February
  215. // const AUTOFILTER_COLUMN_RULE_ALLDATESINQUARTER = 'allDatesInQuarter'; // <dynamicFilter type="Q2"/> for Quarter 2
  216. /**
  217. * Autofilter Column
  218. *
  219. * @var PHPExcel_Worksheet_AutoFilter_Column
  220. */
  221. private $_parent = NULL;
  222. /**
  223. * Autofilter Rule Type
  224. *
  225. * @var string
  226. */
  227. private $_ruleType = self::AUTOFILTER_RULETYPE_FILTER;
  228. /**
  229. * Autofilter Rule Value
  230. *
  231. * @var string
  232. */
  233. private $_value = '';
  234. /**
  235. * Autofilter Rule Operator
  236. *
  237. * @var string
  238. */
  239. private $_operator = self::AUTOFILTER_COLUMN_RULE_EQUAL;
  240. /**
  241. * DateTimeGrouping Group Value
  242. *
  243. * @var string
  244. */
  245. private $_grouping = '';
  246. /**
  247. * Create a new PHPExcel_Worksheet_AutoFilter_Column_Rule
  248. *
  249. * @param PHPExcel_Worksheet_AutoFilter_Column $pParent
  250. */
  251. public function __construct(PHPExcel_Worksheet_AutoFilter_Column $pParent = NULL)
  252. {
  253. $this->_parent = $pParent;
  254. }
  255. /**
  256. * Get AutoFilter Rule Type
  257. *
  258. * @return string
  259. */
  260. public function getRuleType() {
  261. return $this->_ruleType;
  262. }
  263. /**
  264. * Set AutoFilter Rule Type
  265. *
  266. * @param string $pRuleType
  267. * @throws PHPExcel_Exception
  268. * @return PHPExcel_Worksheet_AutoFilter_Column
  269. */
  270. public function setRuleType($pRuleType = self::AUTOFILTER_RULETYPE_FILTER) {
  271. if (!in_array($pRuleType,self::$_ruleTypes)) {
  272. throw new PHPExcel_Exception('Invalid rule type for column AutoFilter Rule.');
  273. }
  274. $this->_ruleType = $pRuleType;
  275. return $this;
  276. }
  277. /**
  278. * Get AutoFilter Rule Value
  279. *
  280. * @return string
  281. */
  282. public function getValue() {
  283. return $this->_value;
  284. }
  285. /**
  286. * Set AutoFilter Rule Value
  287. *
  288. * @param string|string[] $pValue
  289. * @throws PHPExcel_Exception
  290. * @return PHPExcel_Worksheet_AutoFilter_Column_Rule
  291. */
  292. public function setValue($pValue = '') {
  293. if (is_array($pValue)) {
  294. $grouping = -1;
  295. foreach($pValue as $key => $value) {
  296. // Validate array entries
  297. if (!in_array($key,self::$_dateTimeGroups)) {
  298. // Remove any invalid entries from the value array
  299. unset($pValue[$key]);
  300. } else {
  301. // Work out what the dateTime grouping will be
  302. $grouping = max($grouping,array_search($key,self::$_dateTimeGroups));
  303. }
  304. }
  305. if (count($pValue) == 0) {
  306. throw new PHPExcel_Exception('Invalid rule value for column AutoFilter Rule.');
  307. }
  308. // Set the dateTime grouping that we've anticipated
  309. $this->setGrouping(self::$_dateTimeGroups[$grouping]);
  310. }
  311. $this->_value = $pValue;
  312. return $this;
  313. }
  314. /**
  315. * Get AutoFilter Rule Operator
  316. *
  317. * @return string
  318. */
  319. public function getOperator() {
  320. return $this->_operator;
  321. }
  322. /**
  323. * Set AutoFilter Rule Operator
  324. *
  325. * @param string $pOperator
  326. * @throws PHPExcel_Exception
  327. * @return PHPExcel_Worksheet_AutoFilter_Column_Rule
  328. */
  329. public function setOperator($pOperator = self::AUTOFILTER_COLUMN_RULE_EQUAL) {
  330. if (empty($pOperator))
  331. $pOperator = self::AUTOFILTER_COLUMN_RULE_EQUAL;
  332. if ((!in_array($pOperator,self::$_operators)) &&
  333. (!in_array($pOperator,self::$_topTenValue))) {
  334. throw new PHPExcel_Exception('Invalid operator for column AutoFilter Rule.');
  335. }
  336. $this->_operator = $pOperator;
  337. return $this;
  338. }
  339. /**
  340. * Get AutoFilter Rule Grouping
  341. *
  342. * @return string
  343. */
  344. public function getGrouping() {
  345. return $this->_grouping;
  346. }
  347. /**
  348. * Set AutoFilter Rule Grouping
  349. *
  350. * @param string $pGrouping
  351. * @throws PHPExcel_Exception
  352. * @return PHPExcel_Worksheet_AutoFilter_Column_Rule
  353. */
  354. public function setGrouping($pGrouping = NULL) {
  355. if (($pGrouping !== NULL) &&
  356. (!in_array($pGrouping,self::$_dateTimeGroups)) &&
  357. (!in_array($pGrouping,self::$_dynamicTypes)) &&
  358. (!in_array($pGrouping,self::$_topTenType))) {
  359. throw new PHPExcel_Exception('Invalid rule type for column AutoFilter Rule.');
  360. }
  361. $this->_grouping = $pGrouping;
  362. return $this;
  363. }
  364. /**
  365. * Set AutoFilter Rule
  366. *
  367. * @param string $pOperator
  368. * @param string|string[] $pValue
  369. * @param string $pGrouping
  370. * @throws PHPExcel_Exception
  371. * @return PHPExcel_Worksheet_AutoFilter_Column_Rule
  372. */
  373. public function setRule($pOperator = self::AUTOFILTER_COLUMN_RULE_EQUAL, $pValue = '', $pGrouping = NULL) {
  374. $this->setOperator($pOperator);
  375. $this->setValue($pValue);
  376. // Only set grouping if it's been passed in as a user-supplied argument,
  377. // otherwise we're calculating it when we setValue() and don't want to overwrite that
  378. // If the user supplies an argumnet for grouping, then on their own head be it
  379. if ($pGrouping !== NULL)
  380. $this->setGrouping($pGrouping);
  381. return $this;
  382. }
  383. /**
  384. * Get this Rule's AutoFilter Column Parent
  385. *
  386. * @return PHPExcel_Worksheet_AutoFilter_Column
  387. */
  388. public function getParent() {
  389. return $this->_parent;
  390. }
  391. /**
  392. * Set this Rule's AutoFilter Column Parent
  393. *
  394. * @param PHPExcel_Worksheet_AutoFilter_Column
  395. * @return PHPExcel_Worksheet_AutoFilter_Column_Rule
  396. */
  397. public function setParent(PHPExcel_Worksheet_AutoFilter_Column $pParent = NULL) {
  398. $this->_parent = $pParent;
  399. return $this;
  400. }
  401. /**
  402. * Implement PHP __clone to create a deep clone, not just a shallow copy.
  403. */
  404. public function __clone() {
  405. $vars = get_object_vars($this);
  406. foreach ($vars as $key => $value) {
  407. if (is_object($value)) {
  408. if ($key == '_parent') {
  409. // Detach from autofilter column parent
  410. $this->$key = NULL;
  411. } else {
  412. $this->$key = clone $value;
  413. }
  414. } else {
  415. $this->$key = $value;
  416. }
  417. }
  418. }
  419. }