MDL-67883 core: Make core ready for MoodleNet.
[moodle.git] / course / amd / src / local / activitychooser / repository.js
CommitLineData
05b27f21
MM
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 *
18 * @module core_course/repository
19 * @package core_course
20 * @copyright 2019 Mathew May <mathew.solutions>
21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22 */
23import ajax from 'core/ajax';
24
25/**
26 * Fetch all the information on modules we'll need in the activity chooser.
27 *
28 * @method activityModules
29 * @param {Number} courseid What course to fetch the modules for
30 * @return {object} jQuery promise
31 */
32export const activityModules = (courseid) => {
33 const request = {
806e736a 34 methodname: 'core_course_get_course_content_items',
05b27f21
MM
35 args: {
36 courseid: courseid,
37 },
38 };
39 return ajax.call([request])[0];
40};
6e1a4477
MM
41
42/**
43 * Given a module name, module ID & the current course we want to specify that the module
44 * is a users' favourite.
45 *
46 * @method favouriteModule
47 * @param {String} modName Frankenstyle name of the component to add favourite
48 * @param {int} modID ID of the module. Mainly for LTI cases where they have same / similar names
49 * @return {object} jQuery promise
50 */
51export const favouriteModule = (modName, modID) => {
52 const request = {
53 methodname: 'core_course_add_content_item_to_user_favourites',
54 args: {
55 componentname: modName,
56 contentitemid: modID,
57 },
58 };
59 return ajax.call([request])[0];
60};
61
62/**
63 * Given a module name, module ID & the current course we want to specify that the module
64 * is no longer a users' favourite.
65 *
66 * @method unfavouriteModule
67 * @param {String} modName Frankenstyle name of the component to add favourite
68 * @param {int} modID ID of the module. Mainly for LTI cases where they have same / similar names
69 * @return {object} jQuery promise
70 */
71export const unfavouriteModule = (modName, modID) => {
72 const request = {
73 methodname: 'core_course_remove_content_item_from_user_favourites',
74 args: {
75 componentname: modName,
76 contentitemid: modID,
77 },
78 };
79 return ajax.call([request])[0];
80};
16d77f18
MM
81
82/**
83 * Fetch all the information on modules we'll need in the activity chooser.
84 *
85 * @method fetchFooterData
86 * @param {Number} courseid What course to fetch the data for
87 * @param {Number} sectionid What section to fetch the data for
88 * @return {object} jQuery promise
89 */
90export const fetchFooterData = (courseid, sectionid) => {
91 const request = {
92 methodname: 'core_course_get_activity_chooser_footer',
93 args: {
94 courseid: courseid,
95 sectionid: sectionid,
96 },
97 };
98 return ajax.call([request])[0];
99};