-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson2.php
47 lines (42 loc) · 1.47 KB
/
json2.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
<?
// INITIALIZE
date_default_timezone_set('America/Denver'); //timezone for modified date
require_once('lib/rb.php'); // Redbean ORM v3.4 for database handling
R::setup('sqlite:admin/abx-db'); //connect redbean to the database
// get the version number
$ver = R::load('version', 1);
// Organs array
$organs_dump = R::findAll('organ', ' ORDER BY orderid');
$organs = [];
foreach ($organs_dump as $organ) {
$infections = R::find('infection', ' organ_id = ? ORDER BY orderid', array($organ->id));
$infections = R::exportAll($infections, true, array('infection'));
$organs[$organ->id] = array(
'id' => $organ->id,
'name' => $organ->name,
'infections' => $infections
);
}
// Infections array
$infections_dump = R::findAll('infection');
$infections = [];
foreach ($infections_dump as $infection) {
$treatments = R::find('treatment', ' infection_id = ? ORDER BY orderid', array($infection->id));
$treatments = R::exportAll($treatments);
$infections[$infection->id] = array(
'id' => $infection->id,
'title' => $infection->title,
'subtitle' => $infection->subtitle,
'treatments' => $treatments
);
}
$e = array(
'version' => $ver->version,
'modified' => date('d M Y', strtotime($ver->modified)),
'organs' => $organs,
'infections' => $infections
);
// send back JSON encoded data
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
echo json_encode($e, JSON_PRETTY_PRINT);