File indexing completed on 2025-03-02 05:29:19

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Dojo
0017  * @subpackage Form_Element
0018  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0019  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0020  */
0021 
0022 /** Zend_Dojo_Form_Element_ValidationTextBox */
0023 // require_once 'Zend/Dojo/Form/Element/ValidationTextBox.php';
0024 
0025 /**
0026  * NumberTextBox dijit
0027  *
0028  * @uses       Zend_Dojo_Form_Element_ValidationTextBox
0029  * @package    Zend_Dojo
0030  * @subpackage Form_Element
0031  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0032  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0033  * @version    $Id$
0034  */
0035 class Zend_Dojo_Form_Element_NumberTextBox extends Zend_Dojo_Form_Element_ValidationTextBox
0036 {
0037     /**
0038      * Use NumberTextBox dijit view helper
0039      * @var string
0040      */
0041     public $helper = 'NumberTextBox';
0042 
0043     /**
0044      * Allowed numeric type formats
0045      * @var array
0046      */
0047     protected $_allowedTypes = array(
0048         'decimal',
0049         'scientific',
0050         'percent',
0051         'currency',
0052     );
0053 
0054     /**
0055      * Set locale
0056      *
0057      * @param  string $locale
0058      * @return Zend_Dojo_Form_Element_NumberTextBox
0059      */
0060     public function setLocale($locale)
0061     {
0062         $this->setConstraint('locale', (string) $locale);
0063         return $this;
0064     }
0065 
0066     /**
0067      * Retrieve locale
0068      *
0069      * @return string|null
0070      */
0071     public function getLocale()
0072     {
0073         return $this->getConstraint('locale');
0074     }
0075 
0076     /**
0077      * Set numeric format pattern
0078      *
0079      * @param  string $pattern
0080      * @return Zend_Dojo_Form_Element_NumberTextBox
0081      */
0082     public function setPattern($pattern)
0083     {
0084         $this->setConstraint('pattern', (string) $pattern);
0085         return $this;
0086     }
0087 
0088     /**
0089      * Retrieve numeric format pattern
0090      *
0091      * @return string|null
0092      */
0093     public function getPattern()
0094     {
0095         return $this->getConstraint('pattern');
0096     }
0097 
0098     /**
0099      * Set numeric format type
0100      *
0101      * @see    $_allowedTypes
0102      * @param  string $type
0103      * @return Zend_Dojo_Form_Element_NumberTextBox
0104      */
0105     public function setType($type)
0106     {
0107         $type = strtolower($type);
0108         if (!in_array($type, $this->_allowedTypes)) {
0109             // require_once 'Zend/Form/Element/Exception.php';
0110             throw new Zend_Form_Element_Exception(sprintf('Invalid numeric type "%s" specified', $type));
0111         }
0112 
0113         $this->setConstraint('type', $type);
0114         return $this;
0115     }
0116 
0117     /**
0118      * Retrieve type
0119      *
0120      * @return string|null
0121      */
0122     public function getType()
0123     {
0124         return $this->getConstraint('type');
0125     }
0126 
0127     /**
0128      * Set decimal places
0129      *
0130      * @param  int $places
0131      * @return Zend_Dojo_Form_Element_NumberTextBox
0132      */
0133     public function setPlaces($places)
0134     {
0135         $this->setConstraint('places', (int) $places);
0136         return $this;
0137     }
0138 
0139     /**
0140      * Retrieve decimal places
0141      *
0142      * @return int|null
0143      */
0144     public function getPlaces()
0145     {
0146         return $this->getConstraint('places');
0147     }
0148 
0149     /**
0150      * Set strict flag
0151      *
0152      * @param  bool $strict
0153      * @return Zend_Dojo_Form_Element_NumberTextBox
0154      */
0155     public function setStrict($flag)
0156     {
0157         $this->setConstraint('strict', (bool) $flag);
0158         return $this;
0159     }
0160 
0161     /**
0162      * Retrieve strict flag
0163      *
0164      * @return bool
0165      */
0166     public function getStrict()
0167     {
0168         if (!$this->hasConstraint('strict')) {
0169             return false;
0170         }
0171         return ('true' == $this->getConstraint('strict'));
0172     }
0173 }