Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 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
namespace core_course\output\actionbar;
18
 
19
use core\output\named_templatable;
20
use core\output\renderable;
21
use core\output\renderer_base;
22
use core\url;
23
use stdClass;
24
 
25
/**
26
 * Renderable class for the user_selector_button.
27
 *
28
 * This is the button content for the user_selector renderable, which itself is an extension of the comboboxsearch component.
29
 * {@see initials_selector}.
30
 *
31
 * @package    core_course
32
 * @copyright  2024 Jake Dallimore <jrhdallimore@gmail.com>
33
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34
 */
35
class user_selector_button implements renderable, named_templatable {
36
 
37
    /**
38
     * The class constructor.
39
     */
40
    public function __construct(
41
        private stdClass $course,
42
        private url $resetlink,
43
        private ?int $userid = null,
44
        private ?int $groupid = null,
45
        private string $usersearch = '',
46
        private ?int $instanceid = null
47
    ) {
48
        // If the user ID is set, it indicates that a user has been selected. In this case, override the user search
49
        // string with the full name of the selected user.
50
        if ($this->userid) {
51
            $this->usersearch = fullname(\core_user::get_user($this->userid));
52
        }
53
    }
54
 
55
    public function export_for_template(renderer_base $output) {
56
        return [
57
            'currentvalue' => $this->usersearch,
58
            'courseid' => $this->course->id,
59
            'instance' => $this->instanceid ?? rand(),
60
            'resetlink' => $this->resetlink->out(false),
61
            'group' => $this->groupid ?? 0,
62
            'name' => 'usersearch',
63
            'value' => json_encode([
64
                'userid' => $this->userid,
65
                'search' => $this->usersearch,
66
            ]),
67
        ];
68
    }
69
 
70
    public function get_template_name(renderer_base $renderer): string {
71
        return 'core_user/comboboxsearch/user_selector';
72
    }
73
}