MDL-76246 core_grades: Remove url param from ws

This commit is contained in:
Shamim Rezaie 2023-02-03 02:45:02 +11:00
parent 1a01607463
commit 02471ef1cd
21 changed files with 359 additions and 46 deletions

View File

@ -5,6 +5,6 @@ define("core_grades/searchwidget/group",["exports","core/local/aria/focuslock","
* @module core_grades/searchwidget/group
* @copyright 2022 Mathew May <mathew.solutions>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,FocusLockManager=_interopRequireWildcard(FocusLockManager),_pending=_interopRequireDefault(_pending),Templates=_interopRequireWildcard(Templates),Repository=_interopRequireWildcard(Repository),WidgetBase=_interopRequireWildcard(WidgetBase),_jquery=_interopRequireDefault(_jquery),Selectors=_interopRequireWildcard(Selectors);let initialised=!1;_exports.init=()=>{if(!initialised&&document.querySelector(Selectors.elements.getSearchWidgetSelector("group"))){const pendingPromise=new _pending.default;registerListenerEvents(),pendingPromise.resolve()}initialised=!0};const registerListenerEvents=()=>{let{bodyPromiseResolver:bodyPromiseResolver,bodyPromise:bodyPromise}=WidgetBase.promisesAndResolvers();const dropdownMenuContainer=document.querySelector(Selectors.elements.getSearchWidgetDropdownSelector("group")),menuContainer=document.querySelector(Selectors.elements.getSearchWidgetSelector("group")),inputElement=menuContainer.querySelector('input[name="group"]');(0,_jquery.default)(menuContainer).on("show.bs.dropdown",(async e=>{const courseID=e.relatedTarget.dataset.courseid,actionBaseUrl=e.relatedTarget.dataset.actionBaseUrl;await WidgetBase.showLoader(dropdownMenuContainer);const data=await Repository.groupFetch(courseID,actionBaseUrl).catch((async e=>{const errorTemplateData={errormessage:e.message};bodyPromiseResolver(await Templates.render("core_grades/searchwidget/error",errorTemplateData))}));data!==[]&&(await WidgetBase.init(dropdownMenuContainer,bodyPromise,data.groups,searchGroups(),null,afterSelect),FocusLockManager.trapFocus(dropdownMenuContainer))})),bodyPromiseResolver(Templates.render("core_grades/searchwidget/group/groupsearch_body",[])),(0,_jquery.default)(menuContainer).on("hide.bs.dropdown",(()=>{FocusLockManager.untrapFocus()})),inputElement.addEventListener("change",(e=>{const toggle=menuContainer.querySelector(".dropdown-toggle"),courseId=toggle.dataset.courseid,actionUrl=toggle.dataset.actionBaseUrl?new URL(toggle.dataset.actionBaseUrl.replace(/&amp;/g,"&")):new URL(location.href);actionUrl.searchParams.set("id",courseId),actionUrl.searchParams.set("group",e.target.value),location.href=actionUrl.href,e.stopPropagation()}))},searchGroups=()=>()=>(groups,searchTerm)=>{if(""===searchTerm)return groups;searchTerm=searchTerm.toLowerCase();const searchResults=[];return groups.forEach((group=>{group.name.toLowerCase().includes(searchTerm)&&searchResults.push(group)})),searchResults},afterSelect=selected=>{const menuContainer=document.querySelector(Selectors.elements.getSearchWidgetSelector("group")),inputElement=menuContainer.querySelector('input[name="group"]');(0,_jquery.default)(menuContainer).dropdown("hide"),inputElement.value!=selected&&(inputElement.value=selected,inputElement.dispatchEvent(new Event("change",{bubbles:!0})))}}));
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,FocusLockManager=_interopRequireWildcard(FocusLockManager),_pending=_interopRequireDefault(_pending),Templates=_interopRequireWildcard(Templates),Repository=_interopRequireWildcard(Repository),WidgetBase=_interopRequireWildcard(WidgetBase),_jquery=_interopRequireDefault(_jquery),Selectors=_interopRequireWildcard(Selectors);let initialised=!1;_exports.init=()=>{if(!initialised&&document.querySelector(Selectors.elements.getSearchWidgetSelector("group"))){const pendingPromise=new _pending.default;registerListenerEvents(),pendingPromise.resolve()}initialised=!0};const registerListenerEvents=()=>{let{bodyPromiseResolver:bodyPromiseResolver,bodyPromise:bodyPromise}=WidgetBase.promisesAndResolvers();const dropdownMenuContainer=document.querySelector(Selectors.elements.getSearchWidgetDropdownSelector("group")),menuContainer=document.querySelector(Selectors.elements.getSearchWidgetSelector("group")),inputElement=menuContainer.querySelector('input[name="group"]');(0,_jquery.default)(menuContainer).on("show.bs.dropdown",(async e=>{const courseID=e.relatedTarget.dataset.courseid;await WidgetBase.showLoader(dropdownMenuContainer);const data=await Repository.groupFetch(courseID).catch((async e=>{const errorTemplateData={errormessage:e.message};bodyPromiseResolver(await Templates.render("core_grades/searchwidget/error",errorTemplateData))}));data!==[]&&(await WidgetBase.init(dropdownMenuContainer,bodyPromise,data.groups,searchGroups(),null,afterSelect),FocusLockManager.trapFocus(dropdownMenuContainer))})),bodyPromiseResolver(Templates.render("core_grades/searchwidget/group/groupsearch_body",[])),(0,_jquery.default)(menuContainer).on("hide.bs.dropdown",(()=>{FocusLockManager.untrapFocus()})),inputElement.addEventListener("change",(e=>{const toggle=menuContainer.querySelector(".dropdown-toggle"),courseId=toggle.dataset.courseid,actionUrl=toggle.dataset.actionBaseUrl?new URL(toggle.dataset.actionBaseUrl.replace(/&amp;/g,"&")):new URL(location.href);actionUrl.searchParams.set("id",courseId),actionUrl.searchParams.set("group",e.target.value),location.href=actionUrl.href,e.stopPropagation()}))},searchGroups=()=>()=>(groups,searchTerm)=>{if(""===searchTerm)return groups;searchTerm=searchTerm.toLowerCase();const searchResults=[];return groups.forEach((group=>{group.name.toLowerCase().includes(searchTerm)&&searchResults.push(group)})),searchResults},afterSelect=selected=>{const menuContainer=document.querySelector(Selectors.elements.getSearchWidgetSelector("group")),inputElement=menuContainer.querySelector('input[name="group"]');(0,_jquery.default)(menuContainer).dropdown("hide"),inputElement.value!=selected&&(inputElement.value=selected,inputElement.dispatchEvent(new Event("change",{bubbles:!0})))}}));
//# sourceMappingURL=group.min.js.map

File diff suppressed because one or more lines are too long

View File

@ -5,6 +5,6 @@ define("core_grades/searchwidget/repository",["exports","core/ajax"],(function(_
* @module core_grades/searchwidget/repository
* @copyright 2022 Mathew May <mathew.solutions>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.userFetch=_exports.groupFetch=_exports.gradeitemFetch=void 0,_ajax=(obj=_ajax)&&obj.__esModule?obj:{default:obj};_exports.userFetch=(courseid,actionBaseUrl,groupId)=>{const request={methodname:"core_grades_get_enrolled_users_for_search_widget",args:{courseid:courseid,actionbaseurl:actionBaseUrl,groupid:groupId}};return _ajax.default.call([request])[0]};_exports.groupFetch=(courseid,actionBaseUrl)=>{const request={methodname:"core_grades_get_groups_for_search_widget",args:{courseid:courseid,actionbaseurl:actionBaseUrl}};return _ajax.default.call([request])[0]};_exports.gradeitemFetch=courseid=>{const request={methodname:"gradereport_singleview_get_grade_items_for_search_widget",args:{courseid:courseid}};return _ajax.default.call([request])[0]}}));
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.userFetch=_exports.groupFetch=_exports.gradeitemFetch=void 0,_ajax=(obj=_ajax)&&obj.__esModule?obj:{default:obj};_exports.userFetch=(courseid,groupId)=>{const request={methodname:"core_grades_get_enrolled_users_for_selector",args:{courseid:courseid,groupid:groupId}};return _ajax.default.call([request])[0]};_exports.groupFetch=courseid=>{const request={methodname:"core_grades_get_groups_for_selector",args:{courseid:courseid}};return _ajax.default.call([request])[0]};_exports.gradeitemFetch=courseid=>{const request={methodname:"gradereport_singleview_get_grade_items_for_search_widget",args:{courseid:courseid}};return _ajax.default.call([request])[0]}}));
//# sourceMappingURL=repository.min.js.map

View File

@ -1 +1 @@
{"version":3,"file":"repository.min.js","sources":["../../src/searchwidget/repository.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\n/**\n * A repo for the search widget.\n *\n * @module core_grades/searchwidget/repository\n * @copyright 2022 Mathew May <mathew.solutions>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport ajax from 'core/ajax';\n\n/**\n * Given a course ID, we want to fetch the enrolled learners, so we may fetch their reports.\n *\n * @method userFetch\n * @param {int} courseid ID of the course to fetch the users of.\n * @param {string} actionBaseUrl The base URL for the user option.\n * @param {int} groupId ID of the group to fetch the users of.\n * @return {object} jQuery promise\n */\nexport const userFetch = (courseid, actionBaseUrl, groupId) => {\n const request = {\n methodname: 'core_grades_get_enrolled_users_for_search_widget',\n args: {\n courseid: courseid,\n actionbaseurl: actionBaseUrl,\n groupid: groupId,\n },\n };\n return ajax.call([request])[0];\n};\n\n/**\n * Given a course ID, we want to fetch the groups, so we may fetch their users.\n *\n * @method groupFetch\n * @param {int} courseid ID of the course to fetch the users of.\n * @param {string} actionBaseUrl The base URL for the group action.\n * @return {object} jQuery promise\n */\nexport const groupFetch = (courseid, actionBaseUrl) => {\n const request = {\n methodname: 'core_grades_get_groups_for_search_widget',\n args: {\n courseid: courseid,\n actionbaseurl: actionBaseUrl,\n },\n };\n return ajax.call([request])[0];\n};\n\n/**\n * Given a course ID, we want to fetch the gradable items, so we may fetch reports based on activity items.\n * Note: This will be worked upon in the single view issue.\n *\n * @method gradeitemFetch\n * @param {int} courseid ID of the course to fetch the users of.\n * @return {object} jQuery promise\n */\nexport const gradeitemFetch = (courseid) => {\n const request = {\n methodname: 'gradereport_singleview_get_grade_items_for_search_widget',\n args: {\n courseid: courseid,\n },\n };\n return ajax.call([request])[0];\n};\n"],"names":["courseid","actionBaseUrl","groupId","request","methodname","args","actionbaseurl","groupid","ajax","call"],"mappings":";;;;;;;0MAkCyB,CAACA,SAAUC,cAAeC,iBACzCC,QAAU,CACZC,WAAY,mDACZC,KAAM,CACFL,SAAUA,SACVM,cAAeL,cACfM,QAASL,iBAGVM,cAAKC,KAAK,CAACN,UAAU,wBAWN,CAACH,SAAUC,uBAC3BE,QAAU,CACZC,WAAY,2CACZC,KAAM,CACFL,SAAUA,SACVM,cAAeL,uBAGhBO,cAAKC,KAAK,CAACN,UAAU,4BAWDH,iBACrBG,QAAU,CACZC,WAAY,2DACZC,KAAM,CACFL,SAAUA,kBAGXQ,cAAKC,KAAK,CAACN,UAAU"}
{"version":3,"file":"repository.min.js","sources":["../../src/searchwidget/repository.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\n/**\n * A repo for the search widget.\n *\n * @module core_grades/searchwidget/repository\n * @copyright 2022 Mathew May <mathew.solutions>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport ajax from 'core/ajax';\n\n/**\n * Given a course ID, we want to fetch the enrolled learners, so we may fetch their reports.\n *\n * @method userFetch\n * @param {int} courseid ID of the course to fetch the users of.\n * @param {int} groupId ID of the group to fetch the users of.\n * @return {object} jQuery promise\n */\nexport const userFetch = (courseid, groupId) => {\n const request = {\n methodname: 'core_grades_get_enrolled_users_for_selector',\n args: {\n courseid: courseid,\n groupid: groupId,\n },\n };\n return ajax.call([request])[0];\n};\n\n/**\n * Given a course ID, we want to fetch the groups, so we may fetch their users.\n *\n * @method groupFetch\n * @param {int} courseid ID of the course to fetch the users of.\n * @return {object} jQuery promise\n */\nexport const groupFetch = (courseid) => {\n const request = {\n methodname: 'core_grades_get_groups_for_selector',\n args: {\n courseid: courseid,\n },\n };\n return ajax.call([request])[0];\n};\n\n/**\n * Given a course ID, we want to fetch the gradable items, so we may fetch reports based on activity items.\n * Note: This will be worked upon in the single view issue.\n *\n * @method gradeitemFetch\n * @param {int} courseid ID of the course to fetch the users of.\n * @return {object} jQuery promise\n */\nexport const gradeitemFetch = (courseid) => {\n const request = {\n methodname: 'gradereport_singleview_get_grade_items_for_search_widget',\n args: {\n courseid: courseid,\n },\n };\n return ajax.call([request])[0];\n};\n"],"names":["courseid","groupId","request","methodname","args","groupid","ajax","call"],"mappings":";;;;;;;0MAiCyB,CAACA,SAAUC,iBAC1BC,QAAU,CACZC,WAAY,8CACZC,KAAM,CACFJ,SAAUA,SACVK,QAASJ,iBAGVK,cAAKC,KAAK,CAACL,UAAU,wBAULF,iBACjBE,QAAU,CACZC,WAAY,sCACZC,KAAM,CACFJ,SAAUA,kBAGXM,cAAKC,KAAK,CAACL,UAAU,4BAWDF,iBACrBE,QAAU,CACZC,WAAY,2DACZC,KAAM,CACFJ,SAAUA,kBAGXM,cAAKC,KAAK,CAACL,UAAU"}

View File

@ -66,12 +66,11 @@ const registerListenerEvents = () => {
// Handle the 'shown.bs.dropdown' event (Fired when the dropdown menu is fully displayed).
$(menuContainer).on('show.bs.dropdown', async(e) => {
const courseID = e.relatedTarget.dataset.courseid;
const actionBaseUrl = e.relatedTarget.dataset.actionBaseUrl;
// Display a loading icon in the dropdown menu container until the body promise is resolved.
await WidgetBase.showLoader(dropdownMenuContainer);
// If an error occurs while fetching the data, display the error within the dropdown menu.
const data = await Repository.groupFetch(courseID, actionBaseUrl).catch(async(e) => {
const data = await Repository.groupFetch(courseID).catch(async(e) => {
const errorTemplateData = {
'errormessage': e.message
};

View File

@ -28,16 +28,14 @@ import ajax from 'core/ajax';
*
* @method userFetch
* @param {int} courseid ID of the course to fetch the users of.
* @param {string} actionBaseUrl The base URL for the user option.
* @param {int} groupId ID of the group to fetch the users of.
* @return {object} jQuery promise
*/
export const userFetch = (courseid, actionBaseUrl, groupId) => {
export const userFetch = (courseid, groupId) => {
const request = {
methodname: 'core_grades_get_enrolled_users_for_search_widget',
methodname: 'core_grades_get_enrolled_users_for_selector',
args: {
courseid: courseid,
actionbaseurl: actionBaseUrl,
groupid: groupId,
},
};
@ -49,15 +47,13 @@ export const userFetch = (courseid, actionBaseUrl, groupId) => {
*
* @method groupFetch
* @param {int} courseid ID of the course to fetch the users of.
* @param {string} actionBaseUrl The base URL for the group action.
* @return {object} jQuery promise
*/
export const groupFetch = (courseid, actionBaseUrl) => {
export const groupFetch = (courseid) => {
const request = {
methodname: 'core_grades_get_groups_for_search_widget',
methodname: 'core_grades_get_groups_for_selector',
args: {
courseid: courseid,
actionbaseurl: actionBaseUrl,
},
};
return ajax.call([request])[0];

View File

@ -38,6 +38,7 @@ require_once($CFG->dirroot.'/grade/lib.php');
* @copyright 2022 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 4.1
* @deprecated
*/
class get_enrolled_users_for_search_widget extends external_api {
@ -45,6 +46,7 @@ class get_enrolled_users_for_search_widget extends external_api {
* Returns description of method parameters.
*
* @return external_function_parameters
* @deprecated since 4.2
*/
public static function execute_parameters(): external_function_parameters {
return new external_function_parameters (
@ -67,6 +69,7 @@ class get_enrolled_users_for_search_widget extends external_api {
* @throws invalid_parameter_exception
* @throws moodle_exception
* @throws restricted_context_exception
* @deprecated since 4.2
*/
public static function execute(int $courseid, string $actionbaseurl, ?int $groupid = 0): array {
global $DB, $PAGE;
@ -108,7 +111,7 @@ class get_enrolled_users_for_search_widget extends external_api {
$userpicture->size = 1;
$user->profileimage = $userpicture->get_url($PAGE)->out(false);
$user->email = $guiuser->email;
$user->active = false; // @TODO MDL-76246
$user->active = false;
$users[] = $user;
}
@ -124,6 +127,7 @@ class get_enrolled_users_for_search_widget extends external_api {
* Returns description of method result value.
*
* @return external_single_structure
* @deprecated since 4.2
*/
public static function execute_returns(): external_single_structure {
return new external_single_structure([
@ -159,4 +163,12 @@ class get_enrolled_users_for_search_widget extends external_api {
];
return new external_single_structure($userfields);
}
/**
* Mark the function as deprecated.
* @return bool
*/
public static function execute_is_deprecated() {
return true;
}
}

View File

@ -0,0 +1,150 @@
<?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_grades\external;
use core_external\external_api;
use core_external\external_description;
use core_external\external_function_parameters;
use core_external\external_multiple_structure;
use core_external\external_single_structure;
use core_external\external_value;
use core_external\external_warnings;
use core_external\restricted_context_exception;
use core_user;
defined('MOODLE_INTERNAL') || die;
require_once($CFG->dirroot.'/grade/lib.php');
/**
* Get the enrolled users within and map some fields to the returned array of user objects.
*
* @package core_grades
* @copyright 2022 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 4.2
*/
class get_enrolled_users_for_selector extends external_api {
/**
* Returns description of method parameters.
*
* @return external_function_parameters
*/
public static function execute_parameters(): external_function_parameters {
return new external_function_parameters (
[
'courseid' => new external_value(PARAM_INT, 'Course Id', VALUE_REQUIRED),
'groupid' => new external_value(PARAM_INT, 'Group Id', VALUE_DEFAULT, 0)
]
);
}
/**
* Given a course ID find the enrolled users within and map some fields to the returned array of user objects.
*
* @param int $courseid
* @param int|null $groupid
* @return array Users and warnings to pass back to the calling widget.
* @throws coding_exception
* @throws invalid_parameter_exception
* @throws moodle_exception
* @throws restricted_context_exception
*/
public static function execute(int $courseid, ?int $groupid = 0): array {
global $DB, $PAGE;
$params = self::validate_parameters(
self::execute_parameters(),
[
'courseid' => $courseid,
'groupid' => $groupid
]
);
$warnings = [];
$coursecontext = \context_course::instance($params['courseid']);
parent::validate_context($coursecontext);
require_capability('moodle/course:viewparticipants', $coursecontext);
$course = $DB->get_record('course', ['id' => $params['courseid']]);
// Create a graded_users_iterator because it will properly check the groups etc.
$defaultgradeshowactiveenrol = !empty($CFG->grade_report_showonlyactiveenrol);
$showonlyactiveenrol = get_user_preferences('grade_report_showonlyactiveenrol', $defaultgradeshowactiveenrol);
$showonlyactiveenrol = $showonlyactiveenrol || !has_capability('moodle/course:viewsuspendedusers', $coursecontext);
$gui = new \graded_users_iterator($course, null, $params['groupid']);
$gui->require_active_enrolment($showonlyactiveenrol);
$gui->init();
$users = [];
while ($userdata = $gui->next_user()) {
$guiuser = $userdata->user;
$user = new \stdClass();
$user->fullname = fullname($guiuser);
$user->id = $guiuser->id;
$userpicture = new \user_picture($guiuser);
$userpicture->size = 1;
$user->profileimage = $userpicture->get_url($PAGE)->out(false);
$user->email = $guiuser->email;
$users[] = $user;
}
$gui->close();
return [
'users' => $users,
'warnings' => $warnings,
];
}
/**
* Returns description of method result value.
*
* @return external_single_structure
*/
public static function execute_returns(): external_single_structure {
return new external_single_structure([
'users' => new external_multiple_structure(self::user_description()),
'warnings' => new external_warnings(),
]);
}
/**
* Create user return value description.
*
* @return external_description
*/
public static function user_description(): external_description {
$userfields = [
'id' => new external_value(core_user::get_property_type('id'), 'ID of the user'),
'profileimage' => new external_value(
PARAM_URL,
'The location of the users larger image',
VALUE_OPTIONAL
),
'fullname' => new external_value(PARAM_TEXT, 'The full name of the user', VALUE_OPTIONAL),
'email' => new external_value(
core_user::get_property_type('email'),
'An email address - allow email as root@localhost',
VALUE_OPTIONAL)
];
return new external_single_structure($userfields);
}
}

View File

@ -32,6 +32,7 @@ use core_external\external_warnings;
* @copyright 2022 Mathew May <mathew.solutions>
* @category external
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @deprecated
*/
class get_groups_for_search_widget extends external_api {
@ -39,6 +40,7 @@ class get_groups_for_search_widget extends external_api {
* Returns description of method parameters.
*
* @return external_function_parameters
* @deprecated since 4.2
*/
public static function execute_parameters(): external_function_parameters {
return new external_function_parameters (
@ -59,6 +61,7 @@ class get_groups_for_search_widget extends external_api {
* @throws invalid_parameter_exception
* @throws moodle_exception
* @throws restricted_context_exception
* @deprecated since 4.2
*/
protected static function execute(int $courseid, string $actionbaseurl): array {
global $DB, $USER, $COURSE;
@ -111,7 +114,7 @@ class get_groups_for_search_widget extends external_api {
'id' => $group->id,
'name' => format_string($group->name, true, ['context' => $context]),
'url' => $url->out(false),
'active' => false // @TODO MDL-76246
'active' => false
];
}, $groupsmenu);
}
@ -126,6 +129,7 @@ class get_groups_for_search_widget extends external_api {
* Returns description of what the group search for the widget should return.
*
* @return external_single_structure
* @deprecated since 4.2
*/
public static function execute_returns(): external_single_structure {
return new external_single_structure([
@ -148,4 +152,12 @@ class get_groups_for_search_widget extends external_api {
];
return new external_single_structure($groupfields);
}
/**
* Mark the function as deprecated.
* @return bool
*/
public static function execute_is_deprecated() {
return true;
}
}

View File

@ -0,0 +1,140 @@
<?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_grades\external;
use context_course;
use core_external\external_api;
use core_external\external_description;
use core_external\external_function_parameters;
use core_external\external_multiple_structure;
use core_external\external_single_structure;
use core_external\external_value;
use core_external\external_warnings;
/**
* External group report API implementation
*
* @package core_grades
* @copyright 2022 Mathew May <mathew.solutions>
* @category external
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class get_groups_for_selector extends external_api {
/**
* Returns description of method parameters.
*
* @return external_function_parameters
*/
public static function execute_parameters(): external_function_parameters {
return new external_function_parameters (
[
'courseid' => new external_value(PARAM_INT, 'Course Id', VALUE_REQUIRED),
]
);
}
/**
* Given a course ID find the existing user groups and map some fields to the returned array of group objects.
*
* @param int $courseid
* @return array Groups and warnings to pass back to the calling widget.
* @throws coding_exception
* @throws invalid_parameter_exception
* @throws moodle_exception
* @throws restricted_context_exception
*/
protected static function execute(int $courseid): array {
global $DB, $USER;
$params = self::validate_parameters(
self::execute_parameters(),
[
'courseid' => $courseid,
]
);
$warnings = [];
$context = context_course::instance($params['courseid']);
parent::validate_context($context);
$mappedgroups = [];
$course = $DB->get_record('course', ['id' => $params['courseid']]);
// Initialise the grade tracking object.
if ($groupmode = $course->groupmode) {
$aag = has_capability('moodle/site:accessallgroups', $context);
$usergroups = [];
$groupuserid = 0;
if ($groupmode == VISIBLEGROUPS || $aag) {
// Get user's own groups and put to the top.
$usergroups = groups_get_all_groups($course->id, $USER->id, $course->defaultgroupingid);
} else {
$groupuserid = $USER->id;
}
$allowedgroups = groups_get_all_groups($course->id, $groupuserid, $course->defaultgroupingid);
$allgroups = array_merge($allowedgroups, $usergroups);
// Filter out any duplicate groups.
$groupsmenu = array_intersect_key($allgroups, array_unique(array_column($allgroups, 'name')));
if (!$allowedgroups || $groupmode == VISIBLEGROUPS || $aag) {
array_unshift($groupsmenu, (object) [
'id' => 0,
'name' => get_string('allparticipants'),
]);
}
$mappedgroups = array_map(function($group) use ($context) {
return (object) [
'id' => $group->id,
'name' => format_string($group->name, true, ['context' => $context])
];
}, $groupsmenu);
}
return [
'groups' => $mappedgroups,
'warnings' => $warnings,
];
}
/**
* Returns description of what the group search for the widget should return.
*
* @return external_single_structure
*/
public static function execute_returns(): external_single_structure {
return new external_single_structure([
'groups' => new external_multiple_structure(self::group_description()),
'warnings' => new external_warnings(),
]);
}
/**
* Create group return value description.
*
* @return external_description
*/
public static function group_description(): external_description {
$groupfields = [
'id' => new external_value(PARAM_ALPHANUM, 'An ID for the group', VALUE_REQUIRED),
'name' => new external_value(PARAM_TEXT, 'The full name of the group', VALUE_REQUIRED)
];
return new external_single_structure($groupfields);
}
}

View File

@ -5,6 +5,6 @@ define("gradereport_singleview/user",["exports","core/local/aria/focuslock","cor
* @module gradereport_singleview/user
* @copyright 2022 Mathew May <mathew.solutions>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,FocusLockManager=_interopRequireWildcard(FocusLockManager),_pending=_interopRequireDefault(_pending),Templates=_interopRequireWildcard(Templates),Repository=_interopRequireWildcard(Repository),WidgetBase=_interopRequireWildcard(WidgetBase),_url=_interopRequireDefault(_url),_jquery=_interopRequireDefault(_jquery),Selectors=_interopRequireWildcard(Selectors);_exports.init=()=>{if(document.querySelector(Selectors.elements.getSearchWidgetSelector("user"))){const pendingPromise=new _pending.default;registerListenerEvents(),pendingPromise.resolve()}};const registerListenerEvents=()=>{let{bodyPromiseResolver:bodyPromiseResolver,bodyPromise:bodyPromise}=WidgetBase.promisesAndResolvers();const dropdownMenuContainer=document.querySelector(Selectors.elements.getSearchWidgetDropdownSelector("user")),menuContainer=document.querySelector(Selectors.elements.getSearchWidgetSelector("user")),inputElement=menuContainer.querySelector('input[name="userid"]');(0,_jquery.default)(menuContainer).on("show.bs.dropdown",(async e=>{const courseId=e.relatedTarget.dataset.courseid,groupId=e.relatedTarget.dataset.groupid,actionBaseUrl=_url.default.relativeUrl("/grade/report/singleview/index.php",{item:"user"},!1);await WidgetBase.showLoader(dropdownMenuContainer);const data=await Repository.userFetch(courseId,actionBaseUrl,groupId).catch((async e=>{const errorTemplateData={errormessage:e.message};bodyPromiseResolver(await Templates.render("core_grades/searchwidget/error",errorTemplateData))}));data!==[]&&(await WidgetBase.init(dropdownMenuContainer,bodyPromise,data.users,searchUsers(),null,afterSelect),bodyPromiseResolver(Templates.render("core_grades/searchwidget/user/usersearch_body",[])),FocusLockManager.trapFocus(dropdownMenuContainer))})),(0,_jquery.default)(menuContainer).on("hide.bs.dropdown",(()=>{FocusLockManager.untrapFocus()})),inputElement.addEventListener("change",(e=>{const courseId=menuContainer.querySelector(".dropdown-toggle").dataset.courseid,actionUrl=_url.default.relativeUrl("/grade/report/singleview/index.php",{id:courseId,item:"user",userid:e.target.value},!1);location.href=actionUrl,e.stopPropagation()}))},searchUsers=()=>()=>(users,searchTerm)=>{if(""===searchTerm)return users;searchTerm=searchTerm.toLowerCase();const searchResults=[];return users.forEach((user=>{user.fullname.toLowerCase().includes(searchTerm)&&searchResults.push(user)})),searchResults},afterSelect=selected=>{const menuContainer=document.querySelector(Selectors.elements.getSearchWidgetSelector("user")),inputElement=menuContainer.querySelector('input[name="userid"]');(0,_jquery.default)(menuContainer).dropdown("hide"),inputElement.value!=selected&&(inputElement.value=selected,inputElement.dispatchEvent(new Event("change",{bubbles:!0})))}}));
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,FocusLockManager=_interopRequireWildcard(FocusLockManager),_pending=_interopRequireDefault(_pending),Templates=_interopRequireWildcard(Templates),Repository=_interopRequireWildcard(Repository),WidgetBase=_interopRequireWildcard(WidgetBase),_url=_interopRequireDefault(_url),_jquery=_interopRequireDefault(_jquery),Selectors=_interopRequireWildcard(Selectors);_exports.init=()=>{if(document.querySelector(Selectors.elements.getSearchWidgetSelector("user"))){const pendingPromise=new _pending.default;registerListenerEvents(),pendingPromise.resolve()}};const registerListenerEvents=()=>{let{bodyPromiseResolver:bodyPromiseResolver,bodyPromise:bodyPromise}=WidgetBase.promisesAndResolvers();const dropdownMenuContainer=document.querySelector(Selectors.elements.getSearchWidgetDropdownSelector("user")),menuContainer=document.querySelector(Selectors.elements.getSearchWidgetSelector("user")),inputElement=menuContainer.querySelector('input[name="userid"]');(0,_jquery.default)(menuContainer).on("show.bs.dropdown",(async e=>{const courseId=e.relatedTarget.dataset.courseid,groupId=e.relatedTarget.dataset.groupid;await WidgetBase.showLoader(dropdownMenuContainer);const data=await Repository.userFetch(courseId,groupId).catch((async e=>{const errorTemplateData={errormessage:e.message};bodyPromiseResolver(await Templates.render("core_grades/searchwidget/error",errorTemplateData))}));data!==[]&&(await WidgetBase.init(dropdownMenuContainer,bodyPromise,data.users,searchUsers(),null,afterSelect),bodyPromiseResolver(Templates.render("core_grades/searchwidget/user/usersearch_body",[])),FocusLockManager.trapFocus(dropdownMenuContainer))})),(0,_jquery.default)(menuContainer).on("hide.bs.dropdown",(()=>{FocusLockManager.untrapFocus()})),inputElement.addEventListener("change",(e=>{const courseId=menuContainer.querySelector(".dropdown-toggle").dataset.courseid,actionUrl=_url.default.relativeUrl("/grade/report/singleview/index.php",{id:courseId,item:"user",userid:e.target.value},!1);location.href=actionUrl,e.stopPropagation()}))},searchUsers=()=>()=>(users,searchTerm)=>{if(""===searchTerm)return users;searchTerm=searchTerm.toLowerCase();const searchResults=[];return users.forEach((user=>{user.fullname.toLowerCase().includes(searchTerm)&&searchResults.push(user)})),searchResults},afterSelect=selected=>{const menuContainer=document.querySelector(Selectors.elements.getSearchWidgetSelector("user")),inputElement=menuContainer.querySelector('input[name="userid"]');(0,_jquery.default)(menuContainer).dropdown("hide"),inputElement.value!=selected&&(inputElement.value=selected,inputElement.dispatchEvent(new Event("change",{bubbles:!0})))}}));
//# sourceMappingURL=user.min.js.map

File diff suppressed because one or more lines are too long

View File

@ -59,12 +59,11 @@ const registerListenerEvents = () => {
$(menuContainer).on('show.bs.dropdown', async(e) => {
const courseId = e.relatedTarget.dataset.courseid;
const groupId = e.relatedTarget.dataset.groupid;
const actionBaseUrl = Url.relativeUrl('/grade/report/singleview/index.php', {item: 'user'}, false);
// Display a loading icon in the dropdown menu container until the body promise is resolved.
await WidgetBase.showLoader(dropdownMenuContainer);
// If an error occurs while fetching the data, display the error within the dropdown menu.
const data = await Repository.userFetch(courseId, actionBaseUrl, groupId).catch(async(e) => {
const data = await Repository.userFetch(courseId, groupId).catch(async(e) => {
const errorTemplateData = {
'errormessage': e.message
};

View File

@ -23,7 +23,6 @@ use core_external\external_multiple_structure;
use core_external\external_single_structure;
use core_external\external_value;
use core_external\external_warnings;
use moodle_url;
use grade_tree;
defined('MOODLE_INTERNAL') || die;
@ -82,15 +81,7 @@ class singleview extends core_course_external {
$gradeitems = array_map(function ($gradeitem) use ($PAGE, $USER, $params) {
$item = new \stdClass();
$item->id = $gradeitem->id;
$url = new moodle_url('/grade/report/singleview/index.php', [
'id' => $params['courseid'],
'itemid' => $gradeitem->id,
'item' => 'grade'
]
);
$item->name = $gradeitem->get_name(true);
$item->url = $url->out(false);
$item->active = false; // @TODO MDL-76246
return $item;
}, $gradeableitems);
@ -112,13 +103,7 @@ class singleview extends core_course_external {
'gradeitems' => new external_multiple_structure(
new external_single_structure([
'id' => new external_value(PARAM_INT, 'ID of the grade item', VALUE_OPTIONAL),
'url' => new external_value(
PARAM_URL,
'The link to the grade report',
VALUE_OPTIONAL
),
'name' => new external_value(PARAM_TEXT, 'The full name of the grade item', VALUE_OPTIONAL),
'active' => new external_value(PARAM_BOOL, 'Are we currently on this item?', VALUE_REQUIRED)
'name' => new external_value(PARAM_TEXT, 'The full name of the grade item', VALUE_OPTIONAL)
])
),
'warnings' => new external_warnings(),

View File

@ -5,6 +5,6 @@ define("gradereport_user/user",["exports","core/local/aria/focuslock","core/pend
* @module gradereport_user/user
* @copyright 2022 Mathew May <mathew.solutions>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,FocusLockManager=_interopRequireWildcard(FocusLockManager),_pending=_interopRequireDefault(_pending),Templates=_interopRequireWildcard(Templates),Repository=_interopRequireWildcard(Repository),WidgetBase=_interopRequireWildcard(WidgetBase),_url=_interopRequireDefault(_url),_jquery=_interopRequireDefault(_jquery),Selectors=_interopRequireWildcard(Selectors);_exports.init=()=>{const pendingPromise=new _pending.default;registerListenerEvents(),pendingPromise.resolve()};const registerListenerEvents=()=>{let{bodyPromiseResolver:bodyPromiseResolver,bodyPromise:bodyPromise}=WidgetBase.promisesAndResolvers();const dropdownMenuContainer=document.querySelector(Selectors.elements.getSearchWidgetDropdownSelector("user")),menuContainer=document.querySelector(Selectors.elements.getSearchWidgetSelector("user")),inputElement=menuContainer.querySelector('input[name="userid"]');(0,_jquery.default)(menuContainer).on("show.bs.dropdown",(async e=>{const courseID=e.relatedTarget.dataset.courseid,groupId=e.relatedTarget.dataset.groupid,actionBaseUrl=_url.default.relativeUrl("/grade/report/user/index.php",{},!1);await WidgetBase.showLoader(dropdownMenuContainer);const data=await Repository.userFetch(courseID,actionBaseUrl,groupId).catch((async e=>{const errorTemplateData={errormessage:e.message};bodyPromiseResolver(await Templates.render("core_grades/searchwidget/error",errorTemplateData))}));if(data===[])return;const allUsersOptionName=await(0,_str.get_string)("allusersnum","gradereport_user",data.users.length),allUsersOption=await Templates.render("gradereport_user/all_users_item",{id:0,name:allUsersOptionName,url:_url.default.relativeUrl("/grade/report/user/index.php",{id:courseID,userid:0},!1)});await WidgetBase.init(dropdownMenuContainer,bodyPromise,data.users,searchUsers(),allUsersOption,afterSelect),bodyPromiseResolver(Templates.render("core_grades/searchwidget/user/usersearch_body",{displayunsearchablecontent:!0})),FocusLockManager.trapFocus(dropdownMenuContainer)})),(0,_jquery.default)(menuContainer).on("hide.bs.dropdown",(()=>{FocusLockManager.untrapFocus()})),inputElement.addEventListener("change",(e=>{const courseID=menuContainer.querySelector(".dropdown-toggle").dataset.courseid,actionUrl=_url.default.relativeUrl("/grade/report/user/index.php",{id:courseID,userid:e.target.value},!1);location.href=actionUrl,e.stopPropagation()}))},searchUsers=()=>()=>(users,searchTerm)=>{if(""===searchTerm)return users;searchTerm=searchTerm.toLowerCase();const searchResults=[];return users.forEach((user=>{user.fullname.toLowerCase().includes(searchTerm)&&searchResults.push(user)})),searchResults},afterSelect=selected=>{const menuContainer=document.querySelector(Selectors.elements.getSearchWidgetSelector("user")),inputElement=menuContainer.querySelector('input[name="userid"]');(0,_jquery.default)(menuContainer).dropdown("hide"),inputElement.value!=selected&&(inputElement.value=selected,inputElement.dispatchEvent(new Event("change",{bubbles:!0})))}}));
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,FocusLockManager=_interopRequireWildcard(FocusLockManager),_pending=_interopRequireDefault(_pending),Templates=_interopRequireWildcard(Templates),Repository=_interopRequireWildcard(Repository),WidgetBase=_interopRequireWildcard(WidgetBase),_url=_interopRequireDefault(_url),_jquery=_interopRequireDefault(_jquery),Selectors=_interopRequireWildcard(Selectors);_exports.init=()=>{const pendingPromise=new _pending.default;registerListenerEvents(),pendingPromise.resolve()};const registerListenerEvents=()=>{let{bodyPromiseResolver:bodyPromiseResolver,bodyPromise:bodyPromise}=WidgetBase.promisesAndResolvers();const dropdownMenuContainer=document.querySelector(Selectors.elements.getSearchWidgetDropdownSelector("user")),menuContainer=document.querySelector(Selectors.elements.getSearchWidgetSelector("user")),inputElement=menuContainer.querySelector('input[name="userid"]');(0,_jquery.default)(menuContainer).on("show.bs.dropdown",(async e=>{const courseID=e.relatedTarget.dataset.courseid,groupId=e.relatedTarget.dataset.groupid;await WidgetBase.showLoader(dropdownMenuContainer);const data=await Repository.userFetch(courseID,groupId).catch((async e=>{const errorTemplateData={errormessage:e.message};bodyPromiseResolver(await Templates.render("core_grades/searchwidget/error",errorTemplateData))}));if(data===[])return;const allUsersOptionName=await(0,_str.get_string)("allusersnum","gradereport_user",data.users.length),allUsersOption=await Templates.render("gradereport_user/all_users_item",{id:0,name:allUsersOptionName,url:_url.default.relativeUrl("/grade/report/user/index.php",{id:courseID,userid:0},!1)});await WidgetBase.init(dropdownMenuContainer,bodyPromise,data.users,searchUsers(),allUsersOption,afterSelect),bodyPromiseResolver(Templates.render("core_grades/searchwidget/user/usersearch_body",{displayunsearchablecontent:!0})),FocusLockManager.trapFocus(dropdownMenuContainer)})),(0,_jquery.default)(menuContainer).on("hide.bs.dropdown",(()=>{FocusLockManager.untrapFocus()})),inputElement.addEventListener("change",(e=>{const courseID=menuContainer.querySelector(".dropdown-toggle").dataset.courseid,actionUrl=_url.default.relativeUrl("/grade/report/user/index.php",{id:courseID,userid:e.target.value},!1);location.href=actionUrl,e.stopPropagation()}))},searchUsers=()=>()=>(users,searchTerm)=>{if(""===searchTerm)return users;searchTerm=searchTerm.toLowerCase();const searchResults=[];return users.forEach((user=>{user.fullname.toLowerCase().includes(searchTerm)&&searchResults.push(user)})),searchResults},afterSelect=selected=>{const menuContainer=document.querySelector(Selectors.elements.getSearchWidgetSelector("user")),inputElement=menuContainer.querySelector('input[name="userid"]');(0,_jquery.default)(menuContainer).dropdown("hide"),inputElement.value!=selected&&(inputElement.value=selected,inputElement.dispatchEvent(new Event("change",{bubbles:!0})))}}));
//# sourceMappingURL=user.min.js.map

File diff suppressed because one or more lines are too long

View File

@ -58,12 +58,11 @@ const registerListenerEvents = () => {
$(menuContainer).on('show.bs.dropdown', async(e) => {
const courseID = e.relatedTarget.dataset.courseid;
const groupId = e.relatedTarget.dataset.groupid;
const actionBaseUrl = Url.relativeUrl('/grade/report/user/index.php', {}, false);
// Display a loading icon in the dropdown menu container until the body promise is resolved.
await WidgetBase.showLoader(dropdownMenuContainer);
// If an error occurs while fetching the data, display the error within the dropdown menu.
const data = await Repository.userFetch(courseID, actionBaseUrl, groupId).catch(async(e) => {
const data = await Repository.userFetch(courseID, groupId).catch(async(e) => {
const errorTemplateData = {
'errormessage': e.message
};

View File

@ -23,8 +23,7 @@
{
"id": "1",
"name": "Quiz 1",
"fullname": "Cameron Greeve",
"active": true
"fullname": "Cameron Greeve"
}
}}
<li

View File

@ -91,8 +91,8 @@ $functions = array(
'type' => 'read',
'ajax' => true,
'loginrequired' => true,
),
'core_backup_get_async_backup_links_restore' => array(
),
'core_backup_get_async_backup_links_restore' => array(
'classname' => 'core_backup_external',
'classpath' => 'backup/externallib.php',
'methodname' => 'get_async_backup_links_restore',
@ -965,13 +965,31 @@ $functions = array(
),
'core_grades_get_enrolled_users_for_search_widget' => array (
'classname' => 'core_grades\external\get_enrolled_users_for_search_widget',
'description' => '** DEPRECATED ** Please do not call this function any more. ' .
'Use core_grades_get_enrolled_users_for_selector instead. ' .
'Returns the enrolled users within and map some fields to the returned array of user objects.',
'type' => 'read',
'ajax' => true,
'services' => [MOODLE_OFFICIAL_MOBILE_SERVICE],
),
'core_grades_get_enrolled_users_for_selector' => array (
'classname' => 'core_grades\external\get_enrolled_users_for_selector',
'description' => 'Returns the enrolled users within and map some fields to the returned array of user objects.',
'type' => 'read',
'ajax' => true,
'services' => [MOODLE_OFFICIAL_MOBILE_SERVICE],
),
'core_grades_get_groups_for_search_widget' => [
'classname' => 'core_grades\external\get_groups_for_search_widget',
'classname' => 'core_grades\external\get_groups_for_selector',
'description' => '** DEPRECATED ** Please do not call this function any more. ' .
'Use core_grades_get_groups_for_selector instead. ' .
'Get the group/(s) for a course',
'type' => 'read',
'ajax' => true,
'services' => [MOODLE_OFFICIAL_MOBILE_SERVICE],
],
'core_grades_get_groups_for_selector' => [
'classname' => 'core_grades\external\get_groups_for_selector',
'description' => 'Get the group/(s) for a course',
'type' => 'read',
'ajax' => true,

View File

@ -97,6 +97,10 @@ information provided here is intended especially for developers.
- `createCsvDataSet`
- `createArrayDataSet`
- `loadDataSet`
* The external function core_grades_get_enrolled_users_for_search_widget is now deprecated.
Please use the new core_grades_get_enrolled_users_for_selector external function instead.
* The external function core_grades_get_groups_for_search_widget is now deprecated.
Please use the new core_grades_get_groups_for_selector external function instead.
=== 4.1 ===

View File

@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2023032200.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2023032200.01; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
$release = '4.2dev+ (Build: 20230322)'; // Human-friendly version name