web/enmi/Zend/Dojo/Form/Element/CurrencyTextBox.php
changeset 19 1c2f13fd785c
parent 0 4eba9c11703f
equal deleted inserted replaced
18:bd595ad770fc 19:1c2f13fd785c
       
     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-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    20  */
       
    21 
       
    22 /** Zend_Dojo_Form_Element_NumberTextBox */
       
    23 require_once 'Zend/Dojo/Form/Element/NumberTextBox.php';
       
    24 
       
    25 /**
       
    26  * CurrencyTextBox dijit
       
    27  *
       
    28  * @uses       Zend_Dojo_Form_Element_NumberTextBox
       
    29  * @package    Zend_Dojo
       
    30  * @subpackage Form_Element
       
    31  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    32  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    33  * @version    $Id: CurrencyTextBox.php 20096 2010-01-06 02:05:09Z bkarwin $
       
    34  */
       
    35 class Zend_Dojo_Form_Element_CurrencyTextBox extends Zend_Dojo_Form_Element_NumberTextBox
       
    36 {
       
    37     /**
       
    38      * Use CurrencyTextBox dijit view helper
       
    39      * @var string
       
    40      */
       
    41     public $helper = 'CurrencyTextBox';
       
    42 
       
    43     /**
       
    44      * Set currency
       
    45      *
       
    46      * @param  string $currency
       
    47      * @return Zend_Dojo_Form_Element_CurrencyTextBox
       
    48      */
       
    49     public function setCurrency($currency)
       
    50     {
       
    51         $this->setDijitParam('currency', (string) $currency);
       
    52         return $this;
       
    53     }
       
    54 
       
    55     /**
       
    56      * Retrieve currency
       
    57      *
       
    58      * @return string|null
       
    59      */
       
    60     public function getCurrency()
       
    61     {
       
    62         return $this->getDijitParam('currency');
       
    63     }
       
    64 
       
    65     /**
       
    66      * Set currency symbol
       
    67      *
       
    68      * Casts to string, uppercases, and trims to three characters.
       
    69      *
       
    70      * @param  string $symbol
       
    71      * @return Zend_Dojo_Form_Element_CurrencyTextBox
       
    72      */
       
    73     public function setSymbol($symbol)
       
    74     {
       
    75         $symbol = strtoupper((string) $symbol);
       
    76         $length = strlen($symbol);
       
    77         if (3 > $length) {
       
    78             require_once 'Zend/Form/Element/Exception.php';
       
    79             throw new Zend_Form_Element_Exception('Invalid symbol provided; please provide ISO 4217 alphabetic currency code');
       
    80         }
       
    81         if (3 < $length) {
       
    82             $symbol = substr($symbol, 0, 3);
       
    83         }
       
    84 
       
    85         $this->setConstraint('symbol', $symbol);
       
    86         return $this;
       
    87     }
       
    88 
       
    89     /**
       
    90      * Retrieve symbol
       
    91      *
       
    92      * @return string|null
       
    93      */
       
    94     public function getSymbol()
       
    95     {
       
    96         return $this->getConstraint('symbol');
       
    97     }
       
    98 
       
    99     /**
       
   100      * Set whether currency is fractional
       
   101      *
       
   102      * @param  bool $flag
       
   103      * @return Zend_Dojo_Form_Element_CurrencyTextBox
       
   104      */
       
   105     public function setFractional($flag)
       
   106     {
       
   107         $this->setConstraint('fractional', (bool) $flag);
       
   108         return $this;
       
   109     }
       
   110 
       
   111     /**
       
   112      * Get whether or not to present fractional values
       
   113      *
       
   114      * @return bool
       
   115      */
       
   116     public function getFractional()
       
   117     {
       
   118         return ('true' == $this->getConstraint('fractional'));
       
   119     }
       
   120 }