DataValidation.php 8.0 KB

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