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_Dijit */
0023 // require_once 'Zend/Dojo/Form/Element/Dijit.php';
0024 
0025 /**
0026  * Button dijit
0027  *
0028  * @category   Zend
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_Button extends Zend_Dojo_Form_Element_Dijit
0036 {
0037     /**
0038      * Use Button dijit view helper
0039      * @var string
0040      */
0041     public $helper = 'Button';
0042 
0043     /**
0044      * Constructor
0045      *
0046      * @param  string|array|Zend_Config $spec Element name or configuration
0047      * @param  string|array|Zend_Config $options Element value or configuration
0048      * @return void
0049      */
0050     public function __construct($spec, $options = null)
0051     {
0052         if (is_string($spec) && ((null !== $options) && is_string($options))) {
0053             $options = array('label' => $options);
0054         }
0055 
0056         parent::__construct($spec, $options);
0057     }
0058 
0059     /**
0060      * Return label
0061      *
0062      * If no label is present, returns the currently set name.
0063      *
0064      * If a translator is present, returns the translated label.
0065      *
0066      * @return string
0067      */
0068     public function getLabel()
0069     {
0070         $value = parent::getLabel();
0071 
0072         if (null === $value) {
0073             $value = $this->getName();
0074         }
0075 
0076         if (null !== ($translator = $this->getTranslator())) {
0077             return $translator->translate($value);
0078         }
0079 
0080         return $value;
0081     }
0082 
0083     /**
0084      * Has this submit button been selected?
0085      *
0086      * @return bool
0087      */
0088     public function isChecked()
0089     {
0090         $value = $this->getValue();
0091 
0092         if (empty($value)) {
0093             return false;
0094         }
0095         if ($value != $this->getLabel()) {
0096             return false;
0097         }
0098 
0099         return true;
0100     }
0101 
0102     /**
0103      * Default decorators
0104      *
0105      * Uses only 'DijitElement' and 'DtDdWrapper' decorators by default.
0106      *
0107      * @return void
0108      */
0109     public function loadDefaultDecorators()
0110     {
0111         if ($this->loadDefaultDecoratorsIsDisabled()) {
0112             return;
0113         }
0114 
0115         $decorators = $this->getDecorators();
0116         if (empty($decorators)) {
0117             $this->addDecorator('DijitElement')
0118                  ->addDecorator('DtDdWrapper');
0119         }
0120     }
0121 }