Rev 1279 | Rev 1285 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1279 | Rev 1280 | ||
---|---|---|---|
Line 85... | Line 85... | ||
85 | */ |
85 | */ |
86 | public function restApiCall(string $requestMethod, string $endpoint, array $json_in) { |
86 | public function restApiCall(string $requestMethod, string $endpoint, array $json_in) { |
87 | if (str_starts_with($endpoint, 'objects/')) { |
87 | if (str_starts_with($endpoint, 'objects/')) { |
88 | $id = substr($endpoint, strlen('objects/')); |
88 | $id = substr($endpoint, strlen('objects/')); |
89 | if ($requestMethod == "GET"/*Select*/) { |
89 | if ($requestMethod == "GET"/*Select*/) { |
- | 90 | $obj = OIDplusObject::findFitting($id); |
|
- | 91 | if (!$obj) throw new OIDplusException(_L('The object %1 was not found in this database.', $id), null, 404); |
|
- | 92 | ||
- | 93 | if (!$obj->userHasReadRights()) throw new OIDplusException('Insufficient authorization to read information about this object.', null, 401); |
|
- | 94 | ||
90 | $output = array(); |
95 | $output = array(); |
91 | 96 | ||
92 | $res = OIDplus::db()->query("select id, ra_email, comment, confidential, title, description from ###objects where id = ?", array($id)); |
- | |
93 | if (!$res->any()) throw new OIDplusException(_L('The object %1 was not found in this database.', $id), null, 404); |
97 | $output['status'] = 0/*OK*/; |
94 | $row = $res->fetch_array(); |
98 | $output['status_bits'] = []; |
95 | 99 | ||
96 | //$output['id'] = $row['id']; |
100 | //$output['id'] = $obj->nodeId(true); |
97 | $output['ra_email'] = $row['ra_email']; |
101 | $output['ra_email'] = $obj->getRaMail(); |
98 | $output['comment'] = $row['comment']; |
102 | $output['comment'] = $obj->getComment(); |
99 | $output['confidential'] = $row['confidential']; |
103 | $output['confidential'] = $obj->isConfidential(); |
100 | $output['title'] = $row['title']; |
104 | $output['title'] = $obj->getTitle(); |
101 | $output['description'] = $row['description']; |
105 | $output['description'] = $obj->getDescription(); |
102 | 106 | ||
103 | $output['asn1ids'] = array(); |
107 | if ($obj instanceof OIDplusOid) { |
104 | $res_asn = OIDplus::db()->query("select name from ###asn1id where oid = ?", array($id)); |
108 | $output['asn1ids'] = array(); // TODO: Rename to oid-alphanum-id ? |
105 | while ($row_asn = $res_asn->fetch_array()) { |
109 | foreach ($obj->getAsn1Ids() as $asn) { |
106 | $output['asn1ids'][] = $row_asn['name']; |
110 | $output['asn1ids'][] = $asn->getName(); |
107 | } |
111 | } |
108 | 112 | ||
109 | $output['iris'] = array(); |
113 | $output['iris'] = array(); // TODO: Rename to oid-unicode-label ? |
110 | $res_iri = OIDplus::db()->query("select name from ###iri where oid = ?", array($id)); |
- | |
111 | while ($row_iri = $res_iri->fetch_array()) { |
114 | foreach ($obj->getIris() as $iri) { |
112 | $output['iris'][] = $row_iri['name']; |
115 | $output['iris'][] = $iri->getName(); |
113 | } |
116 | } |
114 | 117 | } |
|
115 | $output_prepend['status'] = 0/*OK*/; |
- | |
116 | $output_prepend['status_bits'] = []; |
- | |
117 | $output = array_merge($output_prepend, $output); |
- | |
118 | 118 | ||
119 | http_response_code(200); |
119 | http_response_code(200); |
120 | return $output; |
120 | return $output; |
121 | } else if ($requestMethod == "PUT"/*Replace*/) { |
121 | } else if ($requestMethod == "PUT"/*Replace*/) { |
122 | $obj = OIDplusObject::parse($id); |
122 | $obj = OIDplusObject::parse($id); |
Line 215... | Line 215... | ||
215 | 'status ('._L('<0 is error, >=0 is success').')', |
215 | 'status ('._L('<0 is error, >=0 is success').')', |
216 | 'status_bits', |
216 | 'status_bits', |
217 | 'error ('._L('if an error occurred').')', |
217 | 'error ('._L('if an error occurred').')', |
218 | 'ra_email', |
218 | 'ra_email', |
219 | 'comment', |
219 | 'comment', |
220 | 'iris', |
220 | 'iris ('._L('for OID only').')', |
221 | 'asn1ids', |
221 | 'asn1ids ('._L('for OID only').')', |
222 | 'confidential', |
222 | 'confidential', |
223 | 'title', |
223 | 'title', |
224 | 'description' |
224 | 'description' |
225 | ] |
225 | ] |
226 | ], |
226 | ], |