-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscatter.php
46 lines (37 loc) · 1.02 KB
/
scatter.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
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
// read configuration file
$config = parse_ini_file("../stacks-website/config.ini");
// initialize the global database object
try {
$database = new PDO("sqlite:../stacks-website/" . $config["database"]);
}
catch(PDOException $e) {
echo $e->getMessage();
}
function getScatterData() {
global $database;
$sql = $database->prepare("SELECT tag, book_page AS page, book_id, type FROM tags");
if ($sql->execute())
return $sql->fetchAll();
}
$scatter = getScatterData();
// process data
foreach ($scatter as $id => $tag) {
if ($tag["type"] == "item")
$scatter[$id]["chapter"] = 0;
else {
$scatter[$id]["chapter"] = explode(".", $tag["book_id"]);
$scatter[$id]["chapter"] = $scatter[$id]["chapter"][0];
}
// less data footprint
unset($scatter[$id]["0"]);
unset($scatter[$id]["1"]);
unset($scatter[$id]["2"]);
unset($scatter[$id]["3"]);
unset($scatter[$id]["book_id"]);
unset($scatter[$id]["type"]);
}
print json_encode($scatter);
?>