PageRenderTime 44ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

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

#
PHP | 500 lines | 167 code | 51 blank | 282 comment | 2 complexity | 4d175974cb3abf358d18b2e4c1a660f8 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 - 2008 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 - 2008 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 - 2008 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. */
  180. public function setFormula1($value = '') {
  181. $this->_formula1 = $value;
  182. }
  183. /**
  184. * Get Formula 2
  185. *
  186. * @return string
  187. */
  188. public function getFormula2() {
  189. return $this->_formula2;
  190. }
  191. /**
  192. * Set Formula 2
  193. *
  194. * @param string $value
  195. */
  196. public function setFormula2($value = '') {
  197. $this->_formula2 = $value;
  198. }
  199. /**
  200. * Get Type
  201. *
  202. * @return string
  203. */
  204. public function getType() {
  205. return $this->_type;
  206. }
  207. /**
  208. * Set Type
  209. *
  210. * @param string $value
  211. */
  212. public function setType($value = PHPExcel_Cell_DataValidation::TYPE_NONE) {
  213. $this->_type = $value;
  214. }
  215. /**
  216. * Get Error style
  217. *
  218. * @return string
  219. */
  220. public function getErrorStyle() {
  221. return $this->_errorStyle;
  222. }
  223. /**
  224. * Set Error style
  225. *
  226. * @param string $value
  227. */
  228. public function setErrorStyle($value = PHPExcel_Cell_DataValidation::STYLE_STOP) {
  229. $this->_errorStyle = $value;
  230. }
  231. /**
  232. * Get Operator
  233. *
  234. * @return string
  235. */
  236. public function getOperator() {
  237. return $this->_operator;
  238. }
  239. /**
  240. * Set Operator
  241. *
  242. * @param string $value
  243. */
  244. public function setOperator($value = '') {
  245. $this->_operator = $value;
  246. }
  247. /**
  248. * Get Allow Blank
  249. *
  250. * @return boolean
  251. */
  252. public function getAllowBlank() {
  253. return $this->_allowBlank;
  254. }
  255. /**
  256. * Set Allow Blank
  257. *
  258. * @param boolean $value
  259. */
  260. public function setAllowBlank($value = false) {
  261. $this->_allowBlank = $value;
  262. }
  263. /**
  264. * Get Show DropDown
  265. *
  266. * @return boolean
  267. */
  268. public function getShowDropDown() {
  269. return $this->_showDropDown;
  270. }
  271. /**
  272. * Set Show DropDown
  273. *
  274. * @param boolean $value
  275. */
  276. public function setShowDropDown($value = false) {
  277. $this->_showDropDown = $value;
  278. }
  279. /**
  280. * Get Show InputMessage
  281. *
  282. * @return boolean
  283. */
  284. public function getShowInputMessage() {
  285. return $this->_showInputMessage;
  286. }
  287. /**
  288. * Set Show InputMessage
  289. *
  290. * @param boolean $value
  291. */
  292. public function setShowInputMessage($value = false) {
  293. $this->_showInputMessage = $value;
  294. }
  295. /**
  296. * Get Show ErrorMessage
  297. *
  298. * @return boolean
  299. */
  300. public function getShowErrorMessage() {
  301. return $this->_showErrorMessage;
  302. }
  303. /**
  304. * Set Show ErrorMessage
  305. *
  306. * @param boolean $value
  307. */
  308. public function setShowErrorMessage($value = false) {
  309. $this->_showErrorMessage = $value;
  310. }
  311. /**
  312. * Get Error title
  313. *
  314. * @return string
  315. */
  316. public function getErrorTitle() {
  317. return $this->_errorTitle;
  318. }
  319. /**
  320. * Set Error title
  321. *
  322. * @param string $value
  323. */
  324. public function setErrorTitle($value = '') {
  325. $this->_errorTitle = $value;
  326. }
  327. /**
  328. * Get Error
  329. *
  330. * @return string
  331. */
  332. public function getError() {
  333. return $this->_error;
  334. }
  335. /**
  336. * Set Error
  337. *
  338. * @param string $value
  339. */
  340. public function setError($value = '') {
  341. $this->_error = $value;
  342. }
  343. /**
  344. * Get Prompt title
  345. *
  346. * @return string
  347. */
  348. public function getPromptTitle() {
  349. return $this->_promptTitle;
  350. }
  351. /**
  352. * Set Prompt title
  353. *
  354. * @param string $value
  355. */
  356. public function setPromptTitle($value = '') {
  357. $this->_promptTitle = $value;
  358. }
  359. /**
  360. * Get Prompt
  361. *
  362. * @return string
  363. */
  364. public function getPrompt() {
  365. return $this->_prompt;
  366. }
  367. /**
  368. * Set Prompt
  369. *
  370. * @param string $value
  371. */
  372. public function setPrompt($value = '') {
  373. $this->_prompt = $value;
  374. }
  375. /**
  376. * Get parent
  377. *
  378. * @return PHPExcel_Cell
  379. */
  380. public function getParent() {
  381. return $this->_parent;
  382. }
  383. /**
  384. * Set Parent
  385. *
  386. * @param PHPExcel_Cell $value
  387. */
  388. public function setParent($value = null) {
  389. $this->_parent = $value;
  390. }
  391. /**
  392. * Get hash code
  393. *
  394. * @return string Hash code
  395. */
  396. public function getHashCode() {
  397. return md5(
  398. $this->_formula1
  399. . $this->_formula2
  400. . $this->_type = PHPExcel_Cell_DataValidation::TYPE_NONE
  401. . $this->_errorStyle = PHPExcel_Cell_DataValidation::STYLE_STOP
  402. . $this->_operator
  403. . ($this->_allowBlank ? 't' : 'f')
  404. . ($this->_showDropDown ? 't' : 'f')
  405. . ($this->_showInputMessage ? 't' : 'f')
  406. . ($this->_showErrorMessage ? 't' : 'f')
  407. . $this->_errorTitle
  408. . $this->_error
  409. . $this->_promptTitle
  410. . $this->_prompt
  411. . $this->_parent->getCoordinate()
  412. . __CLASS__
  413. );
  414. }
  415. /**
  416. * Implement PHP __clone to create a deep clone, not just a shallow copy.
  417. */
  418. public function __clone() {
  419. $vars = get_object_vars($this);
  420. foreach ($vars as $key => $value) {
  421. if (is_object($value)) {
  422. $this->$key = clone $value;
  423. } else {
  424. $this->$key = $value;
  425. }
  426. }
  427. }
  428. /*
  429. <complexType name="CT_DataValidation">
  430. <sequence>
  431. <element name="formula1" type="ST_Formula" minOccurs="0" maxOccurs="1"/>
  432. <element name="formula2" type="ST_Formula" minOccurs="0" maxOccurs="1"/>
  433. </sequence>
  434. <attribute name="type" type="ST_DataValidationType" use="optional" default="none"/>
  435. <attribute name="errorStyle" type="ST_DataValidationErrorStyle" use="optional" default="stop"/>
  436. <attribute name="imeMode" type="ST_DataValidationImeMode" use="optional" default="noControl"/>
  437. <attribute name="operator" type="ST_DataValidationOperator" use="optional" default="between"/>
  438. <attribute name="allowBlank" type="xsd:boolean" use="optional" default="false"/>
  439. <attribute name="showDropDown" type="xsd:boolean" use="optional" default="false"/>
  440. <attribute name="showInputMessage" type="xsd:boolean" use="optional" default="false"/>
  441. <attribute name="showErrorMessage" type="xsd:boolean" use="optional" default="false"/>
  442. <attribute name="errorTitle" type="ST_Xstring" use="optional"/>
  443. <attribute name="error" type="ST_Xstring" use="optional"/>
  444. <attribute name="promptTitle" type="ST_Xstring" use="optional"/>
  445. <attribute name="prompt" type="ST_Xstring" use="optional"/>
  446. <attribute name="sqref" type="ST_Sqref" use="required"/>
  447. </complexType>
  448. */
  449. }