PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/branches/v1.7.2/Classes/PHPExcel/Cell/DataValidation.php

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