Merge branch 'MDL-84036-main' of https://github.com/aanabit/moodle

This commit is contained in:
Andrew Nicols 2025-03-06 11:47:47 +08:00
commit 8d5f85017a
No known key found for this signature in database
GPG Key ID: 6D1E3157C8CFBF14
11 changed files with 35 additions and 537 deletions

View File

@ -0,0 +1,7 @@
issueNumber: MDL-84036
notes:
core_grades:
- message: >-
The external function core_grades_get_enrolled_users_for_search_widget
has been fully removed.
type: removed

View File

@ -0,0 +1,7 @@
issueNumber: MDL-84036
notes:
core_grades:
- message: >-
The external function core_grades_get_groups_for_search_widget has been
fully removed.
type: removed

View File

@ -0,0 +1,7 @@
issueNumber: MDL-84036
notes:
core:
- message: >-
The `core_output_load_fontawesome_icon_map` web service has been
fully removed and replaced by `core_output_load_fontawesome_icon_system_map`
type: removed

View File

@ -0,0 +1,7 @@
issueNumber: MDL-84036
notes:
report_insights:
- message: >-
report_insights_set_notuseful_prediction() external function has been
fully removed.
type: removed

View File

@ -0,0 +1,7 @@
issueNumber: MDL-84036
notes:
report_insights:
- message: >-
report_insights_set_fixed_prediction() external function has been fully
removed.
type: removed

View File

@ -1,182 +0,0 @@
<?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 moodle_url;
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.1
* @deprecated
*/
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 (
[
'courseid' => new external_value(PARAM_INT, 'Course Id', VALUE_REQUIRED),
'actionbaseurl' => new external_value(PARAM_URL, 'The base URL for the user option', 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 string $actionbaseurl The base URL for the user option.
* @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
* @deprecated since 4.2
*/
public static function execute(int $courseid, string $actionbaseurl, ?int $groupid = 0): array {
global $DB, $PAGE;
$params = self::validate_parameters(
self::execute_parameters(),
[
'courseid' => $courseid,
'actionbaseurl' => $actionbaseurl,
'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 = [];
$userfieldsapi = \core_user\fields::for_identity($coursecontext, false)->with_userpic();
$extrauserfields = $userfieldsapi->get_required_fields([\core_user\fields::PURPOSE_IDENTITY]);
while ($userdata = $gui->next_user()) {
$guiuser = $userdata->user;
$user = new \stdClass();
$user->fullname = fullname($guiuser);
foreach (\core_user\fields::get_name_fields() as $field) {
$user->$field = $guiuser->$field ?? null;
}
$user->id = $guiuser->id;
$user->url = (new moodle_url($actionbaseurl, ['id' => $courseid, 'userid' => $guiuser->id]))->out(false);
$userpicture = new \user_picture($guiuser);
$userpicture->size = 1;
$user->profileimage = $userpicture->get_url($PAGE)->out(false);
foreach ($extrauserfields as $field) {
$user->$field = $userdata->user->$field ?? null;
}
$user->active = false;
$users[] = $user;
}
$gui->close();
return [
'users' => $users,
'warnings' => $warnings,
];
}
/**
* 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([
'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
),
'url' => new external_value(
PARAM_URL,
'The link to the user report',
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),
'active' => new external_value(PARAM_BOOL, 'Are we currently on this item?', VALUE_REQUIRED)
];
return new external_single_structure($userfields);
}
/**
* Mark the function as deprecated.
* @return bool
*/
public static function execute_is_deprecated() {
return true;
}
}

View File

@ -1,159 +0,0 @@
<?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
* @deprecated
*/
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 (
[
'courseid' => new external_value(PARAM_INT, 'Course Id', VALUE_REQUIRED),
'actionbaseurl' => new external_value(PARAM_URL, 'The base URL for the group action', 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
* @param string $actionbaseurl The base URL for the group action.
* @return array Groups and warnings to pass back to the calling widget.
* @deprecated since 4.2
*/
public static function execute(int $courseid, string $actionbaseurl): array {
global $DB, $USER, $COURSE;
$params = self::validate_parameters(
self::execute_parameters(),
[
'courseid' => $courseid,
'actionbaseurl' => $actionbaseurl
]
);
$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 ($COURSE, $actionbaseurl, $context) {
$url = new \moodle_url($actionbaseurl, [
'id' => $COURSE->id,
'group' => $group->id
]);
return (object) [
'id' => $group->id,
'name' => format_string($group->name, true, ['context' => $context]),
'url' => $url->out(false),
'active' => false
];
}, $groupsmenu);
}
return [
'groups' => $mappedgroups,
'warnings' => $warnings,
];
}
/**
* 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([
'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),
'url' => new external_value(PARAM_URL, 'The link that applies the group action', VALUE_REQUIRED),
'name' => new external_value(PARAM_TEXT, 'The full name of the group', VALUE_REQUIRED),
'active' => new external_value(PARAM_BOOL, 'Are we currently on this item?', VALUE_REQUIRED)
];
return new external_single_structure($groupfields);
}
/**
* Mark the function as deprecated.
* @return bool
*/
public static function execute_is_deprecated() {
return true;
}
}

View File

@ -183,44 +183,4 @@ class external extends external_api {
'strings' => new external_multiple_structure($resourcestructure),
]);
}
/**
* Returns description of load_icon_map() parameters.
*
* @return external_function_parameters
*/
public static function load_fontawesome_icon_map_parameters() {
return new external_function_parameters([]);
}
/**
* Return a mapping of icon names to icons.
*
* @deprecated since Moodle 3.10
* @return array the mapping
*/
public static function load_fontawesome_icon_map() {
global $PAGE;
return load_fontawesome_map::execute($PAGE->theme->name);
}
/**
* Returns description of load_icon_map() result value.
*
* @return \core_external\external_description
*/
public static function load_fontawesome_icon_map_returns() {
return load_fontawesome_map::execute_returns();
}
/**
* The `load_fontawesome_icon_map` function has been replaced with
* @see load_fontawesome_map::execute()
*
* @return bool
*/
public static function load_fontawesome_icon_map_is_deprecated() {
return true;
}
}

View File

@ -1037,15 +1037,6 @@ $functions = array(
'type' => 'write',
'capabilities' => 'moodle/grade:manage',
),
'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.',
@ -1053,15 +1044,6 @@ $functions = array(
'ajax' => true,
'services' => [MOODLE_OFFICIAL_MOBILE_SERVICE],
),
'core_grades_get_groups_for_search_widget' => [
'classname' => 'core_group\external\get_groups_for_selector',
'description' => '** DEPRECATED ** Please do not call this function any more. ' .
'Use core_group_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_group\external\get_groups_for_selector',
'description' => '** DEPRECATED ** Please do not call this function any more. ' .
@ -1726,14 +1708,6 @@ $functions = array(
'loginrequired' => false,
'ajax' => true,
),
'core_output_load_fontawesome_icon_map' => array(
'classname' => 'core\output\external',
'methodname' => 'load_fontawesome_icon_map',
'description' => 'Load the mapping of names to icons',
'type' => 'read',
'loginrequired' => false,
'ajax' => true,
),
'core_output_load_fontawesome_icon_system_map' => array(
'classname' => 'core\external\output\icon_system\load_fontawesome_map',
'description' => 'Load the mapping of moodle pix names to fontawesome icon names',

View File

@ -31,117 +31,6 @@ use core_external\external_warnings;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class external extends external_api {
/**
* set_notuseful_prediction parameters.
*
* @return external_function_parameters
* @since Moodle 3.4
*/
public static function set_notuseful_prediction_parameters() {
return new external_function_parameters(
array(
'predictionid' => new external_value(PARAM_INT, 'The prediction id', VALUE_REQUIRED)
)
);
}
/**
* Flags a prediction as fixed so no need to display it any more.
*
* @param int $predictionid
* @return array an array of warnings and a boolean
* @since Moodle 3.4
*/
public static function set_notuseful_prediction($predictionid) {
$params = self::validate_parameters(self::set_notuseful_prediction_parameters(), array('predictionid' => $predictionid));
list($model, $prediction, $context) = self::validate_prediction($params['predictionid']);
$prediction->action_executed(\core_analytics\prediction::ACTION_NOT_USEFUL, $model->get_target());
$success = true;
return array('success' => $success, 'warnings' => array());
}
/**
* set_notuseful_prediction return
*
* @return \core_external\external_description
* @since Moodle 3.4
*/
public static function set_notuseful_prediction_returns() {
return new external_single_structure(
array(
'success' => new external_value(PARAM_BOOL, 'True if the prediction was successfully flagged as not useful.'),
'warnings' => new external_warnings(),
)
);
}
/**
* Deprecated in favour of action_executed.
*/
public static function set_notuseful_prediction_is_deprecated() {
return true;
}
/**
* set_fixed_prediction parameters.
*
* @return external_function_parameters
* @since Moodle 3.4
*/
public static function set_fixed_prediction_parameters() {
return new external_function_parameters(
array(
'predictionid' => new external_value(PARAM_INT, 'The prediction id', VALUE_REQUIRED)
)
);
}
/**
* Flags a prediction as fixed so no need to display it any more.
*
* @param int $predictionid
* @return array an array of warnings and a boolean
* @since Moodle 3.4
*/
public static function set_fixed_prediction($predictionid) {
$params = self::validate_parameters(self::set_fixed_prediction_parameters(), array('predictionid' => $predictionid));
list($model, $prediction, $context) = self::validate_prediction($params['predictionid']);
$prediction->action_executed(\core_analytics\prediction::ACTION_FIXED, $model->get_target());
$success = true;
return array('success' => $success, 'warnings' => array());
}
/**
* set_fixed_prediction return
*
* @return \core_external\external_description
* @since Moodle 3.4
*/
public static function set_fixed_prediction_returns() {
return new external_single_structure(
array(
'success' => new external_value(PARAM_BOOL, 'True if the prediction was successfully flagged as fixed.'),
'warnings' => new external_warnings(),
)
);
}
/**
* Deprecated in favour of action_executed.
*/
public static function set_fixed_prediction_is_deprecated() {
return true;
}
/**
* action_executed parameters.
*

View File

@ -25,25 +25,6 @@
defined('MOODLE_INTERNAL') || die();
$functions = array(
'report_insights_set_notuseful_prediction' => array(
'classname' => 'report_insights\external',
'methodname' => 'set_notuseful_prediction',
'description' => 'Flags the prediction as not useful.',
'type' => 'write',
'ajax' => true,
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE)
),
'report_insights_set_fixed_prediction' => array(
'classname' => 'report_insights\external',
'methodname' => 'set_fixed_prediction',
'description' => 'Flags a prediction as fixed.',
'type' => 'write',
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE),
'ajax' => true,
),
'report_insights_action_executed' => array(
'classname' => 'report_insights\external',
'methodname' => 'action_executed',