For God so loved the world, that He gave His only begotten Son, that all who believe in Him should not perish but have everlasting life
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

293 lines
6.8 KiB

  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2015 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 - 2015 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_Style_Conditional
  29. *
  30. * @category PHPExcel
  31. * @package PHPExcel_Style
  32. * @copyright Copyright (c) 2006 - 2015 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. {
  103. return $this->conditionType;
  104. }
  105. /**
  106. * Set Condition type
  107. *
  108. * @param string $pValue PHPExcel_Style_Conditional condition type
  109. * @return PHPExcel_Style_Conditional
  110. */
  111. public function setConditionType($pValue = PHPExcel_Style_Conditional::CONDITION_NONE)
  112. {
  113. $this->conditionType = $pValue;
  114. return $this;
  115. }
  116. /**
  117. * Get Operator type
  118. *
  119. * @return string
  120. */
  121. public function getOperatorType()
  122. {
  123. return $this->operatorType;
  124. }
  125. /**
  126. * Set Operator type
  127. *
  128. * @param string $pValue PHPExcel_Style_Conditional operator type
  129. * @return PHPExcel_Style_Conditional
  130. */
  131. public function setOperatorType($pValue = PHPExcel_Style_Conditional::OPERATOR_NONE)
  132. {
  133. $this->operatorType = $pValue;
  134. return $this;
  135. }
  136. /**
  137. * Get text
  138. *
  139. * @return string
  140. */
  141. public function getText()
  142. {
  143. return $this->text;
  144. }
  145. /**
  146. * Set text
  147. *
  148. * @param string $value
  149. * @return PHPExcel_Style_Conditional
  150. */
  151. public function setText($value = null)
  152. {
  153. $this->text = $value;
  154. return $this;
  155. }
  156. /**
  157. * Get Condition
  158. *
  159. * @deprecated Deprecated, use getConditions instead
  160. * @return string
  161. */
  162. public function getCondition()
  163. {
  164. if (isset($this->condition[0])) {
  165. return $this->condition[0];
  166. }
  167. return '';
  168. }
  169. /**
  170. * Set Condition
  171. *
  172. * @deprecated Deprecated, use setConditions instead
  173. * @param string $pValue Condition
  174. * @return PHPExcel_Style_Conditional
  175. */
  176. public function setCondition($pValue = '')
  177. {
  178. if (!is_array($pValue)) {
  179. $pValue = array($pValue);
  180. }
  181. return $this->setConditions($pValue);
  182. }
  183. /**
  184. * Get Conditions
  185. *
  186. * @return string[]
  187. */
  188. public function getConditions()
  189. {
  190. return $this->condition;
  191. }
  192. /**
  193. * Set Conditions
  194. *
  195. * @param string[] $pValue Condition
  196. * @return PHPExcel_Style_Conditional
  197. */
  198. public function setConditions($pValue)
  199. {
  200. if (!is_array($pValue)) {
  201. $pValue = array($pValue);
  202. }
  203. $this->condition = $pValue;
  204. return $this;
  205. }
  206. /**
  207. * Add Condition
  208. *
  209. * @param string $pValue Condition
  210. * @return PHPExcel_Style_Conditional
  211. */
  212. public function addCondition($pValue = '')
  213. {
  214. $this->condition[] = $pValue;
  215. return $this;
  216. }
  217. /**
  218. * Get Style
  219. *
  220. * @return PHPExcel_Style
  221. */
  222. public function getStyle()
  223. {
  224. return $this->style;
  225. }
  226. /**
  227. * Set Style
  228. *
  229. * @param PHPExcel_Style $pValue
  230. * @throws PHPExcel_Exception
  231. * @return PHPExcel_Style_Conditional
  232. */
  233. public function setStyle(PHPExcel_Style $pValue = null)
  234. {
  235. $this->style = $pValue;
  236. return $this;
  237. }
  238. /**
  239. * Get hash code
  240. *
  241. * @return string Hash code
  242. */
  243. public function getHashCode()
  244. {
  245. return md5(
  246. $this->conditionType .
  247. $this->operatorType .
  248. implode(';', $this->condition) .
  249. $this->style->getHashCode() .
  250. __CLASS__
  251. );
  252. }
  253. /**
  254. * Implement PHP __clone to create a deep clone, not just a shallow copy.
  255. */
  256. public function __clone()
  257. {
  258. $vars = get_object_vars($this);
  259. foreach ($vars as $key => $value) {
  260. if (is_object($value)) {
  261. $this->$key = clone $value;
  262. } else {
  263. $this->$key = $value;
  264. }
  265. }
  266. }
  267. }