| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- Lib::loadClass('Relations');
- Lib::loadClass('Http');
- class Api_Process_P5_GetRelations { // TODO: extends Api_ProcessBase
- static function run($args, $responseForm) {
- $typeName = (!empty($args['typeName'][0])) ? $args['typeName'][0] : '';
- if (!$typeName) throw new Api_OwsException("Missing value for 'typeName'", 501, null, 'MissingParameterValue', 'request');
- $primaryKey = (!empty($args['primaryKey'][0])) ? $args['primaryKey'][0] : '';
- if (!$primaryKey) throw new Api_OwsException("Missing value for 'primaryKey'", 501, null, 'MissingParameterValue', 'request');
- $remoteTypeName = (!empty($args['remoteTypeName'][0])) ? $args['remoteTypeName'][0] : '';
- if (!$remoteTypeName) throw new Api_OwsException("Missing value for 'remoteTypeName'", 501, null, 'MissingParameterValue', 'request');
- try {
- Relations::isAllowedToGetRelation($userLogin = User::getLogin(), $typeName, $primaryKey, $remoteTypeName);
- $listRelations = Relations::getRelations($typeName, $primaryKey, $remoteTypeName);
- $totalRelations = count($listRelations);
- } catch (HttpException $e) {
- DBG::log($e);
- throw new Api_OwsException($e->getMessage(), $e->getCode(), null, Http::getStatusText($e->getCode()), 'request');
- } catch (Exception $e) {
- DBG::log($e);
- throw new Api_OwsException("User is not allowed to read relations from '{$typeName}.{$primaryKey}' to '{$remoteTypeName}'.\n" . $e->getMessage(), 501, null, 'AccessDenied', 'request');
- }
- header('Content-Type: application/json');
- echo json_encode([
- 'type' => "success",
- 'msg' => "done",
- 'body' => [
- 'relationSource' => [
- 'namespace' => Api_WfsNs::toNamespace($typeName),
- 'primaryKey' => $primaryKey,
- 'featureID' => Api_WfsNs::toTypeName($typeName) . ".{$primaryKey}",
- ],
- 'relationTarget' => [
- 'typeName' => Api_WfsNs::toTypeName($remoteTypeName),
- ],
- 'total' => $totalRelations,
- 'relations' => $listRelations,
- // 'DBG__total' => ACL::fetchRefs(Api_WfsNs::toNamespace($typeName), $primaryKey, $remoteTypeName, [ 'total' => true ]),
- ]
- ]);
- exit;
- }
- }
|