TimeTextBox.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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_DateTextBox */
  22. require_once 'Zend/Dojo/Form/Element/DateTextBox.php';
  23. /**
  24. * TimeTextBox dijit
  25. *
  26. * @uses Zend_Dojo_Form_Element_DateTextBox
  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_TimeTextBox extends Zend_Dojo_Form_Element_DateTextBox
  34. {
  35. /**
  36. * Use TimeTextBox dijit view helper
  37. * @var string
  38. */
  39. public $helper = 'TimeTextBox';
  40. /**
  41. * Validate ISO 8601 time format
  42. *
  43. * @param string $format
  44. * @return true
  45. * @throws Zend_Form_Element_Exception
  46. */
  47. protected function _validateIso8601($format)
  48. {
  49. if (!preg_match('/^T\d{2}:\d{2}:\d{2}$/', $format)) {
  50. require_once 'Zend/Form/Element/Exception.php';
  51. throw new Zend_Form_Element_Exception(sprintf('Invalid format "%s" provided; must match T:00:00:00 format', $format));
  52. }
  53. return true;
  54. }
  55. /**
  56. * Set time format pattern
  57. *
  58. * @param string $pattern
  59. * @return Zend_Dojo_Form_Element_NumberTextBox
  60. */
  61. public function setTimePattern($pattern)
  62. {
  63. $this->setConstraint('timePattern', (string) $pattern);
  64. return $this;
  65. }
  66. /**
  67. * Retrieve time format pattern
  68. *
  69. * @return string|null
  70. */
  71. public function getTimePattern()
  72. {
  73. return $this->getConstraint('timePattern');
  74. }
  75. /**
  76. * Set clickableIncrement
  77. *
  78. * @param string $format
  79. * @return Zend_Dojo_Form_Element_NumberTextBox
  80. */
  81. public function setClickableIncrement($format)
  82. {
  83. $format = (string) $format;
  84. $this->_validateIso8601($format);
  85. $this->setConstraint('clickableIncrement', $format);
  86. return $this;
  87. }
  88. /**
  89. * Retrieve clickableIncrement
  90. *
  91. * @return string|null
  92. */
  93. public function getClickableIncrement()
  94. {
  95. return $this->getConstraint('clickableIncrement');
  96. }
  97. /**
  98. * Set visibleIncrement
  99. *
  100. * @param string $format
  101. * @return Zend_Dojo_Form_Element_NumberTextBox
  102. */
  103. public function setVisibleIncrement($format)
  104. {
  105. $format = (string) $format;
  106. $this->_validateIso8601($format);
  107. $this->setConstraint('visibleIncrement', $format);
  108. return $this;
  109. }
  110. /**
  111. * Retrieve visibleIncrement
  112. *
  113. * @return string|null
  114. */
  115. public function getVisibleIncrement()
  116. {
  117. return $this->getConstraint('visibleIncrement');
  118. }
  119. /**
  120. * Set visibleRange
  121. *
  122. * @param string $format
  123. * @return Zend_Dojo_Form_Element_NumberTextBox
  124. */
  125. public function setVisibleRange($format)
  126. {
  127. $format = (string) $format;
  128. $this->_validateIso8601($format);
  129. $this->setConstraint('visibleRange', $format);
  130. return $this;
  131. }
  132. /**
  133. * Retrieve visibleRange
  134. *
  135. * @return string|null
  136. */
  137. public function getVisibleRange()
  138. {
  139. return $this->getConstraint('visibleRange');
  140. }
  141. }