DateTextBox.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. * DateTextBox 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_DateTextBox extends Zend_Dojo_Form_Element_ValidationTextBox
  34. {
  35. /**
  36. * Use DateTextBox dijit view helper
  37. * @var string
  38. */
  39. public $helper = 'DateTextBox';
  40. /**
  41. * Allowed formatLength types
  42. * @var array
  43. */
  44. protected $_allowedFormatTypes = array(
  45. 'long',
  46. 'short',
  47. 'medium',
  48. 'full',
  49. );
  50. /**
  51. * Allowed selector types
  52. * @var array
  53. */
  54. protected $_allowedSelectorTypes = array(
  55. 'time',
  56. 'date',
  57. );
  58. /**
  59. * Set am,pm flag
  60. *
  61. * @param bool $am,pm
  62. * @return Zend_Dojo_Form_Element_DateTextBox
  63. */
  64. public function setAmPm($flag)
  65. {
  66. $this->setConstraint('am,pm', (bool) $flag);
  67. return $this;
  68. }
  69. /**
  70. * Retrieve am,pm flag
  71. *
  72. * @return bool
  73. */
  74. public function getAmPm()
  75. {
  76. if (!$this->hasConstraint('am,pm')) {
  77. return false;
  78. }
  79. return ('true' ==$this->getConstraint('am,pm'));
  80. }
  81. /**
  82. * Set strict flag
  83. *
  84. * @param bool $strict
  85. * @return Zend_Dojo_Form_Element_DateTextBox
  86. */
  87. public function setStrict($flag)
  88. {
  89. $this->setConstraint('strict', (bool) $flag);
  90. return $this;
  91. }
  92. /**
  93. * Retrieve strict flag
  94. *
  95. * @return bool
  96. */
  97. public function getStrict()
  98. {
  99. if (!$this->hasConstraint('strict')) {
  100. return false;
  101. }
  102. return ('true' == $this->getConstraint('strict'));
  103. }
  104. /**
  105. * Set locale
  106. *
  107. * @param string $locale
  108. * @return Zend_Dojo_Form_Element_DateTextBox
  109. */
  110. public function setLocale($locale)
  111. {
  112. $this->setConstraint('locale', (string) $locale);
  113. return $this;
  114. }
  115. /**
  116. * Retrieve locale
  117. *
  118. * @return string|null
  119. */
  120. public function getLocale()
  121. {
  122. return $this->getConstraint('locale');
  123. }
  124. /**
  125. * Set date format pattern
  126. *
  127. * @param string $pattern
  128. * @return Zend_Dojo_Form_Element_NumberTextBox
  129. */
  130. public function setDatePattern($pattern)
  131. {
  132. $this->setConstraint('datePattern', (string) $pattern);
  133. return $this;
  134. }
  135. /**
  136. * Retrieve date format pattern
  137. *
  138. * @return string|null
  139. */
  140. public function getDatePattern()
  141. {
  142. return $this->getConstraint('datePattern');
  143. }
  144. /**
  145. * Set numeric format formatLength
  146. *
  147. * @see $_allowedFormatTypes
  148. * @param string $formatLength
  149. * @return Zend_Dojo_Form_Element_NumberTextBox
  150. */
  151. public function setFormatLength($formatLength)
  152. {
  153. $formatLength = strtolower($formatLength);
  154. if (!in_array($formatLength, $this->_allowedFormatTypes)) {
  155. require_once 'Zend/Form/Element/Exception.php';
  156. throw new Zend_Form_Element_Exception(sprintf('Invalid formatLength "%s" specified', $formatLength));
  157. }
  158. $this->setConstraint('formatLength', $formatLength);
  159. return $this;
  160. }
  161. /**
  162. * Retrieve formatLength
  163. *
  164. * @return string|null
  165. */
  166. public function getFormatLength()
  167. {
  168. return $this->getConstraint('formatLength');
  169. }
  170. /**
  171. * Set numeric format Selector
  172. *
  173. * @see $_allowedSelectorTypes
  174. * @param string $selector
  175. * @return Zend_Dojo_Form_Element_NumberTextBox
  176. */
  177. public function setSelector($selector)
  178. {
  179. $selector = strtolower($selector);
  180. if (!in_array($selector, $this->_allowedSelectorTypes)) {
  181. require_once 'Zend/Form/Element/Exception.php';
  182. throw new Zend_Form_Element_Exception(sprintf('Invalid Selector "%s" specified', $selector));
  183. }
  184. $this->setConstraint('selector', $selector);
  185. return $this;
  186. }
  187. /**
  188. * Retrieve selector
  189. *
  190. * @return string|null
  191. */
  192. public function getSelector()
  193. {
  194. return $this->getConstraint('selector');
  195. }
  196. }