From 8b2f9b0386b504142ea5d2a155e0f89cf8bb90e0 Mon Sep 17 00:00:00 2001 From: Mihail Geshoski Date: Sat, 8 Oct 2022 00:12:42 +0800 Subject: [PATCH] MDL-75513 core_grades: Create trigger element for the group selector Creates a renderer method and a template for the element that would trigger the group selector. --- grade/renderer.php | 45 +++++++++++++++++++++++ grade/templates/group_selector.mustache | 49 +++++++++++++++++++++++++ lang/en/moodle.php | 2 + 3 files changed, 96 insertions(+) create mode 100644 grade/templates/group_selector.mustache diff --git a/grade/renderer.php b/grade/renderer.php index ceb5ab92fc4..8a595a875ca 100644 --- a/grade/renderer.php +++ b/grade/renderer.php @@ -37,4 +37,49 @@ class core_grades_renderer extends plugin_renderer_base { $data = $actionbar->export_for_template($this); return $this->render_from_template($actionbar->get_template(), $data); } + + /** + * Renders the group selector trigger element. + * + * @param object $course The course object. + * @param string|null $groupactionbaseurl The base URL for the group action. + * @return string|null The raw HTML to render. + */ + public function group_selector(object $course, ?string $groupactionbaseurl = null): ?string { + global $USER; + + // Make sure that group mode is enabled. + if (!$groupmode = $course->groupmode) { + return null; + } + + $label = $groupmode == VISIBLEGROUPS ? get_string('selectgroupsvisible') : + get_string('selectgroupsseparate'); + + $data = [ + 'label' => $label, + 'courseid' => $course->id, + 'groupactionbaseurl' => $groupactionbaseurl + ]; + + $context = context_course::instance($course->id); + + if ($groupmode == VISIBLEGROUPS || has_capability('moodle/site:accessallgroups', $context)) { + $allowedgroups = groups_get_all_groups($course->id, 0, $course->defaultgroupingid); + } else { + $allowedgroups = groups_get_all_groups($course->id, $USER->id, $course->defaultgroupingid); + } + + $activegroup = groups_get_course_group($course, true, $allowedgroups); + + if ($activegroup) { + $group = groups_get_group($activegroup); + $data['selectedgroup'] = $group->name; + } else if ($activegroup === 0) { + $data['selectedgroup'] = get_string('allparticipants'); + } + + $this->page->requires->js_call_amd('core_grades/searchwidget/group', 'init'); + return $this->render_from_template('core_grades/group_selector', $data); + } } diff --git a/grade/templates/group_selector.mustache b/grade/templates/group_selector.mustache new file mode 100644 index 00000000000..7adef07653d --- /dev/null +++ b/grade/templates/group_selector.mustache @@ -0,0 +1,49 @@ +{{! + This file is part of Moodle - http://moodle.org/ + + Moodle is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Moodle is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Moodle. If not, see . +}} +{{! + @template core_grades/group_selector + + The group selector trigger element. + + Context variables required for this template: + * label - The label text fot the group selector element. + * courseid - The course ID. + * groupactionbaseurl - The base URL for the group action. + * selectedgroup - The text of the selected group option. + + Example context (json): + { + "label": "Select separate groups", + "courseid": "2", + "groupactionbaseurl": "index.php?item=test", + "selectedgroup": "Group 1" + } +}} +
+ +
diff --git a/lang/en/moodle.php b/lang/en/moodle.php index c36f447ff46..c436ec1d28e 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -1939,6 +1939,8 @@ $string['selectedcategories'] = 'Selected categories'; $string['selectednowmove'] = '{$a} files selected for moving. Now go into the destination folder and press \'Move files to here\''; $string['selectfiles'] = 'Select files'; $string['selectfiltertype'] = 'Select'; +$string['selectgroupsseparate'] = 'Select separate groups'; +$string['selectgroupsvisible'] = 'Select visible groups'; $string['selectitem'] = 'Select \'{$a}\''; $string['selectmoduletoviewhelp'] = 'Select an activity or resource to view its help.