PageRenderTime 53ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/phpoffice/phpexcel/Classes/PHPExcel/Worksheet/AutoFilter/Column.php

https://gitlab.com/ehfahad/Library_Management_System
PHP | 394 lines | 138 code | 51 blank | 205 comment | 14 complexity | 97619d12625a9ca2a0f057d8979fddc5 MD5 | raw file
  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
  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
  35. {
  36. const AUTOFILTER_FILTERTYPE_FILTER = 'filters';
  37. const AUTOFILTER_FILTERTYPE_CUSTOMFILTER = 'customFilters';
  38. // Supports no more than 2 rules, with an And/Or join criteria
  39. // if more than 1 rule is defined
  40. const AUTOFILTER_FILTERTYPE_DYNAMICFILTER = 'dynamicFilter';
  41. // Even though the filter rule is constant, the filtered data can vary
  42. // e.g. filtered by date = TODAY
  43. const AUTOFILTER_FILTERTYPE_TOPTENFILTER = 'top10';
  44. /**
  45. * Types of autofilter rules
  46. *
  47. * @var string[]
  48. */
  49. private static $_filterTypes = array(
  50. // Currently we're not handling
  51. // colorFilter
  52. // extLst
  53. // iconFilter
  54. self::AUTOFILTER_FILTERTYPE_FILTER,
  55. self::AUTOFILTER_FILTERTYPE_CUSTOMFILTER,
  56. self::AUTOFILTER_FILTERTYPE_DYNAMICFILTER,
  57. self::AUTOFILTER_FILTERTYPE_TOPTENFILTER,
  58. );
  59. /* Multiple Rule Connections */
  60. const AUTOFILTER_COLUMN_JOIN_AND = 'and';
  61. const AUTOFILTER_COLUMN_JOIN_OR = 'or';
  62. /**
  63. * Join options for autofilter rules
  64. *
  65. * @var string[]
  66. */
  67. private static $_ruleJoins = array(
  68. self::AUTOFILTER_COLUMN_JOIN_AND,
  69. self::AUTOFILTER_COLUMN_JOIN_OR,
  70. );
  71. /**
  72. * Autofilter
  73. *
  74. * @var PHPExcel_Worksheet_AutoFilter
  75. */
  76. private $_parent = NULL;
  77. /**
  78. * Autofilter Column Index
  79. *
  80. * @var string
  81. */
  82. private $_columnIndex = '';
  83. /**
  84. * Autofilter Column Filter Type
  85. *
  86. * @var string
  87. */
  88. private $_filterType = self::AUTOFILTER_FILTERTYPE_FILTER;
  89. /**
  90. * Autofilter Multiple Rules And/Or
  91. *
  92. * @var string
  93. */
  94. private $_join = self::AUTOFILTER_COLUMN_JOIN_OR;
  95. /**
  96. * Autofilter Column Rules
  97. *
  98. * @var array of PHPExcel_Worksheet_AutoFilter_Column_Rule
  99. */
  100. private $_ruleset = array();
  101. /**
  102. * Autofilter Column Dynamic Attributes
  103. *
  104. * @var array of mixed
  105. */
  106. private $_attributes = array();
  107. /**
  108. * Create a new PHPExcel_Worksheet_AutoFilter_Column
  109. *
  110. * @param string $pColumn Column (e.g. A)
  111. * @param PHPExcel_Worksheet_AutoFilter $pParent Autofilter for this column
  112. */
  113. public function __construct($pColumn, PHPExcel_Worksheet_AutoFilter $pParent = NULL)
  114. {
  115. $this->_columnIndex = $pColumn;
  116. $this->_parent = $pParent;
  117. }
  118. /**
  119. * Get AutoFilter Column Index
  120. *
  121. * @return string
  122. */
  123. public function getColumnIndex() {
  124. return $this->_columnIndex;
  125. }
  126. /**
  127. * Set AutoFilter Column Index
  128. *
  129. * @param string $pColumn Column (e.g. A)
  130. * @throws PHPExcel_Exception
  131. * @return PHPExcel_Worksheet_AutoFilter_Column
  132. */
  133. public function setColumnIndex($pColumn) {
  134. // Uppercase coordinate
  135. $pColumn = strtoupper($pColumn);
  136. if ($this->_parent !== NULL) {
  137. $this->_parent->testColumnInRange($pColumn);
  138. }
  139. $this->_columnIndex = $pColumn;
  140. return $this;
  141. }
  142. /**
  143. * Get this Column's AutoFilter Parent
  144. *
  145. * @return PHPExcel_Worksheet_AutoFilter
  146. */
  147. public function getParent() {
  148. return $this->_parent;
  149. }
  150. /**
  151. * Set this Column's AutoFilter Parent
  152. *
  153. * @param PHPExcel_Worksheet_AutoFilter
  154. * @return PHPExcel_Worksheet_AutoFilter_Column
  155. */
  156. public function setParent(PHPExcel_Worksheet_AutoFilter $pParent = NULL) {
  157. $this->_parent = $pParent;
  158. return $this;
  159. }
  160. /**
  161. * Get AutoFilter Type
  162. *
  163. * @return string
  164. */
  165. public function getFilterType() {
  166. return $this->_filterType;
  167. }
  168. /**
  169. * Set AutoFilter Type
  170. *
  171. * @param string $pFilterType
  172. * @throws PHPExcel_Exception
  173. * @return PHPExcel_Worksheet_AutoFilter_Column
  174. */
  175. public function setFilterType($pFilterType = self::AUTOFILTER_FILTERTYPE_FILTER) {
  176. if (!in_array($pFilterType,self::$_filterTypes)) {
  177. throw new PHPExcel_Exception('Invalid filter type for column AutoFilter.');
  178. }
  179. $this->_filterType = $pFilterType;
  180. return $this;
  181. }
  182. /**
  183. * Get AutoFilter Multiple Rules And/Or Join
  184. *
  185. * @return string
  186. */
  187. public function getJoin() {
  188. return $this->_join;
  189. }
  190. /**
  191. * Set AutoFilter Multiple Rules And/Or
  192. *
  193. * @param string $pJoin And/Or
  194. * @throws PHPExcel_Exception
  195. * @return PHPExcel_Worksheet_AutoFilter_Column
  196. */
  197. public function setJoin($pJoin = self::AUTOFILTER_COLUMN_JOIN_OR) {
  198. // Lowercase And/Or
  199. $pJoin = strtolower($pJoin);
  200. if (!in_array($pJoin,self::$_ruleJoins)) {
  201. throw new PHPExcel_Exception('Invalid rule connection for column AutoFilter.');
  202. }
  203. $this->_join = $pJoin;
  204. return $this;
  205. }
  206. /**
  207. * Set AutoFilter Attributes
  208. *
  209. * @param string[] $pAttributes
  210. * @throws PHPExcel_Exception
  211. * @return PHPExcel_Worksheet_AutoFilter_Column
  212. */
  213. public function setAttributes($pAttributes = array()) {
  214. $this->_attributes = $pAttributes;
  215. return $this;
  216. }
  217. /**
  218. * Set An AutoFilter Attribute
  219. *
  220. * @param string $pName Attribute Name
  221. * @param string $pValue Attribute Value
  222. * @throws PHPExcel_Exception
  223. * @return PHPExcel_Worksheet_AutoFilter_Column
  224. */
  225. public function setAttribute($pName, $pValue) {
  226. $this->_attributes[$pName] = $pValue;
  227. return $this;
  228. }
  229. /**
  230. * Get AutoFilter Column Attributes
  231. *
  232. * @return string
  233. */
  234. public function getAttributes() {
  235. return $this->_attributes;
  236. }
  237. /**
  238. * Get specific AutoFilter Column Attribute
  239. *
  240. * @param string $pName Attribute Name
  241. * @return string
  242. */
  243. public function getAttribute($pName) {
  244. if (isset($this->_attributes[$pName]))
  245. return $this->_attributes[$pName];
  246. return NULL;
  247. }
  248. /**
  249. * Get all AutoFilter Column Rules
  250. *
  251. * @throws PHPExcel_Exception
  252. * @return array of PHPExcel_Worksheet_AutoFilter_Column_Rule
  253. */
  254. public function getRules() {
  255. return $this->_ruleset;
  256. }
  257. /**
  258. * Get a specified AutoFilter Column Rule
  259. *
  260. * @param integer $pIndex Rule index in the ruleset array
  261. * @return PHPExcel_Worksheet_AutoFilter_Column_Rule
  262. */
  263. public function getRule($pIndex) {
  264. if (!isset($this->_ruleset[$pIndex])) {
  265. $this->_ruleset[$pIndex] = new PHPExcel_Worksheet_AutoFilter_Column_Rule($this);
  266. }
  267. return $this->_ruleset[$pIndex];
  268. }
  269. /**
  270. * Create a new AutoFilter Column Rule in the ruleset
  271. *
  272. * @return PHPExcel_Worksheet_AutoFilter_Column_Rule
  273. */
  274. public function createRule() {
  275. $this->_ruleset[] = new PHPExcel_Worksheet_AutoFilter_Column_Rule($this);
  276. return end($this->_ruleset);
  277. }
  278. /**
  279. * Add a new AutoFilter Column Rule to the ruleset
  280. *
  281. * @param PHPExcel_Worksheet_AutoFilter_Column_Rule $pRule
  282. * @param boolean $returnRule Flag indicating whether the rule object or the column object should be returned
  283. * @return PHPExcel_Worksheet_AutoFilter_Column|PHPExcel_Worksheet_AutoFilter_Column_Rule
  284. */
  285. public function addRule(PHPExcel_Worksheet_AutoFilter_Column_Rule $pRule, $returnRule=TRUE) {
  286. $pRule->setParent($this);
  287. $this->_ruleset[] = $pRule;
  288. return ($returnRule) ? $pRule : $this;
  289. }
  290. /**
  291. * Delete a specified AutoFilter Column Rule
  292. * If the number of rules is reduced to 1, then we reset And/Or logic to Or
  293. *
  294. * @param integer $pIndex Rule index in the ruleset array
  295. * @return PHPExcel_Worksheet_AutoFilter_Column
  296. */
  297. public function deleteRule($pIndex) {
  298. if (isset($this->_ruleset[$pIndex])) {
  299. unset($this->_ruleset[$pIndex]);
  300. // If we've just deleted down to a single rule, then reset And/Or joining to Or
  301. if (count($this->_ruleset) <= 1) {
  302. $this->setJoin(self::AUTOFILTER_COLUMN_JOIN_OR);
  303. }
  304. }
  305. return $this;
  306. }
  307. /**
  308. * Delete all AutoFilter Column Rules
  309. *
  310. * @return PHPExcel_Worksheet_AutoFilter_Column
  311. */
  312. public function clearRules() {
  313. $this->_ruleset = array();
  314. $this->setJoin(self::AUTOFILTER_COLUMN_JOIN_OR);
  315. return $this;
  316. }
  317. /**
  318. * Implement PHP __clone to create a deep clone, not just a shallow copy.
  319. */
  320. public function __clone() {
  321. $vars = get_object_vars($this);
  322. foreach ($vars as $key => $value) {
  323. if (is_object($value)) {
  324. if ($key == '_parent') {
  325. // Detach from autofilter parent
  326. $this->$key = NULL;
  327. } else {
  328. $this->$key = clone $value;
  329. }
  330. } elseif ((is_array($value)) && ($key == '_ruleset')) {
  331. // The columns array of PHPExcel_Worksheet_AutoFilter objects
  332. $this->$key = array();
  333. foreach ($value as $k => $v) {
  334. $this->$key[$k] = clone $v;
  335. // attach the new cloned Rule to this new cloned Autofilter Cloned object
  336. $this->$key[$k]->setParent($this);
  337. }
  338. } else {
  339. $this->$key = $value;
  340. }
  341. }
  342. }
  343. }