-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexternallib.php
53 lines (43 loc) · 1.62 KB
/
externallib.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
defined('MOODLE_INTERNAL') || die();
require_once("$CFG->libdir/externallib.php");
use local_ws_courselist\tools;
use local_ws_courselist\exceptions\course_not_found_exception;
class local_ws_courselist_external extends external_api {
public static function get_courses_parameters() {
return new external_function_parameters([]);
}
public static function get_courses() {
global $DB;
// Check permissions and context
$context = context_system::instance();
tools::validate_course_access($context);
// Retrieve visible courses with their categoryid
$courses = tools::get_visible_courses();
if (!$courses) {
throw new course_not_found_exception();
}
$result = [];
foreach ($courses as $course) {
$result[] = [
'id' => $course->id,
'fullname' => $course->fullname,
'shortname' => $course->shortname,
'categoryid' => $course->category,
];
}
return $result;
}
public static function get_courses_returns() {
return new external_multiple_structure(
new external_single_structure(
[
'id' => new external_value(PARAM_INT, 'Course ID'),
'fullname' => new external_value(PARAM_TEXT, 'Full name of the course'),
'shortname' => new external_value(PARAM_TEXT, 'Short name of the course'),
'categoryid' => new external_value(PARAM_INT, 'Category ID of the course'),
]
)
);
}
}