Conditional.php 6.1 KB

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