forked from iv-enovation/auth
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcourse_mapping.php
More file actions
51 lines (45 loc) · 2.18 KB
/
course_mapping.php
File metadata and controls
51 lines (45 loc) · 2.18 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
<?php
$role_mapping = array();
$course_mapping = array();
try {
$config = get_config('auth/saml');
require_once ("roles.php");
require_once ("courses.php");
$role_mapping = get_role_mapping_for_sync($err, $config);
$course_mapping = get_course_mapping_for_sync($err, $config);
}
catch(Exception $e) {
print_error('Caught exception while mapping: '. $e->getMessage(). "\n");
}
$mapped_roles = array_unique(array_values($role_mapping));
$mapped_courses = array();
foreach($saml_courses as $key => $course) {
if (function_exists('saml_hook_get_course_info')) {
$regs = saml_hook_get_course_info($course);
if ($regs) {
list($match, $country, $domain, $course_id, $period, $role, $status) = $regs;
if(isset($role_mapping[$role]) && isset($course_mapping[$course_id][$period])) {
$mapped_role = $role_mapping[$role];
$mapped_course_id = $course_mapping[$course_id][$period];
$mapped_courses[$mapped_role][$status][$mapped_course_id] = array( 'country' => $country,
'domain' => $domain,
'course_id' => $mapped_course_id,
'period' => $period,
'role' => $mapped_role,
'status' => $status,
);
if(!$any_course_active && $status == 'active') {
$any_course_active = true;
}
}
else {
$str_obj = new stdClass();
$str_obj->course = '('.$course_id.' -- '.$period.')';
$str_obj->user = $saml_user_identify;
$err['course_enrollment'][] = get_string('auth_saml_course_not_found' , 'auth_saml', $str_obj);
}
}
}
}
unset($saml_courses);
unset($saml_user_identify);