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 |
* Forum repository class to encapsulate all of the AJAX requests that subscribe or unsubscribe
|
|
|
18 |
* can be sent for forum.
|
|
|
19 |
*
|
|
|
20 |
* @module mod_forum/repository
|
|
|
21 |
* @copyright 2019 Andrew Nicols <andrew@nicols.co.uk>
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
define(['core/ajax'], function(Ajax) {
|
|
|
25 |
/**
|
|
|
26 |
* Set the subscription state for a discussion in a forum.
|
|
|
27 |
*
|
|
|
28 |
* @param {number} forumId ID of the forum the discussion belongs to
|
|
|
29 |
* @param {number} discussionId ID of the discussion with the subscription state
|
|
|
30 |
* @param {boolean} targetState Set the subscribed state. True == subscribed; false == unsubscribed.
|
|
|
31 |
* @return {object} jQuery promise
|
|
|
32 |
*/
|
|
|
33 |
var setDiscussionSubscriptionState = function(forumId, discussionId, targetState) {
|
|
|
34 |
var request = {
|
|
|
35 |
methodname: 'mod_forum_set_subscription_state',
|
|
|
36 |
args: {
|
|
|
37 |
forumid: forumId,
|
|
|
38 |
discussionid: discussionId,
|
|
|
39 |
targetstate: targetState
|
|
|
40 |
}
|
|
|
41 |
};
|
|
|
42 |
return Ajax.call([request])[0];
|
|
|
43 |
};
|
|
|
44 |
|
|
|
45 |
var addDiscussionPost = function(postid, subject, message, messageformat, isprivatereply, topreferredformat) {
|
|
|
46 |
var request = {
|
|
|
47 |
methodname: 'mod_forum_add_discussion_post',
|
|
|
48 |
args: {
|
|
|
49 |
postid: postid,
|
|
|
50 |
message: message,
|
|
|
51 |
messageformat: messageformat,
|
|
|
52 |
subject: subject,
|
|
|
53 |
options: [{
|
|
|
54 |
name: "private",
|
|
|
55 |
value: isprivatereply,
|
|
|
56 |
}, {
|
|
|
57 |
name: "topreferredformat",
|
|
|
58 |
value: topreferredformat,
|
|
|
59 |
}]
|
|
|
60 |
}
|
|
|
61 |
};
|
|
|
62 |
return Ajax.call([request])[0];
|
|
|
63 |
};
|
|
|
64 |
|
|
|
65 |
/**
|
|
|
66 |
* Set the favourite state for a discussion in a forum.
|
|
|
67 |
*
|
|
|
68 |
* @param {number} forumId ID of the forum the discussion belongs to
|
|
|
69 |
* @param {number} discussionId ID of the discussion with the subscription state
|
|
|
70 |
* @param {null|date} targetState Set the favourite state. True == favourited; false == unfavourited.
|
|
|
71 |
* @return {object} jQuery promise
|
|
|
72 |
*/
|
|
|
73 |
var setFavouriteDiscussionState = function(forumId, discussionId, targetState) {
|
|
|
74 |
var request = {
|
|
|
75 |
methodname: 'mod_forum_toggle_favourite_state',
|
|
|
76 |
args: {
|
|
|
77 |
discussionid: discussionId,
|
|
|
78 |
targetstate: targetState
|
|
|
79 |
}
|
|
|
80 |
};
|
|
|
81 |
return Ajax.call([request])[0];
|
|
|
82 |
};
|
|
|
83 |
|
|
|
84 |
var setDiscussionLockState = function(forumId, discussionId, targetState) {
|
|
|
85 |
var request = {
|
|
|
86 |
methodname: 'mod_forum_set_lock_state',
|
|
|
87 |
args: {
|
|
|
88 |
forumid: forumId,
|
|
|
89 |
discussionid: discussionId,
|
|
|
90 |
targetstate: targetState}
|
|
|
91 |
};
|
|
|
92 |
return Ajax.call([request])[0];
|
|
|
93 |
};
|
|
|
94 |
|
|
|
95 |
/**
|
|
|
96 |
* Set the pinned state for the discussion provided.
|
|
|
97 |
*
|
|
|
98 |
* @param {number} forumid
|
|
|
99 |
* @param {number} discussionid
|
|
|
100 |
* @param {boolean} targetstate
|
|
|
101 |
* @return {*|Promise}
|
|
|
102 |
*/
|
|
|
103 |
var setPinDiscussionState = function(forumid, discussionid, targetstate) {
|
|
|
104 |
var request = {
|
|
|
105 |
methodname: 'mod_forum_set_pin_state',
|
|
|
106 |
args: {
|
|
|
107 |
discussionid: discussionid,
|
|
|
108 |
targetstate: targetstate
|
|
|
109 |
}
|
|
|
110 |
};
|
|
|
111 |
return Ajax.call([request])[0];
|
|
|
112 |
};
|
|
|
113 |
|
|
|
114 |
/**
|
|
|
115 |
* Get the discussions for the user and cmid provided.
|
|
|
116 |
*
|
|
|
117 |
* @param {number} userid
|
|
|
118 |
* @param {number} cmid
|
|
|
119 |
* @param {string} sortby
|
|
|
120 |
* @param {string} sortdirection
|
|
|
121 |
* @return {*|Promise}
|
|
|
122 |
*/
|
|
|
123 |
var getDiscussionByUserID = function(userid, cmid, sortby = 'modified', sortdirection = 'DESC') {
|
|
|
124 |
var request = {
|
|
|
125 |
methodname: 'mod_forum_get_discussion_posts_by_userid',
|
|
|
126 |
args: {
|
|
|
127 |
userid: userid,
|
|
|
128 |
cmid: cmid,
|
|
|
129 |
sortby: sortby,
|
|
|
130 |
sortdirection: sortdirection,
|
|
|
131 |
},
|
|
|
132 |
};
|
|
|
133 |
return Ajax.call([request])[0];
|
|
|
134 |
};
|
|
|
135 |
|
|
|
136 |
/**
|
|
|
137 |
* Get the posts for the discussion ID provided.
|
|
|
138 |
*
|
|
|
139 |
* @param {number} discussionId
|
|
|
140 |
* @param {String} sortby
|
|
|
141 |
* @param {String} sortdirection
|
|
|
142 |
* @return {*|Promise}
|
|
|
143 |
*/
|
|
|
144 |
var getDiscussionPosts = function(discussionId, sortby = 'created', sortdirection = 'ASC') {
|
|
|
145 |
var request = {
|
|
|
146 |
methodname: 'mod_forum_get_discussion_posts',
|
|
|
147 |
args: {
|
|
|
148 |
discussionid: discussionId,
|
|
|
149 |
sortby: sortby,
|
|
|
150 |
sortdirection: sortdirection,
|
|
|
151 |
},
|
|
|
152 |
};
|
|
|
153 |
return Ajax.call([request])[0];
|
|
|
154 |
};
|
|
|
155 |
|
|
|
156 |
return {
|
|
|
157 |
setDiscussionSubscriptionState: setDiscussionSubscriptionState,
|
|
|
158 |
addDiscussionPost: addDiscussionPost,
|
|
|
159 |
setDiscussionLockState: setDiscussionLockState,
|
|
|
160 |
setFavouriteDiscussionState: setFavouriteDiscussionState,
|
|
|
161 |
setPinDiscussionState: setPinDiscussionState,
|
|
|
162 |
getDiscussionByUserID: getDiscussionByUserID,
|
|
|
163 |
getDiscussionPosts: getDiscussionPosts,
|
|
|
164 |
};
|
|
|
165 |
});
|