-
Notifications
You must be signed in to change notification settings - Fork 1
/
user.php
80 lines (76 loc) · 1.95 KB
/
user.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
<?php
require_once('model/user_model.php');
if (isset($_GET['data']))
{
switch ($_GET['data'])
{
case "users":
$user_model = new User_model();
$users = $user_model->get_users();
header('Content-type: application/json');
echo parse_users_to_json($users);
break;
case "users-sorted-by-last-name":
if (isset($_GET['order']))
{
$user_model = new User_model();
$users = $user_model->get_users_sorted_by_last_name($_GET['order']);
header('Content-type: application/json');
echo parse_users_to_json($users);
}
break;
case "users-sorted-by-academic-year":
if (isset($_GET['order']))
{
$user_model = new User_model();
$users = $user_model->get_users_sorted_by_academic_year($_GET['order']);
header('Content-type: application/json');
echo parse_users_to_json($users);
}
break;
case "users-filtered-by-first-name":
if (isset($_GET['filter']))
{
$user_model = new User_model();
$users = $user_model->get_users_filtered_by_first_name($_GET['filter']);
header('Content-type: application/json');
echo parse_users_to_json($users);
}
break;
case "users-filtered-by-last-name":
if (isset($_GET['filter']))
{
$user_model = new User_model();
$users = $user_model->get_users_filtered_by_last_name($_GET['filter']);
header('Content-type: application/json');
echo parse_users_to_json($users);
}
break;
case "users-filtered-by-academic-year":
if (isset($_GET['filter']))
{
$user_model = new User_model();
$users = $user_model->get_users_filtered_by_academic_year($_GET['filter']);
header('Content-type: application/json');
echo parse_users_to_json($users);
}
break;
default:
header("HTTP/1.0 404 Not Found");
die();
}
}
function parse_users_to_json($users)
{
if ($users)
{
$json_users = array();
foreach($users as $user)
{
array_push($json_users, $user->to_json());
}
return json_encode($json_users);
}
return null;
}
?>