mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
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.
This commit is contained in:
parent
c2851ed141
commit
8b2f9b0386
@ -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);
|
||||
}
|
||||
}
|
||||
|
49
grade/templates/group_selector.mustache
Normal file
49
grade/templates/group_selector.mustache
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||
}}
|
||||
{{!
|
||||
@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"
|
||||
}
|
||||
}}
|
||||
<div class="group-selector d-flex">
|
||||
<div role="button" class="groupwidget btn dropdown-toggle d-flex text-left align-items-center p-0" data-courseid="{{courseid}}" data-action-base-url="{{groupactionbaseurl}}" data-searchtype="group" tabindex="0">
|
||||
<div class="align-items-center d-flex">
|
||||
<div class="d-block pr-3">
|
||||
<span class="d-block small">
|
||||
{{label}}
|
||||
</span>
|
||||
<span class="p-0 font-weight-bold">
|
||||
{{selectedgroup}}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
@ -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.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user