File indexing completed on 2024-06-23 05:55:12

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 View
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  * @version    $Id$
0021  */
0022 
0023 /** Zend_Dojo_View_Helper_Dijit */
0024 // require_once 'Zend/Dojo/View/Helper/Dijit.php';
0025 
0026 /**
0027  * Dojo CheckBox dijit
0028  *
0029  * @uses       Zend_Dojo_View_Helper_Dijit
0030  * @package    Zend_Dojo
0031  * @subpackage View
0032  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0033  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0034   */
0035 class Zend_Dojo_View_Helper_CheckBox extends Zend_Dojo_View_Helper_Dijit
0036 {
0037     /**
0038      * Dijit being used
0039      * @var string
0040      */
0041     protected $_dijit  = 'dijit.form.CheckBox';
0042 
0043     /**
0044      * Element type
0045      * @var string
0046      */
0047     protected $_elementType = 'checkbox';
0048 
0049     /**
0050      * Dojo module to use
0051      * @var string
0052      */
0053     protected $_module = 'dijit.form.CheckBox';
0054 
0055     /**
0056      * dijit.form.CheckBox
0057      *
0058      * @param  int $id
0059      * @param  string $content
0060      * @param  array $params  Parameters to use for dijit creation
0061      * @param  array $attribs HTML attributes
0062      * @param  array $checkedOptions Should contain either two items, or the keys checkedValue and uncheckedValue
0063      * @return string
0064      */
0065     public function checkBox($id, $value = null, array $params = array(), array $attribs = array(), array $checkedOptions = null)
0066     {
0067         // Prepare the checkbox options
0068         // require_once 'Zend/View/Helper/FormCheckbox.php';
0069         $checked = false;
0070         if (isset($attribs['checked']) && $attribs['checked']) {
0071             $checked = true;
0072         } elseif (isset($attribs['checked'])) {
0073             $checked = false;
0074         }
0075         $checkboxInfo = Zend_View_Helper_FormCheckbox::determineCheckboxInfo($value, $checked, $checkedOptions);
0076         $attribs['checked'] = $checkboxInfo['checked'];
0077         if (!array_key_exists('id', $attribs)) {
0078             $attribs['id'] = $id;
0079         }
0080 
0081         $attribs = $this->_prepareDijit($attribs, $params, 'element');
0082 
0083         // strip options so they don't show up in markup
0084         if (array_key_exists('options', $attribs)) {
0085             unset($attribs['options']);
0086         }
0087 
0088         // and now we create it:
0089         $html = '';
0090         if (!strstr($id, '[]')) {
0091             // hidden element for unchecked value
0092             $html .= $this->_renderHiddenElement($id, $checkboxInfo['uncheckedValue']);
0093         }
0094 
0095         // and final element
0096         $html .= $this->_createFormElement($id, $checkboxInfo['checkedValue'], $params, $attribs);
0097 
0098         return $html;
0099     }
0100 }