Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.
   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   * Yes/No (boolean) filter.
  19   *
  20   * @package   core_user
  21   * @category  user
  22   * @copyright 1999 Martin Dougiamas  http://dougiamas.com
  23   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  /**
  27   * Generic yes/no filter with radio buttons for integer fields.
  28   * @copyright 1999 Martin Dougiamas  http://dougiamas.com
  29   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  30   */
  31  class user_filter_yesno extends user_filter_simpleselect {
  32  
  33      /**
  34       * Constructor
  35       * @param string $name the name of the filter instance
  36       * @param string $label the label of the filter instance
  37       * @param boolean $advanced advanced form element flag
  38       * @param string $field user table filed name
  39       */
  40      public function __construct($name, $label, $advanced, $field) {
  41          parent::__construct($name, $label, $advanced, $field, array(0 => get_string('no'), 1 => get_string('yes')));
  42      }
  43  
  44      /**
  45       * Old syntax of class constructor. Deprecated in PHP7.
  46       *
  47       * @deprecated since Moodle 3.1
  48       */
  49      public function user_filter_yesno($name, $label, $advanced, $field) {
  50          debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
  51          self::__construct($name, $label, $advanced, $field);
  52      }
  53  
  54      /**
  55       * Returns the condition to be used with SQL
  56       *
  57       * @param array $data filter settings
  58       * @return array sql string and $params
  59       */
  60      public function get_sql_filter($data) {
  61          static $counter = 0;
  62          $name = 'ex_yesno'.$counter++;
  63  
  64          $value = $data['value'];
  65          $field = $this->_field;
  66          if ($value == '') {
  67              return array();
  68          }
  69          return array("$field=:$name", array($name => $value));
  70      }
  71  }