NumberSpinner.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Dojo
  17. * @subpackage Form_Element
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /** Zend_Dojo_Form_Element_ValidationTextBox */
  22. require_once 'Zend/Dojo/Form/Element/ValidationTextBox.php';
  23. /**
  24. * NumberSpinner dijit
  25. *
  26. * @uses Zend_Dojo_Form_Element_ValidationTextBox
  27. * @package Zend_Dojo
  28. * @subpackage Form_Element
  29. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. * @version $Id$
  32. */
  33. class Zend_Dojo_Form_Element_NumberSpinner extends Zend_Dojo_Form_Element_ValidationTextBox
  34. {
  35. /**
  36. * Use NumberSpinner dijit view helper
  37. * @var string
  38. */
  39. public $helper = 'NumberSpinner';
  40. /**
  41. * Set defaultTimeout
  42. *
  43. * @param int $timeout
  44. * @return Zend_Dojo_Form_Element_NumberSpinner
  45. */
  46. public function setDefaultTimeout($timeout)
  47. {
  48. $this->setDijitParam('defaultTimeout', (int) $timeout);
  49. return $this;
  50. }
  51. /**
  52. * Retrieve defaultTimeout
  53. *
  54. * @return int|null
  55. */
  56. public function getDefaultTimeout()
  57. {
  58. return $this->getDijitParam('defaultTimeout');
  59. }
  60. /**
  61. * Set timeoutChangeRate
  62. *
  63. * @param int $rate
  64. * @return Zend_Dojo_Form_Element_NumberSpinner
  65. */
  66. public function setTimeoutChangeRate($rate)
  67. {
  68. $this->setDijitParam('timeoutChangeRate', (int) $rate);
  69. return $this;
  70. }
  71. /**
  72. * Retrieve timeoutChangeRate
  73. *
  74. * @return int|null
  75. */
  76. public function getTimeoutChangeRate()
  77. {
  78. return $this->getDijitParam('timeoutChangeRate');
  79. }
  80. /**
  81. * Set largeDelta
  82. *
  83. * @param int $delta
  84. * @return Zend_Dojo_Form_Element_NumberSpinner
  85. */
  86. public function setLargeDelta($delta)
  87. {
  88. $this->setDijitParam('largeDelta', (float) $delta);
  89. return $this;
  90. }
  91. /**
  92. * Retrieve largeDelta
  93. *
  94. * @return int|null
  95. */
  96. public function getLargeDelta()
  97. {
  98. return $this->getDijitParam('largeDelta');
  99. }
  100. /**
  101. * Set smallDelta
  102. *
  103. * @param int $delta
  104. * @return Zend_Dojo_Form_Element_NumberSpinner
  105. */
  106. public function setSmallDelta($delta)
  107. {
  108. $this->setDijitParam('smallDelta', (float) $delta);
  109. return $this;
  110. }
  111. /**
  112. * Retrieve smallDelta
  113. *
  114. * @return int|null
  115. */
  116. public function getSmallDelta()
  117. {
  118. return $this->getDijitParam('smallDelta');
  119. }
  120. /**
  121. * Set intermediateChanges flag
  122. *
  123. * @param bool $flag
  124. * @return Zend_Dojo_Form_Element_TextBox
  125. */
  126. public function setIntermediateChanges($flag)
  127. {
  128. $this->setDijitParam('intermediateChanges', (bool) $flag);
  129. return $this;
  130. }
  131. /**
  132. * Retrieve intermediateChanges flag
  133. *
  134. * @return bool
  135. */
  136. public function getIntermediateChanges()
  137. {
  138. if (!$this->hasDijitParam('intermediateChanges')) {
  139. return false;
  140. }
  141. return $this->getDijitParam('intermediateChanges');
  142. }
  143. /**
  144. * Set rangeMessage
  145. *
  146. * @param string $message
  147. * @return Zend_Dojo_Form_Element_NumberSpinner
  148. */
  149. public function setRangeMessage($message)
  150. {
  151. $this->setDijitParam('rangeMessage', (string) $message);
  152. return $this;
  153. }
  154. /**
  155. * Retrieve rangeMessage
  156. *
  157. * @return string|null
  158. */
  159. public function getRangeMessage()
  160. {
  161. return $this->getDijitParam('rangeMessage');
  162. }
  163. /**
  164. * Set minimum value
  165. *
  166. * @param int $value
  167. * @return Zend_Dojo_Form_Element_NumberSpinner
  168. */
  169. public function setMin($value)
  170. {
  171. $constraints = array();
  172. if ($this->hasDijitParam('constraints')) {
  173. $constraints = $this->getDijitParam('constraints');
  174. }
  175. $constraints['min'] = (float) $value;
  176. $this->setDijitParam('constraints', $constraints);
  177. return $this;
  178. }
  179. /**
  180. * Get minimum value
  181. *
  182. * @return null|int
  183. */
  184. public function getMin()
  185. {
  186. if (!$this->hasDijitParam('constraints')) {
  187. return null;
  188. }
  189. $constraints = $this->getDijitParam('constraints');
  190. if (!array_key_exists('min', $constraints)) {
  191. return null;
  192. }
  193. return $constraints['min'];
  194. }
  195. /**
  196. * Set maximum value
  197. *
  198. * @param int $value
  199. * @return Zend_Dojo_Form_Element_NumberSpinner
  200. */
  201. public function setMax($value)
  202. {
  203. $constraints = array();
  204. if ($this->hasDijitParam('constraints')) {
  205. $constraints = $this->getDijitParam('constraints');
  206. }
  207. $constraints['max'] = (float) $value;
  208. $this->setDijitParam('constraints', $constraints);
  209. return $this;
  210. }
  211. /**
  212. * Get maximum value
  213. *
  214. * @return null|int
  215. */
  216. public function getMax()
  217. {
  218. if (!$this->hasDijitParam('constraints')) {
  219. return null;
  220. }
  221. $constraints = $this->getDijitParam('constraints');
  222. if (!array_key_exists('max', $constraints)) {
  223. return null;
  224. }
  225. return $constraints['max'];
  226. }
  227. }