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 context;
|
|
|
20 |
use core\output\named_templatable;
|
|
|
21 |
use core\output\renderable;
|
|
|
22 |
use core\output\renderer_base;
|
|
|
23 |
|
|
|
24 |
/**
|
|
|
25 |
* Renderable class for the group selection button state.
|
|
|
26 |
*
|
|
|
27 |
* This form is the button state for the group_selector renderable, which itself is an extension of the comboboxsearch component.
|
|
|
28 |
* {@see group_selector}.
|
|
|
29 |
*
|
|
|
30 |
* @package core_course
|
|
|
31 |
* @copyright 2024 Jake Dallimore <jrhdallimore@gmail.com>
|
|
|
32 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
33 |
*/
|
|
|
34 |
class group_selector_button implements renderable, named_templatable {
|
|
|
35 |
|
|
|
36 |
/**
|
|
|
37 |
* The class constructor.
|
|
|
38 |
*
|
|
|
39 |
* @param context $context The context instance.
|
|
|
40 |
* @param int|bool $activegroup The active group, or false if groups not used.
|
|
|
41 |
* @param string $label the label string.
|
|
|
42 |
*/
|
|
|
43 |
public function __construct(
|
|
|
44 |
protected context $context,
|
|
|
45 |
protected int|bool $activegroup,
|
|
|
46 |
protected string $label
|
|
|
47 |
) {
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
public function export_for_template(renderer_base $output) {
|
|
|
51 |
$context = [
|
|
|
52 |
'label' => $this->label,
|
|
|
53 |
'group' => $this->activegroup,
|
|
|
54 |
];
|
|
|
55 |
|
|
|
56 |
if ($this->activegroup) {
|
|
|
57 |
$group = groups_get_group($this->activegroup);
|
|
|
58 |
$context['selectedgroup'] = format_string($group->name, true, ['context' => $this->context->get_course_context()]);
|
|
|
59 |
} else if ($this->activegroup === 0) {
|
|
|
60 |
$context['selectedgroup'] = get_string('allparticipants');
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
return $context;
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
public function get_template_name(renderer_base $renderer): string {
|
|
|
67 |
return 'core_group/comboboxsearch/group_selector';
|
|
|
68 |
}
|
|
|
69 |
}
|