-
Notifications
You must be signed in to change notification settings - Fork 3
/
rgrade_json_data.php
99 lines (74 loc) · 2.31 KB
/
rgrade_json_data.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
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
<?php
define('AJAX_SCRIPT', true);
define('NO_DEBUG_DISPLAY', true);
header("Content-Type: application/json; charset=UTF-8");
require_once("../../config.php");
require_once('rgrade_lib.php');
global $DB;
$courseid = optional_param('courseid', '', PARAM_NUMBER);
if(!$courseid) {
rgrade_json_error("Course required");
}
$course = rgrade_get_course($courseid);
if(!$course) {
rgrade_json_error("Course does not exists: $courseid");
}
$bookid = optional_param('bookid', '', PARAM_NUMBER);
$book = rgrade_get_book_from_course($courseid, $bookid);
if(!$book) {
rgrade_json_error('Book not valid');
}
$data = array();
$data['students'] = array();
$students = rgrade_get_all_students($courseid);
foreach ($students as $student) {
$sid = (int) $student->id;
$data['students'][] = array(
'id' => $sid,
'lastname' => $student->lastname,
'firstname' => $student->firstname);
}
$data['groups'] = array();
$groups = rgrade_get_groups_studentsid($courseid);
foreach ($groups as $group) {
$gid = (int) $group->groupid;
if(!isset($data['groups'][$gid])){
$data['groups'][$gid] = array(
'id' => $gid,
'name' => $group->groupname,
'studentids' => array());
}
$data['groups'][$gid]['studentids'][] = (int) $group->userid;
}
$data['groups'] = array_values($data['groups']);
$data['scores'] = $ENUM_SCORES;
$data['status'] = $ENUM_STATUS;
$data['book'] = array('id' => $book->id, 'name' => $book->name, 'units' => array());
$units = rgrade_get_recordset_units($book->id);
foreach ($units as $unit) {
$uid = (int) $unit->id;
if(!isset($data['book']['units'][$uid])){
$data['book']['units'][$uid] = array(
'id' => $uid,
'code' => $unit->code,
'name' => $unit->name);
$data['book']['units'][$uid]['activities'] = array();
}
}
$activities = rgrade_get_recordset_activities($book->id);
foreach ($activities as $activity) {
$uid = (int) $activity->unitid;
if(!isset($data['book']['units'][$uid])){
$data['book']['units'][$uid] = array(
'id' => $uid,
'code' => $activity->unitcode,
'name' => $activity->unitname);
$data['book']['units'][$uid]['activities'] = array();
}
$data['book']['units'][$uid]['activities'][] = array(
'id' => (int) $activity->id,
'code' => $activity->code,
'name' => $activity->name);
}
$data['book']['units'] = array_values($data['book']['units']);
echo json_encode($data);