MDL-64285 core: Fix environment check test
[moodle.git] / user / filters / yesno.php
blob5dadd8050087ce0ae5c3bf3779ed244a5bfaa237
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.
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/>.
17 /**
18 * Yes/No (boolean) filter.
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
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
31 class user_filter_yesno extends user_filter_simpleselect {
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
40 public function __construct($name, $label, $advanced, $field) {
41 parent::__construct($name, $label, $advanced, $field, array(0 => get_string('no'), 1 => get_string('yes')));
44 /**
45 * Old syntax of class constructor. Deprecated in PHP7.
47 * @deprecated since Moodle 3.1
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);
54 /**
55 * Returns the condition to be used with SQL
57 * @param array $data filter settings
58 * @return array sql string and $params
60 public function get_sql_filter($data) {
61 static $counter = 0;
62 $name = 'ex_yesno'.$counter++;
64 $value = $data['value'];
65 $field = $this->_field;
66 if ($value == '') {
67 return array();
69 return array("$field=:$name", array($name => $value));