1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* Amanote external api.
|
|
|
19 |
*
|
|
|
20 |
* @package filter_amanote
|
|
|
21 |
* @copyright 2020 Amaplex Software
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
defined('MOODLE_INTERNAL') || die;
|
|
|
26 |
|
|
|
27 |
require_once($CFG->libdir . "/externallib.php");
|
|
|
28 |
require_once(__DIR__ . "/helpers/notificationhelper.php");
|
|
|
29 |
|
|
|
30 |
/**
|
|
|
31 |
* Amanote external functions.
|
|
|
32 |
*
|
|
|
33 |
* @copyright 2020 Amaplex Software
|
|
|
34 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
35 |
*/
|
|
|
36 |
class filter_amanote_external extends external_api {
|
|
|
37 |
|
|
|
38 |
/**
|
|
|
39 |
* Returns description of method parameters.
|
|
|
40 |
*
|
|
|
41 |
* @return external_function_parameters
|
|
|
42 |
*/
|
|
|
43 |
public static function can_update_course_parameters() {
|
|
|
44 |
return new external_function_parameters(
|
|
|
45 |
[
|
|
|
46 |
'courseid' => new external_value(PARAM_INT, 'id of the course'),
|
|
|
47 |
]
|
|
|
48 |
);
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
/**
|
|
|
52 |
* Determine if the user can update a specific Amanote resource.
|
|
|
53 |
*
|
|
|
54 |
* @param integer $courseid File id.
|
|
|
55 |
*
|
|
|
56 |
* @return boolean True if current user can update the amanote resource
|
|
|
57 |
*/
|
|
|
58 |
public static function can_update_course($courseid) {
|
|
|
59 |
global $DB;
|
|
|
60 |
// Parameters validation.
|
|
|
61 |
$params = self::validate_parameters(self::can_update_course_parameters(),
|
|
|
62 |
['courseid' => $courseid]);
|
|
|
63 |
|
|
|
64 |
if (is_nan($courseid) || $courseid < 0) {
|
|
|
65 |
throw new invalid_parameter_exception('Invalid course id');
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
$context = context_course::instance($courseid, MUST_EXIST);
|
|
|
69 |
|
|
|
70 |
if ($context && has_capability('moodle/course:update', $context)) {
|
|
|
71 |
return true;
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
return false;
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
/**
|
|
|
78 |
* Returns description of method result value.
|
|
|
79 |
*
|
|
|
80 |
* @return external_description
|
|
|
81 |
*/
|
|
|
82 |
public static function can_update_course_returns() {
|
|
|
83 |
return new external_value(PARAM_BOOL, 'true if the current user can update the course');
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
/**
|
|
|
87 |
* Returns description of method parameters.
|
|
|
88 |
*
|
|
|
89 |
* @return external_function_parameters
|
|
|
90 |
*/
|
|
|
91 |
public static function notify_parameters() {
|
|
|
92 |
return new external_function_parameters(
|
|
|
93 |
[
|
|
|
94 |
'kind' => new external_value(PARAM_TEXT, 'the notification kind (e.g. "submission")'),
|
|
|
95 |
'annotatableid' => new external_value(PARAM_TEXT, 'id of the annotatable'),
|
|
|
96 |
]
|
|
|
97 |
);
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
/**
|
|
|
101 |
* Send a notification related to a given annotatable.
|
|
|
102 |
*
|
|
|
103 |
* @param string $kind The kind of notification.
|
|
|
104 |
* @param integer $annotatableid The annotatable id.
|
|
|
105 |
*
|
|
|
106 |
* @return array An array containing the ids of sent notifications.
|
|
|
107 |
*/
|
|
|
108 |
public static function notify($kind, $annotatableid) {
|
|
|
109 |
global $USER;
|
|
|
110 |
|
|
|
111 |
return send_annotatable_notifications($kind, $annotatableid);
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
/**
|
|
|
115 |
* Returns description of method result value.
|
|
|
116 |
*
|
|
|
117 |
* @return external_description
|
|
|
118 |
*/
|
|
|
119 |
public static function notify_returns() {
|
|
|
120 |
return new external_multiple_structure(
|
|
|
121 |
new external_value(PARAM_INT, 'the ids of the notifications sent.')
|
|
|
122 |
);
|
|
|
123 |
}
|
|
|
124 |
}
|