-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathpath.php
More file actions
152 lines (131 loc) · 4.62 KB
/
Copy pathpath.php
File metadata and controls
152 lines (131 loc) · 4.62 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
/**
* @api {get} /api/houses/house/:treeOrFrom get tree
*
* @apiVersion 1.0.0
*
* @apiName getPathPart
* @apiGroup houses
*
* @apiHeader {String} Authorization authentication token
*
* @apiParam {String} treeOrFrom tree or parent
* @apiQuery {String} [search]
* @apiQuery {String} [from]
* @apiQuery {String} [tree]
* @apiQuery {Boolean} [withParents]
*
* @apiSuccess {Object[]} tree
*/
/**
* @api {post} /api/houses/house/:parentId add node
*
* @apiVersion 1.0.0
*
* @apiName addTreeNode
* @apiGroup houses
*
* @apiHeader {String} Authorization authentication token
*
* @apiParam {Number} parentId
* @apiBody {String} text
* @apiBody {String} icon
* @apiBody {String="list","map"} [type=list]
* @apiBody {String} [visibleForFlats] comma-separated flat numbers and ranges, e.g. "1,3,10-20"; empty inherits from parent
*
* @apiSuccess {Number} nodeId
*/
/**
* @api {put} /api/houses/house/:nodeId modify node
*
* @apiVersion 1.0.0
*
* @apiName modifyTreeNode
* @apiGroup houses
*
* @apiHeader {String} Authorization authentication token
*
* @apiParam {Number} nodeId
* @apiBody {String} text
* @apiBody {String} icon
* @apiBody {String="list","map"} [type]
* @apiBody {String} [visibleForFlats] comma-separated flat numbers and ranges, e.g. "1,3,10-20"; empty inherits from parent
*
* @apiSuccess {Boolean} oprationResult
*/
/**
* @api {delete} /api/houses/house/:nodeId delete node
*
* @apiVersion 1.0.0
*
* @apiName deleteTreeNode
* @apiGroup houses
*
* @apiHeader {String} Authorization authentication token
*
* @apiParam {Number} nodeId
*
* @apiSuccess {Boolean} oprationResult
*/
/**
* houses api
*/
namespace api\houses {
use api\api;
/**
* path method
*/
class path extends api {
public static function GET($params) {
$households = loadBackend("households");
if (!$households) {
return api::ERROR();
} else {
$tree = [];
if (@$params["search"]) {
$tree = $households->searchPath($params["_id"], $params["search"]);
} else {
$tree = $households->getPath($params["_id"], !!@$params["withParents"], false, !!@$params["withParents"] ? $params["_id"] : false, @$params["tree"]);
}
return api::ANSWER($tree, "tree");
}
}
public static function POST($params) {
$households = loadBackend("households");
if (!$households) {
return api::ERROR();
} else {
if ((int)$params["_id"]) {
return api::ANSWER($households->addPathNode($params["_id"], @$params["text"], @$params["icon"], @$params["type"] ?: "list", @$params["visibleForFlats"]), "nodeId");
} else {
return api::ANSWER($households->addRootPathNode($params["_id"], @$params["text"], @$params["icon"], @$params["type"] ?: "list", @$params["visibleForFlats"]), "nodeId");
}
}
}
public static function PUT($params) {
$households = loadBackend("households");
if (!$households) {
return api::ERROR();
} else {
$visibleForFlats = array_key_exists("visibleForFlats", $params) ? $params["visibleForFlats"] : false;
return api::ANSWER($households->modifyPathNode($params["_id"], @$params["text"], @$params["icon"], @$params["type"], $visibleForFlats));
}
}
public static function DELETE($params) {
$households = loadBackend("households");
if (!$households) {
return api::ERROR();
} else {
return api::ANSWER($households->deletePathNode($params["_id"]));
}
}
public static function index() {
return [
"GET" => "#same(addresses,house,GET)",
"POST" => "#same(addresses,house,POST)",
"PUT" => "#same(addresses,house,PUT)",
"DELETE" => "#same(addresses,house,DELETE)",
];
}
}
}