DataValidation.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. <?php
  2. /**
  3. * PHPExcel_Cell_DataValidation
  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_Cell
  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. class PHPExcel_Cell_DataValidation
  28. {
  29. /* Data validation types */
  30. const TYPE_NONE = 'none';
  31. const TYPE_CUSTOM = 'custom';
  32. const TYPE_DATE = 'date';
  33. const TYPE_DECIMAL = 'decimal';
  34. const TYPE_LIST = 'list';
  35. const TYPE_TEXTLENGTH = 'textLength';
  36. const TYPE_TIME = 'time';
  37. const TYPE_WHOLE = 'whole';
  38. /* Data validation error styles */
  39. const STYLE_STOP = 'stop';
  40. const STYLE_WARNING = 'warning';
  41. const STYLE_INFORMATION = 'information';
  42. /* Data validation operators */
  43. const OPERATOR_BETWEEN = 'between';
  44. const OPERATOR_EQUAL = 'equal';
  45. const OPERATOR_GREATERTHAN = 'greaterThan';
  46. const OPERATOR_GREATERTHANOREQUAL = 'greaterThanOrEqual';
  47. const OPERATOR_LESSTHAN = 'lessThan';
  48. const OPERATOR_LESSTHANOREQUAL = 'lessThanOrEqual';
  49. const OPERATOR_NOTBETWEEN = 'notBetween';
  50. const OPERATOR_NOTEQUAL = 'notEqual';
  51. /**
  52. * Formula 1
  53. *
  54. * @var string
  55. */
  56. private $formula1;
  57. /**
  58. * Formula 2
  59. *
  60. * @var string
  61. */
  62. private $formula2;
  63. /**
  64. * Type
  65. *
  66. * @var string
  67. */
  68. private $type = PHPExcel_Cell_DataValidation::TYPE_NONE;
  69. /**
  70. * Error style
  71. *
  72. * @var string
  73. */
  74. private $errorStyle = PHPExcel_Cell_DataValidation::STYLE_STOP;
  75. /**
  76. * Operator
  77. *
  78. * @var string
  79. */
  80. private $operator;
  81. /**
  82. * Allow Blank
  83. *
  84. * @var boolean
  85. */
  86. private $allowBlank;
  87. /**
  88. * Show DropDown
  89. *
  90. * @var boolean
  91. */
  92. private $showDropDown;
  93. /**
  94. * Show InputMessage
  95. *
  96. * @var boolean
  97. */
  98. private $showInputMessage;
  99. /**
  100. * Show ErrorMessage
  101. *
  102. * @var boolean
  103. */
  104. private $showErrorMessage;
  105. /**
  106. * Error title
  107. *
  108. * @var string
  109. */
  110. private $errorTitle;
  111. /**
  112. * Error
  113. *
  114. * @var string
  115. */
  116. private $error;
  117. /**
  118. * Prompt title
  119. *
  120. * @var string
  121. */
  122. private $promptTitle;
  123. /**
  124. * Prompt
  125. *
  126. * @var string
  127. */
  128. private $prompt;
  129. /**
  130. * Create a new PHPExcel_Cell_DataValidation
  131. */
  132. public function __construct()
  133. {
  134. // Initialise member variables
  135. $this->formula1 = '';
  136. $this->formula2 = '';
  137. $this->type = PHPExcel_Cell_DataValidation::TYPE_NONE;
  138. $this->errorStyle = PHPExcel_Cell_DataValidation::STYLE_STOP;
  139. $this->operator = '';
  140. $this->allowBlank = false;
  141. $this->showDropDown = false;
  142. $this->showInputMessage = false;
  143. $this->showErrorMessage = false;
  144. $this->errorTitle = '';
  145. $this->error = '';
  146. $this->promptTitle = '';
  147. $this->prompt = '';
  148. }
  149. /**
  150. * Get Formula 1
  151. *
  152. * @return string
  153. */
  154. public function getFormula1()
  155. {
  156. return $this->formula1;
  157. }
  158. /**
  159. * Set Formula 1
  160. *
  161. * @param string $value
  162. * @return PHPExcel_Cell_DataValidation
  163. */
  164. public function setFormula1($value = '')
  165. {
  166. $this->formula1 = $value;
  167. return $this;
  168. }
  169. /**
  170. * Get Formula 2
  171. *
  172. * @return string
  173. */
  174. public function getFormula2()
  175. {
  176. return $this->formula2;
  177. }
  178. /**
  179. * Set Formula 2
  180. *
  181. * @param string $value
  182. * @return PHPExcel_Cell_DataValidation
  183. */
  184. public function setFormula2($value = '')
  185. {
  186. $this->formula2 = $value;
  187. return $this;
  188. }
  189. /**
  190. * Get Type
  191. *
  192. * @return string
  193. */
  194. public function getType()
  195. {
  196. return $this->type;
  197. }
  198. /**
  199. * Set Type
  200. *
  201. * @param string $value
  202. * @return PHPExcel_Cell_DataValidation
  203. */
  204. public function setType($value = PHPExcel_Cell_DataValidation::TYPE_NONE)
  205. {
  206. $this->type = $value;
  207. return $this;
  208. }
  209. /**
  210. * Get Error style
  211. *
  212. * @return string
  213. */
  214. public function getErrorStyle()
  215. {
  216. return $this->errorStyle;
  217. }
  218. /**
  219. * Set Error style
  220. *
  221. * @param string $value
  222. * @return PHPExcel_Cell_DataValidation
  223. */
  224. public function setErrorStyle($value = PHPExcel_Cell_DataValidation::STYLE_STOP)
  225. {
  226. $this->errorStyle = $value;
  227. return $this;
  228. }
  229. /**
  230. * Get Operator
  231. *
  232. * @return string
  233. */
  234. public function getOperator()
  235. {
  236. return $this->operator;
  237. }
  238. /**
  239. * Set Operator
  240. *
  241. * @param string $value
  242. * @return PHPExcel_Cell_DataValidation
  243. */
  244. public function setOperator($value = '')
  245. {
  246. $this->operator = $value;
  247. return $this;
  248. }
  249. /**
  250. * Get Allow Blank
  251. *
  252. * @return boolean
  253. */
  254. public function getAllowBlank()
  255. {
  256. return $this->allowBlank;
  257. }
  258. /**
  259. * Set Allow Blank
  260. *
  261. * @param boolean $value
  262. * @return PHPExcel_Cell_DataValidation
  263. */
  264. public function setAllowBlank($value = false)
  265. {
  266. $this->allowBlank = $value;
  267. return $this;
  268. }
  269. /**
  270. * Get Show DropDown
  271. *
  272. * @return boolean
  273. */
  274. public function getShowDropDown()
  275. {
  276. return $this->showDropDown;
  277. }
  278. /**
  279. * Set Show DropDown
  280. *
  281. * @param boolean $value
  282. * @return PHPExcel_Cell_DataValidation
  283. */
  284. public function setShowDropDown($value = false)
  285. {
  286. $this->showDropDown = $value;
  287. return $this;
  288. }
  289. /**
  290. * Get Show InputMessage
  291. *
  292. * @return boolean
  293. */
  294. public function getShowInputMessage()
  295. {
  296. return $this->showInputMessage;
  297. }
  298. /**
  299. * Set Show InputMessage
  300. *
  301. * @param boolean $value
  302. * @return PHPExcel_Cell_DataValidation
  303. */
  304. public function setShowInputMessage($value = false)
  305. {
  306. $this->showInputMessage = $value;
  307. return $this;
  308. }
  309. /**
  310. * Get Show ErrorMessage
  311. *
  312. * @return boolean
  313. */
  314. public function getShowErrorMessage()
  315. {
  316. return $this->showErrorMessage;
  317. }
  318. /**
  319. * Set Show ErrorMessage
  320. *
  321. * @param boolean $value
  322. * @return PHPExcel_Cell_DataValidation
  323. */
  324. public function setShowErrorMessage($value = false)
  325. {
  326. $this->showErrorMessage = $value;
  327. return $this;
  328. }
  329. /**
  330. * Get Error title
  331. *
  332. * @return string
  333. */
  334. public function getErrorTitle()
  335. {
  336. return $this->errorTitle;
  337. }
  338. /**
  339. * Set Error title
  340. *
  341. * @param string $value
  342. * @return PHPExcel_Cell_DataValidation
  343. */
  344. public function setErrorTitle($value = '')
  345. {
  346. $this->errorTitle = $value;
  347. return $this;
  348. }
  349. /**
  350. * Get Error
  351. *
  352. * @return string
  353. */
  354. public function getError()
  355. {
  356. return $this->error;
  357. }
  358. /**
  359. * Set Error
  360. *
  361. * @param string $value
  362. * @return PHPExcel_Cell_DataValidation
  363. */
  364. public function setError($value = '')
  365. {
  366. $this->error = $value;
  367. return $this;
  368. }
  369. /**
  370. * Get Prompt title
  371. *
  372. * @return string
  373. */
  374. public function getPromptTitle()
  375. {
  376. return $this->promptTitle;
  377. }
  378. /**
  379. * Set Prompt title
  380. *
  381. * @param string $value
  382. * @return PHPExcel_Cell_DataValidation
  383. */
  384. public function setPromptTitle($value = '')
  385. {
  386. $this->promptTitle = $value;
  387. return $this;
  388. }
  389. /**
  390. * Get Prompt
  391. *
  392. * @return string
  393. */
  394. public function getPrompt()
  395. {
  396. return $this->prompt;
  397. }
  398. /**
  399. * Set Prompt
  400. *
  401. * @param string $value
  402. * @return PHPExcel_Cell_DataValidation
  403. */
  404. public function setPrompt($value = '')
  405. {
  406. $this->prompt = $value;
  407. return $this;
  408. }
  409. /**
  410. * Get hash code
  411. *
  412. * @return string Hash code
  413. */
  414. public function getHashCode()
  415. {
  416. return md5(
  417. $this->formula1 .
  418. $this->formula2 .
  419. $this->type = PHPExcel_Cell_DataValidation::TYPE_NONE .
  420. $this->errorStyle = PHPExcel_Cell_DataValidation::STYLE_STOP .
  421. $this->operator .
  422. ($this->allowBlank ? 't' : 'f') .
  423. ($this->showDropDown ? 't' : 'f') .
  424. ($this->showInputMessage ? 't' : 'f') .
  425. ($this->showErrorMessage ? 't' : 'f') .
  426. $this->errorTitle .
  427. $this->error .
  428. $this->promptTitle .
  429. $this->prompt .
  430. __CLASS__
  431. );
  432. }
  433. /**
  434. * Implement PHP __clone to create a deep clone, not just a shallow copy.
  435. */
  436. public function __clone()
  437. {
  438. $vars = get_object_vars($this);
  439. foreach ($vars as $key => $value) {
  440. if (is_object($value)) {
  441. $this->$key = clone $value;
  442. } else {
  443. $this->$key = $value;
  444. }
  445. }
  446. }
  447. }