1 |
efrain |
1 |
// This file is part of Moodle - http://moodle.org/
|
|
|
2 |
//
|
|
|
3 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
4 |
// it under the terms of the GNU General Public License as published by
|
|
|
5 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
6 |
// (at your option) any later version.
|
|
|
7 |
//
|
|
|
8 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
9 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
10 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
11 |
// GNU General Public License for more details.
|
|
|
12 |
//
|
|
|
13 |
// You should have received a copy of the GNU General Public License
|
|
|
14 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
15 |
|
|
|
16 |
/**
|
|
|
17 |
* Module to handle AJAX interactions.
|
|
|
18 |
*
|
|
|
19 |
* @module core_user/repository
|
|
|
20 |
* @copyright 2020 Andrew Nicols <andrew@nicols.co.uk>
|
|
|
21 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
22 |
*/
|
|
|
23 |
|
|
|
24 |
import {call as fetchMany} from 'core/ajax';
|
|
|
25 |
|
|
|
26 |
/**
|
|
|
27 |
* Get single user preference
|
|
|
28 |
*
|
|
|
29 |
* @param {String} name Name of the preference
|
|
|
30 |
* @param {Number} userid User ID (defaults to current user)
|
|
|
31 |
* @return {Promise}
|
|
|
32 |
*/
|
|
|
33 |
export const getUserPreference = (name, userid = 0) => {
|
|
|
34 |
return getUserPreferences(name, userid)
|
|
|
35 |
.then(response => response.preferences[0].value);
|
|
|
36 |
};
|
|
|
37 |
|
|
|
38 |
/**
|
|
|
39 |
* Get multiple user preferences
|
|
|
40 |
*
|
|
|
41 |
* @param {String|null} name Name of the preference (omit if you want to retrieve all)
|
|
|
42 |
* @param {Number} userid User ID (defaults to current user)
|
|
|
43 |
* @return {Promise}
|
|
|
44 |
*/
|
|
|
45 |
export const getUserPreferences = (name = null, userid = 0) => {
|
|
|
46 |
return fetchMany([{
|
|
|
47 |
methodname: 'core_user_get_user_preferences',
|
|
|
48 |
args: {name, userid}
|
|
|
49 |
}])[0];
|
|
|
50 |
};
|
|
|
51 |
|
|
|
52 |
/**
|
|
|
53 |
* Set single user preference
|
|
|
54 |
*
|
|
|
55 |
* @param {String} name Name of the preference
|
|
|
56 |
* @param {String|null} value Value of the preference (omit if you want to remove the current value)
|
|
|
57 |
* @param {Number} userid User ID (defaults to current user)
|
|
|
58 |
* @return {Promise}
|
|
|
59 |
*/
|
|
|
60 |
export const setUserPreference = (name, value = null, userid = 0) => {
|
|
|
61 |
return setUserPreferences([{name, value, userid}]);
|
|
|
62 |
};
|
|
|
63 |
|
|
|
64 |
/**
|
|
|
65 |
* Set multiple user preferences
|
|
|
66 |
*
|
|
|
67 |
* @param {Object[]} preferences Array of preferences containing name/value/userid attributes
|
|
|
68 |
* @return {Promise}
|
|
|
69 |
*/
|
|
|
70 |
export const setUserPreferences = (preferences) => {
|
|
|
71 |
return fetchMany([{
|
|
|
72 |
methodname: 'core_user_set_user_preferences',
|
|
|
73 |
args: {preferences}
|
|
|
74 |
}])[0];
|
|
|
75 |
};
|
|
|
76 |
|
|
|
77 |
/**
|
|
|
78 |
* Unenrol the user with the specified user enrolmentid ID.
|
|
|
79 |
*
|
|
|
80 |
* @param {Number} userEnrolmentId
|
|
|
81 |
* @return {Promise}
|
|
|
82 |
*/
|
|
|
83 |
export const unenrolUser = userEnrolmentId => {
|
|
|
84 |
return fetchMany([{
|
|
|
85 |
methodname: 'core_enrol_unenrol_user_enrolment',
|
|
|
86 |
args: {
|
|
|
87 |
ueid: userEnrolmentId,
|
|
|
88 |
},
|
|
|
89 |
}])[0];
|
|
|
90 |
};
|
|
|
91 |
|
|
|
92 |
/**
|
|
|
93 |
* Submit the user enrolment form with the specified form data.
|
|
|
94 |
*
|
|
|
95 |
* @param {String} formdata
|
|
|
96 |
* @return {Promise}
|
|
|
97 |
*/
|
|
|
98 |
export const submitUserEnrolmentForm = formdata => {
|
|
|
99 |
return fetchMany([{
|
|
|
100 |
methodname: 'core_enrol_submit_user_enrolment_form',
|
|
|
101 |
args: {
|
|
|
102 |
formdata,
|
|
|
103 |
},
|
|
|
104 |
}])[0];
|
|
|
105 |
};
|
|
|
106 |
|
|
|
107 |
export const createNotesForUsers = notes => {
|
|
|
108 |
return fetchMany([{
|
|
|
109 |
methodname: 'core_notes_create_notes',
|
|
|
110 |
args: {
|
|
|
111 |
notes
|
|
|
112 |
}
|
|
|
113 |
}])[0];
|
|
|
114 |
};
|
|
|
115 |
|
|
|
116 |
export const sendMessagesToUsers = messages => {
|
|
|
117 |
return fetchMany([{
|
|
|
118 |
methodname: 'core_message_send_instant_messages',
|
|
|
119 |
args: {messages}
|
|
|
120 |
}])[0];
|
|
|
121 |
};
|