Conditional.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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_Style
  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 1.8.0, 2014-03-02
  26. */
  27. /**
  28. * PHPExcel_Style_Conditional
  29. *
  30. * @category PHPExcel
  31. * @package PHPExcel_Style
  32. * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
  33. */
  34. class PHPExcel_Style_Conditional implements PHPExcel_IComparable
  35. {
  36. /* Condition types */
  37. const CONDITION_NONE = 'none';
  38. const CONDITION_CELLIS = 'cellIs';
  39. const CONDITION_CONTAINSTEXT = 'containsText';
  40. const CONDITION_EXPRESSION = 'expression';
  41. /* Operator types */
  42. const OPERATOR_NONE = '';
  43. const OPERATOR_BEGINSWITH = 'beginsWith';
  44. const OPERATOR_ENDSWITH = 'endsWith';
  45. const OPERATOR_EQUAL = 'equal';
  46. const OPERATOR_GREATERTHAN = 'greaterThan';
  47. const OPERATOR_GREATERTHANOREQUAL = 'greaterThanOrEqual';
  48. const OPERATOR_LESSTHAN = 'lessThan';
  49. const OPERATOR_LESSTHANOREQUAL = 'lessThanOrEqual';
  50. const OPERATOR_NOTEQUAL = 'notEqual';
  51. const OPERATOR_CONTAINSTEXT = 'containsText';
  52. const OPERATOR_NOTCONTAINS = 'notContains';
  53. const OPERATOR_BETWEEN = 'between';
  54. /**
  55. * Condition type
  56. *
  57. * @var int
  58. */
  59. private $_conditionType;
  60. /**
  61. * Operator type
  62. *
  63. * @var int
  64. */
  65. private $_operatorType;
  66. /**
  67. * Text
  68. *
  69. * @var string
  70. */
  71. private $_text;
  72. /**
  73. * Condition
  74. *
  75. * @var string[]
  76. */
  77. private $_condition = array();
  78. /**
  79. * Style
  80. *
  81. * @var PHPExcel_Style
  82. */
  83. private $_style;
  84. /**
  85. * Create a new PHPExcel_Style_Conditional
  86. */
  87. public function __construct()
  88. {
  89. // Initialise values
  90. $this->_conditionType = PHPExcel_Style_Conditional::CONDITION_NONE;
  91. $this->_operatorType = PHPExcel_Style_Conditional::OPERATOR_NONE;
  92. $this->_text = null;
  93. $this->_condition = array();
  94. $this->_style = new PHPExcel_Style(FALSE, TRUE);
  95. }
  96. /**
  97. * Get Condition type
  98. *
  99. * @return string
  100. */
  101. public function getConditionType() {
  102. return $this->_conditionType;
  103. }
  104. /**
  105. * Set Condition type
  106. *
  107. * @param string $pValue PHPExcel_Style_Conditional condition type
  108. * @return PHPExcel_Style_Conditional
  109. */
  110. public function setConditionType($pValue = PHPExcel_Style_Conditional::CONDITION_NONE) {
  111. $this->_conditionType = $pValue;
  112. return $this;
  113. }
  114. /**
  115. * Get Operator type
  116. *
  117. * @return string
  118. */
  119. public function getOperatorType() {
  120. return $this->_operatorType;
  121. }
  122. /**
  123. * Set Operator type
  124. *
  125. * @param string $pValue PHPExcel_Style_Conditional operator type
  126. * @return PHPExcel_Style_Conditional
  127. */
  128. public function setOperatorType($pValue = PHPExcel_Style_Conditional::OPERATOR_NONE) {
  129. $this->_operatorType = $pValue;
  130. return $this;
  131. }
  132. /**
  133. * Get text
  134. *
  135. * @return string
  136. */
  137. public function getText() {
  138. return $this->_text;
  139. }
  140. /**
  141. * Set text
  142. *
  143. * @param string $value
  144. * @return PHPExcel_Style_Conditional
  145. */
  146. public function setText($value = null) {
  147. $this->_text = $value;
  148. return $this;
  149. }
  150. /**
  151. * Get Condition
  152. *
  153. * @deprecated Deprecated, use getConditions instead
  154. * @return string
  155. */
  156. public function getCondition() {
  157. if (isset($this->_condition[0])) {
  158. return $this->_condition[0];
  159. }
  160. return '';
  161. }
  162. /**
  163. * Set Condition
  164. *
  165. * @deprecated Deprecated, use setConditions instead
  166. * @param string $pValue Condition
  167. * @return PHPExcel_Style_Conditional
  168. */
  169. public function setCondition($pValue = '') {
  170. if (!is_array($pValue))
  171. $pValue = array($pValue);
  172. return $this->setConditions($pValue);
  173. }
  174. /**
  175. * Get Conditions
  176. *
  177. * @return string[]
  178. */
  179. public function getConditions() {
  180. return $this->_condition;
  181. }
  182. /**
  183. * Set Conditions
  184. *
  185. * @param string[] $pValue Condition
  186. * @return PHPExcel_Style_Conditional
  187. */
  188. public function setConditions($pValue) {
  189. if (!is_array($pValue))
  190. $pValue = array($pValue);
  191. $this->_condition = $pValue;
  192. return $this;
  193. }
  194. /**
  195. * Add Condition
  196. *
  197. * @param string $pValue Condition
  198. * @return PHPExcel_Style_Conditional
  199. */
  200. public function addCondition($pValue = '') {
  201. $this->_condition[] = $pValue;
  202. return $this;
  203. }
  204. /**
  205. * Get Style
  206. *
  207. * @return PHPExcel_Style
  208. */
  209. public function getStyle() {
  210. return $this->_style;
  211. }
  212. /**
  213. * Set Style
  214. *
  215. * @param PHPExcel_Style $pValue
  216. * @throws PHPExcel_Exception
  217. * @return PHPExcel_Style_Conditional
  218. */
  219. public function setStyle(PHPExcel_Style $pValue = null) {
  220. $this->_style = $pValue;
  221. return $this;
  222. }
  223. /**
  224. * Get hash code
  225. *
  226. * @return string Hash code
  227. */
  228. public function getHashCode() {
  229. return md5(
  230. $this->_conditionType
  231. . $this->_operatorType
  232. . implode(';', $this->_condition)
  233. . $this->_style->getHashCode()
  234. . __CLASS__
  235. );
  236. }
  237. /**
  238. * Implement PHP __clone to create a deep clone, not just a shallow copy.
  239. */
  240. public function __clone() {
  241. $vars = get_object_vars($this);
  242. foreach ($vars as $key => $value) {
  243. if (is_object($value)) {
  244. $this->$key = clone $value;
  245. } else {
  246. $this->$key = $value;
  247. }
  248. }
  249. }
  250. }