[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/form/ -> advcheckbox.php (source)

   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  
  18  /**
  19   * Advanced checkbox type form element
  20   *
  21   * Contains HTML class for an advcheckbox type form element
  22   *
  23   * @package   core_form
  24   * @copyright 2007 Jamie Pratt <me@jamiep.org>
  25   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  26   */
  27  
  28  require_once('HTML/QuickForm/advcheckbox.php');
  29  
  30  /**
  31   * HTML class for an advcheckbox type element
  32   *
  33   * Overloaded {@link HTML_QuickForm_advcheckbox} with default behavior modified for Moodle.
  34   * This will return '0' if not checked and '1' if checked.
  35   *
  36   * @package   core_form
  37   * @category  form
  38   * @copyright 2007 Jamie Pratt <me@jamiep.org>
  39   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  40   */
  41  class MoodleQuickForm_advcheckbox extends HTML_QuickForm_advcheckbox{
  42      /** @var string html for help button, if empty then no help will icon will be dispalyed. */
  43      var $_helpbutton='';
  44  
  45      /** @var string Group to which this checkbox belongs (for select all/select none button) */
  46      var $_group;
  47  
  48      /**
  49       * constructor
  50       *
  51       * @param string $elementName (optional) name of the checkbox
  52       * @param string $elementLabel (optional) checkbox label
  53       * @param string $text (optional) Text to put after the checkbox
  54       * @param mixed $attributes (optional) Either a typical HTML attribute string
  55       *              or an associative array
  56       * @param mixed $values (optional) Values to pass if checked or not checked
  57       */
  58      public function __construct($elementName=null, $elementLabel=null, $text=null, $attributes=null, $values=null)
  59      {
  60          if ($values === null){
  61              $values = array(0, 1);
  62          }
  63  
  64          if (!empty($attributes['group'])) {
  65  
  66              $this->_group = 'checkboxgroup' . $attributes['group'];
  67              unset($attributes['group']);
  68              if (is_null($attributes)) {
  69                  $attributes = array();
  70                  $attributes['class'] .= " $this->_group";
  71              } elseif (is_array($attributes)) {
  72                  if (isset($attributes['class'])) {
  73                      $attributes['class'] .= " $this->_group";
  74                  } else {
  75                      $attributes['class'] = $this->_group;
  76                  }
  77              } elseif ($strpos = stripos($attributes, 'class="')) {
  78                  $attributes = str_ireplace('class="', 'class="' . $this->_group . ' ', $attributes);
  79              } else {
  80                  $attributes .= ' class="' . $this->_group . '"';
  81              }
  82          }
  83  
  84          parent::__construct($elementName, $elementLabel, $text, $attributes, $values);
  85      }
  86  
  87      /**
  88       * Old syntax of class constructor. Deprecated in PHP7.
  89       *
  90       * @deprecated since Moodle 3.1
  91       */
  92      public function MoodleQuickForm_advcheckbox($elementName=null, $elementLabel=null, $text=null, $attributes=null, $values=null) {
  93          debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
  94          self::__construct($elementName, $elementLabel, $text, $attributes, $values);
  95      }
  96  
  97      /**
  98       * get html for help button
  99       *
 100       * @return string html for help button
 101       */
 102      function getHelpButton(){
 103          return $this->_helpbutton;
 104      }
 105  
 106      /**
 107       * Returns HTML for advchecbox form element.
 108       *
 109       * @return string
 110       */
 111      function toHtml()
 112      {
 113          return '<span>' . parent::toHtml() . '</span>';
 114      }
 115  
 116      /**
 117       * Returns the disabled field. Accessibility: the return "[ ]" from parent
 118       * class is not acceptable for screenreader users, and we DO want a label.
 119       *
 120       * @return string
 121       */
 122      function getFrozenHtml()
 123      {
 124          //$this->_generateId();
 125          $output = '<input type="checkbox" disabled="disabled" id="'.$this->getAttribute('id').'" ';
 126          if ($this->getChecked()) {
 127              $output .= 'checked="checked" />'.$this->_getPersistantData();
 128          } else {
 129              $output .= '/>';
 130          }
 131          return $output;
 132      }
 133  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1