web/lib/Zend/Dojo/View/Helper/CheckBox.php
changeset 64 162c1de6545a
parent 19 1c2f13fd785c
child 68 ecaf28ffe26e
equal deleted inserted replaced
63:5b37998e522e 64:162c1de6545a
       
     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 View
       
    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  * @version    $Id: CheckBox.php 20096 2010-01-06 02:05:09Z bkarwin $
       
    21  */
       
    22 
       
    23 /** Zend_Dojo_View_Helper_Dijit */
       
    24 require_once 'Zend/Dojo/View/Helper/Dijit.php';
       
    25 
       
    26 /**
       
    27  * Dojo CheckBox dijit
       
    28  *
       
    29  * @uses       Zend_Dojo_View_Helper_Dijit
       
    30  * @package    Zend_Dojo
       
    31  * @subpackage View
       
    32  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    33  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    34   */
       
    35 class Zend_Dojo_View_Helper_CheckBox extends Zend_Dojo_View_Helper_Dijit
       
    36 {
       
    37     /**
       
    38      * Dijit being used
       
    39      * @var string
       
    40      */
       
    41     protected $_dijit  = 'dijit.form.CheckBox';
       
    42 
       
    43     /**
       
    44      * Element type
       
    45      * @var string
       
    46      */
       
    47     protected $_elementType = 'checkbox';
       
    48 
       
    49     /**
       
    50      * Dojo module to use
       
    51      * @var string
       
    52      */
       
    53     protected $_module = 'dijit.form.CheckBox';
       
    54 
       
    55     /**
       
    56      * dijit.form.CheckBox
       
    57      *
       
    58      * @param  int $id
       
    59      * @param  string $content
       
    60      * @param  array $params  Parameters to use for dijit creation
       
    61      * @param  array $attribs HTML attributes
       
    62      * @param  array $checkedOptions Should contain either two items, or the keys checkedValue and uncheckedValue
       
    63      * @return string
       
    64      */
       
    65     public function checkBox($id, $value = null, array $params = array(), array $attribs = array(), array $checkedOptions = null)
       
    66     {
       
    67         // Prepare the checkbox options
       
    68         require_once 'Zend/View/Helper/FormCheckbox.php';
       
    69         $checked = false;
       
    70         if (isset($attribs['checked']) && $attribs['checked']) {
       
    71             $checked = true;
       
    72         } elseif (isset($attribs['checked'])) {
       
    73             $checked = false;
       
    74         }
       
    75         $checkboxInfo = Zend_View_Helper_FormCheckbox::determineCheckboxInfo($value, $checked, $checkedOptions);
       
    76         $attribs['checked'] = $checkboxInfo['checked'];
       
    77         if (!array_key_exists('id', $attribs)) {
       
    78             $attribs['id'] = $id;
       
    79         }
       
    80 
       
    81         $attribs = $this->_prepareDijit($attribs, $params, 'element');
       
    82 
       
    83         // strip options so they don't show up in markup
       
    84         if (array_key_exists('options', $attribs)) {
       
    85             unset($attribs['options']);
       
    86         }
       
    87 
       
    88         // and now we create it:
       
    89         $html = '';
       
    90         if (!strstr($id, '[]')) {
       
    91             // hidden element for unchecked value
       
    92             $html .= $this->_renderHiddenElement($id, $checkboxInfo['uncheckedValue']);
       
    93         }
       
    94 
       
    95         // and final element
       
    96         $html .= $this->_createFormElement($id, $checkboxInfo['checkedValue'], $params, $attribs);
       
    97 
       
    98         return $html;
       
    99     }
       
   100 }