-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.php
More file actions
74 lines (64 loc) · 2.17 KB
/
api.php
File metadata and controls
74 lines (64 loc) · 2.17 KB
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
<?php
//headers
header('Access-Control-Allow-Origin: *');
header('Content-Type: application/json');
include_once './config/config.php';
include_once './models/Model.php';
include_once './config/errors.php';
include_once './config/urlCheck.php';
//collecting GET optional params
$page_num = ($_GET['page_num'] == null) ? 0 : $_GET['page_num']; //optional
$page_size = ($_GET['page_size'] == null) ? 100 : $_GET['page_size']; //optional
$erroObject = new Err();
$urlValidity = isURLValid($erroObject);
if($urlValidity['isValid'] == false) {
$response['error'] = $urlValidity['errorMsg'];
echo json_encode($response);
} else {
//instatntiate DB and conect
$database = new Database();
$db = $database->connect();
//instantiate data object
$tree = new Model($db);
//Tree data query
$checkSearchname = $tree->checkIfNameExist($_GET['search']);
if($num = $checkSearchname->rowCount() == 0) {
echo json_encode(
array('error' => $erroObject->noNodeName($_GET['search']) )
);
} else {
if($tree->nodeID_searchString_match($_GET['node_id'], $_GET['search']) == 0) {
echo json_encode(array('error' => $erroObject->nodeID_nodeName_mismatch($_GET['node_id'], $_GET['search'])));
} else {
$result = $tree->getTreeFromNode($_GET['node_id'], $_GET['search'], $_GET['language'], $page_size, $page_num);
$num = $result->rowCount();
if($num > 0) {
$response = array();
$response['data'] = array();
while($row = $result->fetch(PDO::FETCH_ASSOC)) {
extract($row);
if($idNode != $_GET['node_id']) {
$tree_item = array(
'idNode' => $idNode,
'NodeName' => $nodeName
);
array_push($response['data'], $tree_item);
}
}
if(count($response['data']) == 0) {
echo json_encode(
array('error' => $erroObject->noChildUnder($_GET['search']) )
);
} else {
echo json_encode($response);
}
} else {
//no matching data
echo json_encode(
array('error' => $erroObject->generalError() )
);
}
}
}
}
?>