CurrencyTextBox.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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_NumberTextBox */
  22. require_once 'Zend/Dojo/Form/Element/NumberTextBox.php';
  23. /**
  24. * CurrencyTextBox dijit
  25. *
  26. * @uses Zend_Dojo_Form_Element_NumberTextBox
  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_CurrencyTextBox extends Zend_Dojo_Form_Element_NumberTextBox
  34. {
  35. /**
  36. * Use CurrencyTextBox dijit view helper
  37. * @var string
  38. */
  39. public $helper = 'CurrencyTextBox';
  40. /**
  41. * Set currency
  42. *
  43. * @param string $currency
  44. * @return Zend_Dojo_Form_Element_CurrencyTextBox
  45. */
  46. public function setCurrency($currency)
  47. {
  48. $this->setDijitParam('currency', (string) $currency);
  49. return $this;
  50. }
  51. /**
  52. * Retrieve currency
  53. *
  54. * @return string|null
  55. */
  56. public function getCurrency()
  57. {
  58. return $this->getDijitParam('currency');
  59. }
  60. /**
  61. * Set currency symbol
  62. *
  63. * Casts to string, uppercases, and trims to three characters.
  64. *
  65. * @param string $symbol
  66. * @return Zend_Dojo_Form_Element_CurrencyTextBox
  67. */
  68. public function setSymbol($symbol)
  69. {
  70. $symbol = strtoupper((string) $symbol);
  71. $length = strlen($symbol);
  72. if (3 > $length) {
  73. require_once 'Zend/Form/Element/Exception.php';
  74. throw new Zend_Form_Element_Exception('Invalid symbol provided; please provide ISO 4217 alphabetic currency code');
  75. }
  76. if (3 < $length) {
  77. $symbol = substr($symbol, 0, 3);
  78. }
  79. $this->setConstraint('symbol', $symbol);
  80. return $this;
  81. }
  82. /**
  83. * Retrieve symbol
  84. *
  85. * @return string|null
  86. */
  87. public function getSymbol()
  88. {
  89. return $this->getConstraint('symbol');
  90. }
  91. /**
  92. * Set whether currency is fractional
  93. *
  94. * @param bool $flag
  95. * @return Zend_Dojo_Form_Element_CurrencyTextBox
  96. */
  97. public function setFractional($flag)
  98. {
  99. $this->setConstraint('fractional', (bool) $flag);
  100. return $this;
  101. }
  102. /**
  103. * Get whether or not to present fractional values
  104. *
  105. * @return bool
  106. */
  107. public function getFractional()
  108. {
  109. return ('true' == $this->getConstraint('fractional'));
  110. }
  111. }