/lib/form/advcheckbox.php

https://bitbucket.org/ngmares/moodle · PHP · 137 lines · 51 code · 14 blank · 72 comment · 8 complexity · bcc6c3f62953c14ce0ac876f254096cd MD5 · raw file

  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Advanced checkbox type form element
  18. *
  19. * Contains HTML class for an advcheckbox type form element
  20. *
  21. * @package core_form
  22. * @copyright 2007 Jamie Pratt <me@jamiep.org>
  23. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24. */
  25. require_once('HTML/QuickForm/advcheckbox.php');
  26. /**
  27. * HTML class for an advcheckbox type element
  28. *
  29. * Overloaded {@link HTML_QuickForm_advcheckbox} with default behavior modified for Moodle.
  30. * This will return '0' if not checked and '1' if checked.
  31. *
  32. * @package core_form
  33. * @category form
  34. * @copyright 2007 Jamie Pratt <me@jamiep.org>
  35. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  36. */
  37. class MoodleQuickForm_advcheckbox extends HTML_QuickForm_advcheckbox{
  38. /** @var string html for help button, if empty then no help will icon will be dispalyed. */
  39. var $_helpbutton='';
  40. /** @var string Group to which this checkbox belongs (for select all/select none button) */
  41. var $_group;
  42. /**
  43. * constructor
  44. *
  45. * @param string $elementName (optional) name of the checkbox
  46. * @param string $elementLabel (optional) checkbox label
  47. * @param string $text (optional) Text to put after the checkbox
  48. * @param mixed $attributes (optional) Either a typical HTML attribute string
  49. * or an associative array
  50. * @param mixed $values (optional) Values to pass if checked or not checked
  51. */
  52. function MoodleQuickForm_advcheckbox($elementName=null, $elementLabel=null, $text=null, $attributes=null, $values=null)
  53. {
  54. if ($values === null){
  55. $values = array(0, 1);
  56. }
  57. if (!is_null($attributes['group'])) {
  58. $this->_group = 'checkboxgroup' . $attributes['group'];
  59. unset($attributes['group']);
  60. if (is_null($attributes)) {
  61. $attributes = array();
  62. $attributes['class'] .= " $this->_group";
  63. } elseif (is_array($attributes)) {
  64. if (isset($attributes['class'])) {
  65. $attributes['class'] .= " $this->_group";
  66. } else {
  67. $attributes['class'] = $this->_group;
  68. }
  69. } elseif ($strpos = stripos($attributes, 'class="')) {
  70. $attributes = str_ireplace('class="', 'class="' . $this->_group . ' ', $attributes);
  71. } else {
  72. $attributes .= ' class="' . $this->_group . '"';
  73. }
  74. }
  75. parent::HTML_QuickForm_advcheckbox($elementName, $elementLabel, $text, $attributes, $values);
  76. }
  77. /**
  78. * set html for help button
  79. *
  80. * @param array $helpbuttonargs array of arguments to make a help button
  81. * @param string $function (optional)function name get help html
  82. * @deprecated since Moodle 2.0. Please do not call this function any more.
  83. * @todo MDL-31047 this api will be removed.
  84. * @see MoodleQuickForm::setHelpButton()
  85. */
  86. function setHelpButton($helpbuttonargs, $function='helpbutton'){
  87. debugging('component setHelpButton() is not used any more, please use $mform->setHelpButton() instead');
  88. }
  89. /**
  90. * get html for help button
  91. *
  92. * @return string html for help button
  93. */
  94. function getHelpButton(){
  95. return $this->_helpbutton;
  96. }
  97. /**
  98. * Returns HTML for advchecbox form element.
  99. *
  100. * @return string
  101. */
  102. function toHtml()
  103. {
  104. return '<span>' . parent::toHtml() . '</span>';
  105. }
  106. /**
  107. * Returns the disabled field. Accessibility: the return "[ ]" from parent
  108. * class is not acceptable for screenreader users, and we DO want a label.
  109. *
  110. * @return string
  111. */
  112. function getFrozenHtml()
  113. {
  114. //$this->_generateId();
  115. $output = '<input type="checkbox" disabled="disabled" id="'.$this->getAttribute('id').'" ';
  116. if ($this->getChecked()) {
  117. $output .= 'checked="checked" />'.$this->_getPersistantData();
  118. } else {
  119. $output .= '/>';
  120. }
  121. return $output;
  122. }
  123. }