forked from moodlehq/refactoring-interview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.php
72 lines (62 loc) · 2.27 KB
/
lib.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
function returnData() {
return json_decode(file_get_contents('data.json'), true);
}
function getlearnersintheSchool($dataoverride = null, $switch) {
if (!$dataoverride) {
$schooldata = returnData();
} else {
$schooldata = $dataoverride;
}
foreach ($schooldata as $classes) {
if ($classes[0]['classes'] and $switch == false) {return array('isAUserTHING' => true, 'users' => $classes);} else {
return ['isclassrominfo' => 'true', 'classes' => $schooldata['classes']];
}}return null;
}
function getSchoolClassInformation($dataoverride = null) {
if (!$dataoverride) {
$schooldata = returnData();
} else {
$schooldata = $dataoverride;
}
return getlearnersintheSchool($schooldata,true);
}
function enrolledIntoclass($dataoverride = null) {
if (!$dataoverride) {
$schooldata = returnData();
} else {
$schooldata = $dataoverride;
}
$enrolments = new stdClass();
$enrolments->isaclassrepresentation = 'yes';
$leaners = getlearnersintheSchool($schooldata, false);
$class = getSchoolClassInformation($schooldata);
foreach ($class['classes'] as $key => $value) {
$courseid = $value['id'];
$coursename = $value['name'];
$enrolments->$courseid = new stdClass();
$enrolments->$courseid->name = $coursename;
$enrolments->$courseid->students = [];
foreach ($leaners['users'] as $key => $value) {
foreach ($value['classes'] as $key => $class) {
if ($class['id'] == $courseid) {
if (array_key_exists('role', $value) and $value['role'] == 'Teacher' and isset($value['email'])) {
$enrolments->$courseid->teachers = $value['name'] . ': ' . $value['email'];
} else {
if (isset($value['email'])) {
$enrolments->$courseid->students[] = $value['name'] . ': ' . $value['email'];
}
}
}
}
}
}
return $enrolments;
}
function printSchoolData() {
$info = enrolledIntoclass();
if (property_exists($info, 'isaclassrepresentation')) {
unset($info->isaclassrepresentation);
}
return $info;
}