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 * Searchable selector field (alias for autocomplete).
20 *
21 * Allows auto-complete selector.
22 *
23 * @package   core_form
24 * @copyright 2015 Damyon Wiese <damyon@moodle.com>
25 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 */
27
28global $CFG;
29require_once($CFG->libdir . '/form/autocomplete.php');
30
31/**
32 * Form field type for selecting from a list of options.
33 *
34 * Allows auto-complete ajax searching.
35 *
36 * @package   core_form
37 * @copyright 2015 Damyon Wiese <damyon@moodle.com>
38 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39 */
40class MoodleQuickForm_searchableselector extends MoodleQuickForm_autocomplete {
41
42    /**
43     * Constructor
44     *
45     * @param string $elementname Element name
46     * @param mixed $elementlabel Label(s) for an element
47     * @param array $options List of valid options for the select
48     * @param array $attributes List of HTML attributes for the select
49     */
50    public function __construct($elementname = null, $elementlabel = null, $options = [], $attributes = []) {
51        unset($options['']);
52        $options = ['' => get_string('noselection', 'form')] + $options;
53        parent::__construct($elementname, $elementlabel, $options, $attributes);
54    }
55
56    /**
57     * Old syntax of class constructor. Deprecated in PHP7.
58     *
59     * @deprecated since Moodle 3.1
60     */
61    public function MoodleQuickForm_searchableselector($elementName=null, $elementLabel=null, $options=null, $attributes=null) {
62        debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
63        self::__construct($elementName, $elementLabel, $options, $attributes);
64    }
65}
66