mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 20:42:22 +02:00
MDL-80745 core_course: group selector renderer for actionbar in course
This commit is contained in:
parent
2bf886f9dd
commit
37eae68cdb
11
course/amd/build/actionbar/group.min.js
vendored
Normal file
11
course/amd/build/actionbar/group.min.js
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
define("core_course/actionbar/group",["exports","core_group/comboboxsearch/group"],(function(_exports,_group){var obj;Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,_group=(obj=_group)&&obj.__esModule?obj:{default:obj};
|
||||
/**
|
||||
* Allow the user to search for groups in the action bar.
|
||||
*
|
||||
* @module core_course/actionbar/group
|
||||
* @copyright 2024 Shamim Rezaie <shamim@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class Group extends _group.default{constructor(baseUrl){super(),function(obj,key,value){key in obj?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value}(this,"baseUrl",void 0),this.baseUrl=baseUrl}static init(baseUrl){return new Group(baseUrl)}selectOneLink(groupID){const url=new URL(this.baseUrl);return url.searchParams.set("groupsearchvalue",this.getSearchTerm()),url.searchParams.set("group",groupID),url.toString()}}return _exports.default=Group,_exports.default}));
|
||||
|
||||
//# sourceMappingURL=group.min.js.map
|
1
course/amd/build/actionbar/group.min.js.map
Normal file
1
course/amd/build/actionbar/group.min.js.map
Normal file
@ -0,0 +1 @@
|
||||
{"version":3,"file":"group.min.js","sources":["../../src/actionbar/group.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\nimport GroupSearch from 'core_group/comboboxsearch/group';\n\n/**\n * Allow the user to search for groups in the action bar.\n *\n * @module core_course/actionbar/group\n * @copyright 2024 Shamim Rezaie <shamim@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nexport default class Group extends GroupSearch {\n\n baseUrl;\n\n /**\n * Construct the class.\n * @param {string} baseUrl The base URL for the page.\n */\n constructor(baseUrl) {\n super();\n this.baseUrl = baseUrl;\n }\n\n /**\n * Allow the class to be invoked via PHP.\n *\n * @param {string} baseUrl The base URL for the page.\n * @returns {Group}\n */\n static init(baseUrl) {\n return new Group(baseUrl);\n }\n\n /**\n * Build up the link that is dedicated to a particular result.\n *\n * @param {Number} groupID The ID of the group selected.\n * @returns {string}\n */\n selectOneLink(groupID) {\n const url = new URL(this.baseUrl);\n url.searchParams.set('groupsearchvalue', this.getSearchTerm());\n url.searchParams.set('group', groupID);\n\n return url.toString();\n }\n}\n"],"names":["Group","GroupSearch","constructor","baseUrl","selectOneLink","groupID","url","URL","this","searchParams","set","getSearchTerm","toString"],"mappings":";;;;;;;;MAwBqBA,cAAcC,eAQ/BC,YAAYC,uLAEHA,QAAUA,oBASPA,gBACD,IAAIH,MAAMG,SASrBC,cAAcC,eACJC,IAAM,IAAIC,IAAIC,KAAKL,gBACzBG,IAAIG,aAAaC,IAAI,mBAAoBF,KAAKG,iBAC9CL,IAAIG,aAAaC,IAAI,QAASL,SAEvBC,IAAIM"}
|
61
course/amd/src/actionbar/group.js
Normal file
61
course/amd/src/actionbar/group.js
Normal file
@ -0,0 +1,61 @@
|
||||
// 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/>.
|
||||
|
||||
import GroupSearch from 'core_group/comboboxsearch/group';
|
||||
|
||||
/**
|
||||
* Allow the user to search for groups in the action bar.
|
||||
*
|
||||
* @module core_course/actionbar/group
|
||||
* @copyright 2024 Shamim Rezaie <shamim@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
export default class Group extends GroupSearch {
|
||||
|
||||
baseUrl;
|
||||
|
||||
/**
|
||||
* Construct the class.
|
||||
* @param {string} baseUrl The base URL for the page.
|
||||
*/
|
||||
constructor(baseUrl) {
|
||||
super();
|
||||
this.baseUrl = baseUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow the class to be invoked via PHP.
|
||||
*
|
||||
* @param {string} baseUrl The base URL for the page.
|
||||
* @returns {Group}
|
||||
*/
|
||||
static init(baseUrl) {
|
||||
return new Group(baseUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build up the link that is dedicated to a particular result.
|
||||
*
|
||||
* @param {Number} groupID The ID of the group selected.
|
||||
* @returns {string}
|
||||
*/
|
||||
selectOneLink(groupID) {
|
||||
const url = new URL(this.baseUrl);
|
||||
url.searchParams.set('groupsearchvalue', this.getSearchTerm());
|
||||
url.searchParams.set('group', groupID);
|
||||
|
||||
return url.toString();
|
||||
}
|
||||
}
|
113
course/classes/output/actionbar/group_selector.php
Normal file
113
course/classes/output/actionbar/group_selector.php
Normal file
@ -0,0 +1,113 @@
|
||||
<?php
|
||||
// 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/>.
|
||||
|
||||
namespace core_course\output\actionbar;
|
||||
|
||||
use core\output\comboboxsearch;
|
||||
use renderable;
|
||||
use renderer_base;
|
||||
use stdClass;
|
||||
use templatable;
|
||||
|
||||
/**
|
||||
* Renderable class for the group selector element in the action bar.
|
||||
*
|
||||
* @package core_course
|
||||
* @copyright 2024 Shamim Rezaie <shamim@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class group_selector implements renderable, templatable {
|
||||
|
||||
/**
|
||||
* @var stdClass The course object.
|
||||
*/
|
||||
protected $course;
|
||||
|
||||
/**
|
||||
* The class constructor.
|
||||
*
|
||||
* @param stdClass $course The course object.
|
||||
*/
|
||||
public function __construct(stdClass $course) {
|
||||
$this->course = $course;
|
||||
}
|
||||
|
||||
/**
|
||||
* Export the data for the mustache template.
|
||||
*
|
||||
* @param renderer_base $output The renderer that will be used to render the output.
|
||||
* @return array
|
||||
*/
|
||||
public function export_for_template(renderer_base $output) {
|
||||
global $USER, $OUTPUT;
|
||||
|
||||
$course = $this->course;
|
||||
$groupmode = $course->groupmode;
|
||||
|
||||
$sbody = $OUTPUT->render_from_template('core_group/comboboxsearch/searchbody', [
|
||||
'courseid' => $course->id,
|
||||
'currentvalue' => optional_param('groupsearchvalue', '', PARAM_NOTAGS),
|
||||
'instance' => rand(),
|
||||
]);
|
||||
|
||||
$label = $groupmode == VISIBLEGROUPS ? get_string('selectgroupsvisible') : get_string('selectgroupsseparate');
|
||||
|
||||
$buttondata = ['label' => $label];
|
||||
|
||||
$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);
|
||||
$buttondata['group'] = $activegroup;
|
||||
|
||||
if ($activegroup) {
|
||||
$group = groups_get_group($activegroup);
|
||||
$buttondata['selectedgroup'] = format_string($group->name, true, ['context' => $context]);
|
||||
} else if ($activegroup === 0) {
|
||||
$buttondata['selectedgroup'] = get_string('allparticipants');
|
||||
}
|
||||
|
||||
$groupdropdown = new comboboxsearch(
|
||||
false,
|
||||
$OUTPUT->render_from_template('core_group/comboboxsearch/group_selector', $buttondata),
|
||||
$sbody,
|
||||
'group-search',
|
||||
'groupsearchwidget',
|
||||
'groupsearchdropdown overflow-auto',
|
||||
null,
|
||||
true,
|
||||
$label,
|
||||
'group',
|
||||
$activegroup
|
||||
);
|
||||
|
||||
return $groupdropdown->export_for_template($OUTPUT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the template for the group selector.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_template(): string {
|
||||
return 'core/comboboxsearch';
|
||||
}
|
||||
}
|
38
course/classes/output/actionbar/renderer.php
Normal file
38
course/classes/output/actionbar/renderer.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
// 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/>.
|
||||
|
||||
namespace core_course\output\actionbar;
|
||||
|
||||
/**
|
||||
* Renderer class for the action bar.
|
||||
*
|
||||
* @package core_course
|
||||
* @copyright 2024 Shamim Rezaie <shamim@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class renderer extends \plugin_renderer_base {
|
||||
|
||||
/**
|
||||
* Renders the group selector trigger element in the action bar.
|
||||
*
|
||||
* @param group_selector $groupselector The group selector object.
|
||||
* @return string The HTML output.
|
||||
*/
|
||||
protected function render_group_selector(group_selector $groupselector) {
|
||||
$data = $groupselector->export_for_template($this);
|
||||
return parent::render_from_template($groupselector->get_template(), $data);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user