Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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
 * A javascript module to handle MoodleNet ajax actions.
18
 *
19
 * @module     core/moodlenet/service
20
 * @copyright  2023 Huong Nguyen <huongnv13@gmail.com>
21
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 * @since      4.2
23
 */
24
 
25
import Ajax from 'core/ajax';
26
 
27
/**
28
 * Get the activity information by course module id.
29
 *
30
 * @param {Integer} cmId The course module id.
31
 * @return {promise}
32
 */
33
export const getActivityInformation = (cmId) => {
34
    const request = {
35
        methodname: 'core_moodlenet_get_share_info_activity',
36
        args: {
37
            cmid: cmId
38
        }
39
    };
40
 
41
    return Ajax.call([request])[0];
42
};
43
 
44
 
45
/**
46
 * Get the course information by course module id.
47
 *
48
 * @param {Integer} courseID The course id.
49
 * @return {promise}
50
 */
51
export const getCourseInformation = (courseID) => {
52
    const request = {
53
        methodname: 'core_moodlenet_get_shared_course_info',
54
        args: {
55
            courseid: courseID
56
        }
57
    };
58
 
59
    return Ajax.call([request])[0];
60
};
61
 
62
/**
63
 * Send the course to MoodleNet.
64
 *
65
 * @param {Integer} issuerId The OAuth 2 issuer ID.
66
 * @param {Integer} courseId The course ID.
67
 * @param {Integer} shareFormat The share format.
68
 * @return {promise}
69
 */
70
export const sendCourse = (issuerId, courseId, shareFormat) => {
71
    const request = {
72
        methodname: 'core_moodlenet_send_course',
73
        args: {
74
            issuerid: issuerId,
75
            courseid: courseId,
76
            shareformat: shareFormat,
77
        }
78
    };
79
 
80
    return Ajax.call([request])[0];
81
};
82
 
83
/**
84
 * Send the activity to Moodlenet.
85
 *
86
 * @param {Integer} issuerId The OAuth 2 issuer ID.
87
 * @param {Integer} cmId The course module ID.
88
 * @param {Integer} shareFormat The share format.
89
 * @return {promise}
90
 */
91
export const sendActivity = (issuerId, cmId, shareFormat) => {
92
    const request = {
93
        methodname: 'core_moodlenet_send_activity',
94
        args: {
95
            issuerid: issuerId,
96
            cmid: cmId,
97
            shareformat: shareFormat,
98
        }
99
    };
100
 
101
    return Ajax.call([request])[0];
102
};
103
 
104
/**
105
 * Send the selected activities in a course to MoodleNet.
106
 *
107
 * @param {Integer} issuerId The OAuth 2 issuer ID.
108
 * @param {Integer} courseId The course ID.
109
 * @param {array} selectedCmIds Course module IDs in the course.
110
 * @param {Integer} shareFormat The share format.
111
 * @return {promise}
112
 */
113
export const sendPartialCourse = (issuerId, courseId, selectedCmIds, shareFormat) => {
114
    const request = {
115
        methodname: 'core_moodlenet_send_course',
116
        args: {
117
            issuerid: issuerId,
118
            courseid: courseId,
119
            shareformat: shareFormat,
120
            cmids: selectedCmIds,
121
        }
122
    };
123
 
124
    return Ajax.call([request])[0];
125
};
126
 
127
/**
128
 * Check if the user is already authorized with MoodleNet.
129
 *
130
 * @param {Integer} issuerId The OAuth 2 issuer ID.
131
 * @param {Integer} courseId The course ID.
132
 * @return {promise}
133
 */
134
export const authorizationCheck = (issuerId, courseId) => {
135
    const request = {
136
        methodname: 'core_moodlenet_auth_check',
137
        args: {
138
            issuerid: issuerId,
139
            courseid: courseId,
140
        }
141
    };
142
 
143
    return Ajax.call([request])[0];
144
};