2 // This file is part of Moodle - https://moodle.org/
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.
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/>.
18 * Provides the {@see core_webservice\token_filter} class.
20 * @package core_webservice
21 * @copyright 2020 David Mudrák <david@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 namespace core_webservice
;
30 * Form allowing to filter displayed tokens.
32 * @copyright 2020 David Mudrák <david@moodle.com>
33 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35 class token_filter
extends moodleform
{
38 * Defines the form fields.
40 public function definition() {
43 $mform = $this->_form
;
44 $presetdata = $this->_customdata
;
46 $mform->addElement('header', 'tokenfilter', get_string('tokenfilter', 'webservice'));
48 if (empty($presetdata->token
) && empty($presetdata->users
) && empty($presetdata->services
)) {
49 $mform->setExpanded('tokenfilter', false);
51 $mform->setExpanded('tokenfilter', true);
55 $mform->addElement('text', 'token', get_string('token', 'core_webservice'), ['size' => 32]);
56 $mform->setType('token', PARAM_ALPHANUM
);
61 'ajax' => 'core_user/form_user_selector',
62 'valuehtmlcallback' => function($userid) {
65 $context = \context_system
::instance();
66 $fields = \core_user\fields
::for_name()->with_identity($context, false);
67 $record = \core_user
::get_user($userid, 'id' . $fields->get_sql()->selects
, MUST_EXIST
);
71 'fullname' => fullname($record, has_capability('moodle/site:viewfullnames', $context)),
75 foreach ($fields->get_required_fields([\core_user\fields
::PURPOSE_IDENTITY
]) as $extrafield) {
76 $user->extrafields
[] = (object)[
77 'name' => $extrafield,
78 'value' => s($record->$extrafield)
82 return $OUTPUT->render_from_template('core_user/form_user_selector_suggestion', $user);
85 $mform->addElement('autocomplete', 'users', get_string('user'), [], $attributes);
88 $options = $DB->get_records_menu('external_services', null, '', 'id, name');
92 $mform->addElement('autocomplete', 'services', get_string('service', 'webservice'), $options, $attributes);
96 $mform->createElement('submit', 'submitbutton', get_string('tokenfiltersubmit', 'core_webservice')),
97 $mform->createElement('submit', 'resetbutton', get_string('tokenfilterreset', 'core_webservice'), [], false),
98 ], 'actionbuttons', '', ' ', false);