-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathUtils.php
More file actions
executable file
·182 lines (151 loc) · 5.04 KB
/
Copy pathUtils.php
File metadata and controls
executable file
·182 lines (151 loc) · 5.04 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<?php
/**
*
* @purpose : CRUD functions for Moodle
* @author : Sanjay Kumar sanjay.kumar001@gmail.com
*
**/
require_once('MoodleRest.php');
// Course
function get_courses(){
$ws_function = 'core_course_get_courses';
$param = array("criteria" => array());
return get_moodle_data($ws_function, $param);
}
function create_courses($courses){
$ws_function = 'core_course_create_courses';
$param = array("courses" => $courses);
return push_data_to_moodle($ws_function, $param);
}
function update_courses($courses){
$ws_function = 'core_course_update_courses';
$param = array("courses" => $courses);
return push_data_to_moodle($ws_function, $param);
}
function delete_courses($courseids){
$ws_function = 'core_course_delete_courses';
$param = array("courseids" => $courseids);
return push_data_to_moodle($ws_function, $param);
}
// Category and Sub Category
function create_categories($course_category){
$ws_function = 'core_course_create_categories';
$param = array("categories" => $course_category);
return push_data_to_moodle($ws_function, $param);
}
function get_categories($criteria){
$ws_function = 'core_course_get_categories';
$param = array("criteria" => $criteria);
return get_moodle_data($ws_function, $param);
}
function delete_categories($categories){
$ws_function = 'core_course_delete_categories';
$param = array("categories" => $categories);
return push_data_to_moodle($ws_function, $param);
}
function update_categories($categories){
$ws_function = 'core_course_update_categories';
$param = array("categories" => $categories);
return push_data_to_moodle($ws_function, $param);
}
// User
function create_users($users){
$ws_function = 'core_user_create_users';
$param = array("users" => $users);
return push_data_to_moodle($ws_function, $param);
}
function get_users(){
$ws_function = 'core_user_get_users';
$param = array("criteria" => array());
return get_moodle_data($ws_function, $param);
}
function get_users_by_field($field, $values){
$ws_function = 'core_user_get_users_by_field';
$param = array("field" => $field, 'values' => $values);
return get_moodle_data($ws_function, $param);
}
function update_users($users){
$ws_function = 'core_user_update_users';
$param = array("users" => $users);
return push_data_to_moodle($ws_function, $param);
}
function delete_users($userids){
$ws_function = 'core_user_delete_users';
$param = array("userids" => $userids);
return push_data_to_moodle($ws_function, $param);
}
// Role
function assign_roles($assignments){
$ws_function = 'core_role_assign_roles';
$param = array("assignments" => $assignments);
return push_data_to_moodle($ws_function, $param);
}
// Cohorts
function get_cohorts($cohortids){
$ws_function = 'core_cohort_get_cohorts';
$param = array("cohortids" => $cohortids);
return get_moodle_data($ws_function, $param);
}
function search_cohorts($query, $context, $includes='parents'){
$ws_function = 'core_cohort_search_cohorts';
$param = array("query" => $query, "context" => $context, "includes" => $includes);
return get_moodle_data($ws_function, $param);
}
function create_cohorts($cohorts){
$ws_function = 'core_cohort_create_cohorts';
$param = array("cohorts" => $cohorts);
return push_data_to_moodle($ws_function, $param);
}
function update_cohorts($cohorts){
$ws_function = 'core_cohort_update_cohorts';
$param = array("cohorts" => $cohorts);
return push_data_to_moodle($ws_function, $param);
}
function delete_cohorts($cohortids){
$ws_function = 'core_cohort_delete_cohorts';
$param = array("cohortids" => $cohortids);
return push_data_to_moodle($ws_function, $param);
}
// Cohorts Enrollment
function get_cohort_members($cohortids){
$ws_function = 'core_cohort_get_cohort_members';
$param = array("cohortids" => $cohortids);
return get_moodle_data($ws_function, $param);
}
function add_cohort_members($members){
$ws_function = 'core_cohort_add_cohort_members';
$param = array("members" => $members);
return push_data_to_moodle($ws_function, $param);
}
function delete_cohort_members($members){
$ws_function = 'core_cohort_delete_cohort_members';
$param = array("members" => $members);
return push_data_to_moodle($ws_function, $param);
}
// Calendar
function create_calendar_events($events){
$ws_function = 'core_calendar_create_calendar_events';
$param = array("events" => $events);
return push_data_to_moodle($ws_function, $param);
}
function get_moodle_data($ws_function, $param){
$config = include('Config.php');
$MoodleRest = new MoodleRest($config->server_address, $config->token);
return $MoodleRest->request($ws_function, $param, MoodleRest::METHOD_GET);
}
function push_data_to_moodle($ws_function, $param){
$config = include('Config.php');
$MoodleRest = new MoodleRest($config->server_address, $config->token);
return $MoodleRest->request($ws_function, $param, MoodleRest::METHOD_POST);
}
function get_key_map($data, $keyfield, $valuefield){
$result = array();
foreach($data as $d){
$result[$d[$keyfield]] = $d[$valuefield];
}
return $result;
}
function convert_to_timestamp($datetime){
$date = new DateTime($datetime);
return $date->getTimestamp();
}