NumberSpinner.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 View
  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. * @version $Id$
  21. */
  22. /** Zend_Dojo_View_Helper_Dijit */
  23. require_once 'Zend/Dojo/View/Helper/Dijit.php';
  24. /**
  25. * Dojo NumberSpinner dijit
  26. *
  27. * @uses Zend_Dojo_View_Helper_Dijit
  28. * @package Zend_Dojo
  29. * @subpackage View
  30. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. */
  33. class Zend_Dojo_View_Helper_NumberSpinner extends Zend_Dojo_View_Helper_Dijit
  34. {
  35. /**
  36. * Dijit being used
  37. * @var string
  38. */
  39. protected $_dijit = 'dijit.form.NumberSpinner';
  40. /**
  41. * HTML element type
  42. * @var string
  43. */
  44. protected $_elementType = 'text';
  45. /**
  46. * Dojo module to use
  47. * @var string
  48. */
  49. protected $_module = 'dijit.form.NumberSpinner';
  50. /**
  51. * dijit.form.NumberSpinner
  52. *
  53. * @param int $id
  54. * @param mixed $value
  55. * @param array $params Parameters to use for dijit creation
  56. * @param array $attribs HTML attributes
  57. * @return string
  58. */
  59. public function numberSpinner($id, $value = null, array $params = array(), array $attribs = array())
  60. {
  61. // Get constraints and serialize to JSON if necessary
  62. if (array_key_exists('constraints', $params)) {
  63. if (!is_array($params['constraints'])) {
  64. unset($params['constraints']);
  65. }
  66. } else {
  67. $constraints = array();
  68. if (array_key_exists('min', $params)) {
  69. $constraints['min'] = $params['min'];
  70. unset($params['min']);
  71. }
  72. if (array_key_exists('max', $params)) {
  73. $constraints['max'] = $params['max'];
  74. unset($params['max']);
  75. }
  76. if (array_key_exists('places', $params)) {
  77. $constraints['places'] = $params['places'];
  78. unset($params['places']);
  79. }
  80. $params['constraints'] = $constraints;
  81. }
  82. return $this->_createFormElement($id, $value, $params, $attribs);
  83. }
  84. }