PageRenderTime 51ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/tine20/library/Zend/Dojo/Form/Element/NumberTextBox.php

https://gitlab.com/rsilveira1987/Expresso
PHP | 173 lines | 65 code | 14 blank | 94 comment | 3 complexity | 42619fee33f3e844c0ad9a50c0ed5712 MD5 | raw file
  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-2009 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. * NumberTextBox dijit
  25. *
  26. * @uses Zend_Dojo_Form_Element_ValidationTextBox
  27. * @package Zend_Dojo
  28. * @subpackage Form_Element
  29. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. * @version $Id: NumberTextBox.php 10020 2009-08-18 14:34:09Z j.fischer@metaways.de $
  32. */
  33. class Zend_Dojo_Form_Element_NumberTextBox extends Zend_Dojo_Form_Element_ValidationTextBox
  34. {
  35. /**
  36. * Use NumberTextBox dijit view helper
  37. * @var string
  38. */
  39. public $helper = 'NumberTextBox';
  40. /**
  41. * Allowed numeric type formats
  42. * @var array
  43. */
  44. protected $_allowedTypes = array(
  45. 'decimal',
  46. 'scientific',
  47. 'percent',
  48. 'currency',
  49. );
  50. /**
  51. * Set locale
  52. *
  53. * @param string $locale
  54. * @return Zend_Dojo_Form_Element_NumberTextBox
  55. */
  56. public function setLocale($locale)
  57. {
  58. $this->setConstraint('locale', (string) $locale);
  59. return $this;
  60. }
  61. /**
  62. * Retrieve locale
  63. *
  64. * @return string|null
  65. */
  66. public function getLocale()
  67. {
  68. return $this->getConstraint('locale');
  69. }
  70. /**
  71. * Set numeric format pattern
  72. *
  73. * @param string $pattern
  74. * @return Zend_Dojo_Form_Element_NumberTextBox
  75. */
  76. public function setPattern($pattern)
  77. {
  78. $this->setConstraint('pattern', (string) $pattern);
  79. return $this;
  80. }
  81. /**
  82. * Retrieve numeric format pattern
  83. *
  84. * @return string|null
  85. */
  86. public function getPattern()
  87. {
  88. return $this->getConstraint('pattern');
  89. }
  90. /**
  91. * Set numeric format type
  92. *
  93. * @see $_allowedTypes
  94. * @param string $type
  95. * @return Zend_Dojo_Form_Element_NumberTextBox
  96. */
  97. public function setType($type)
  98. {
  99. $type = strtolower($type);
  100. if (!in_array($type, $this->_allowedTypes)) {
  101. require_once 'Zend/Form/Element/Exception.php';
  102. throw new Zend_Form_Element_Exception(sprintf('Invalid numeric type "%s" specified', $type));
  103. }
  104. $this->setConstraint('type', $type);
  105. return $this;
  106. }
  107. /**
  108. * Retrieve type
  109. *
  110. * @return string|null
  111. */
  112. public function getType()
  113. {
  114. return $this->getConstraint('type');
  115. }
  116. /**
  117. * Set decimal places
  118. *
  119. * @param int $places
  120. * @return Zend_Dojo_Form_Element_NumberTextBox
  121. */
  122. public function setPlaces($places)
  123. {
  124. $this->setConstraint('places', (int) $places);
  125. return $this;
  126. }
  127. /**
  128. * Retrieve decimal places
  129. *
  130. * @return int|null
  131. */
  132. public function getPlaces()
  133. {
  134. return $this->getConstraint('places');
  135. }
  136. /**
  137. * Set strict flag
  138. *
  139. * @param bool $strict
  140. * @return Zend_Dojo_Form_Element_NumberTextBox
  141. */
  142. public function setStrict($flag)
  143. {
  144. $this->setConstraint('strict', (bool) $flag);
  145. return $this;
  146. }
  147. /**
  148. * Retrieve strict flag
  149. *
  150. * @return bool
  151. */
  152. public function getStrict()
  153. {
  154. if (!$this->hasConstraint('strict')) {
  155. return false;
  156. }
  157. return ('true' == $this->getConstraint('strict'));
  158. }
  159. }