CheckBox.php 3.1 KB

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