forked from miguelfazenda/gerador-horarios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-courses.php
36 lines (28 loc) · 1015 Bytes
/
get-courses.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
<?php
/* Returns a list of courses for a given degree.
Params: ID (degree id)
*/
function get_courses_for_degree($degree) {
$json = file_get_contents('https://fenix.tecnico.ulisboa.pt/api/fenix/v1/degrees/' . $degree . '/courses?academicTerm=2018/2019');
$courses = json_decode($json);
$coursesById = array();
foreach($courses as $course){
$coursesById[$course->id] = $course;
}
return $coursesById;
}
function sort_courses($courses) {
$sortArray = array();
foreach($courses as $course){
$sortArray[$course->acronym] = $course;
}
//var_dump($sortArray);
sort($sortArray);
return $sortArray;
}
$degree = filter_var($_GET['id'], FILTER_SANITIZE_NUMBER_INT);
$courses = get_courses_for_degree($degree);
$courses_sorted = sort_courses($courses);
header('Content-Type: application/json');
echo json_encode($courses);
?>