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\comboboxsearch;
20
use moodle_url;
21
use stdClass;
22
 
23
/**
24
 * Renderable class for the user selector element in the action bar.
25
 *
26
 * @package    core_course
27
 * @copyright  2024 Ilya Tregubov <ilyatregubov@proton.me>
28
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29
 */
30
class user_selector extends comboboxsearch {
31
 
32
    /**
33
     * The class constructor.
34
     *
35
     * @param stdClass $course The course object.
36
     * @param moodle_url $resetlink The reset link.
37
     * @param int|null $userid The user ID.
38
     * @param int|null $groupid The group ID.
39
     * @param string $usersearch The user search query.
40
     * @param int|null $instanceid The instance ID.
41
     */
42
    public function __construct(
43
        private stdClass $course,
44
        private moodle_url $resetlink,
45
        private ?int $userid = null,
46
        private ?int $groupid = null,
47
        private string $usersearch = '',
48
        private ?int $instanceid = null
49
    ) {
50
        // The second argument (buttoncontent) needs to be rendered here, since the comboboxsearch
51
        // template expects HTML in its respective context properties. Ideally, children of comboboxsearch would leverage Mustache's
52
        // blocks pragma, meaning a child template could extend the comboboxsearch, allowing rendering of the child component,
53
        // instead of needing to inject the child's content HTML as part of rendering the comboboxsearch parent, as is the case
54
        // here. Achieving this, however, requires a refactor of comboboxsearch. For now, this must be pre-rendered and injected.
55
        parent::__construct(true, $this->user_selector_output(), null, 'user-search d-flex',
56
            null, 'usersearchdropdown overflow-auto', null, false);
57
    }
58
 
59
    /**
60
     * Method that generates the output for the user selector.
61
     *
62
     * @return string The HTML output.
63
     */
64
    private function user_selector_output(): string {
65
        global $PAGE;
66
 
67
        $userselectordropdown = new user_selector_button(
68
            $this->course,
69
            $this->resetlink,
70
            $this->userid,
71
            $this->groupid,
72
            $this->usersearch,
73
            $this->instanceid
74
        );
75
        return $PAGE->get_renderer('core', 'course')->render($userselectordropdown);
76
    }
77
}