GetRelations.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. Lib::loadClass('Relations');
  3. Lib::loadClass('Http');
  4. class Api_Process_P5_GetRelations { // TODO: extends Api_ProcessBase
  5. static function run($args, $responseForm) {
  6. $typeName = (!empty($args['typeName'][0])) ? $args['typeName'][0] : '';
  7. if (!$typeName) throw new Api_OwsException("Missing value for 'typeName'", 501, null, 'MissingParameterValue', 'request');
  8. $primaryKey = (!empty($args['primaryKey'][0])) ? $args['primaryKey'][0] : '';
  9. if (!$primaryKey) throw new Api_OwsException("Missing value for 'primaryKey'", 501, null, 'MissingParameterValue', 'request');
  10. $remoteTypeName = (!empty($args['remoteTypeName'][0])) ? $args['remoteTypeName'][0] : '';
  11. if (!$remoteTypeName) throw new Api_OwsException("Missing value for 'remoteTypeName'", 501, null, 'MissingParameterValue', 'request');
  12. try {
  13. Relations::isAllowedToGetRelation($userLogin = User::getLogin(), $typeName, $primaryKey, $remoteTypeName);
  14. $listRelations = Relations::getRelations($typeName, $primaryKey, $remoteTypeName);
  15. $totalRelations = count($listRelations);
  16. } catch (HttpException $e) {
  17. DBG::log($e);
  18. throw new Api_OwsException($e->getMessage(), $e->getCode(), null, Http::getStatusText($e->getCode()), 'request');
  19. } catch (Exception $e) {
  20. DBG::log($e);
  21. throw new Api_OwsException("User is not allowed to read relations from '{$typeName}.{$primaryKey}' to '{$remoteTypeName}'.\n" . $e->getMessage(), 501, null, 'AccessDenied', 'request');
  22. }
  23. header('Content-Type: application/json');
  24. echo json_encode([
  25. 'type' => "success",
  26. 'msg' => "done",
  27. 'body' => [
  28. 'relationSource' => [
  29. 'namespace' => Api_WfsNs::toNamespace($typeName),
  30. 'primaryKey' => $primaryKey,
  31. 'featureID' => Api_WfsNs::toTypeName($typeName) . ".{$primaryKey}",
  32. ],
  33. 'relationTarget' => [
  34. 'typeName' => Api_WfsNs::toTypeName($remoteTypeName),
  35. ],
  36. 'total' => $totalRelations,
  37. 'relations' => $listRelations,
  38. // 'DBG__total' => ACL::fetchRefs(Api_WfsNs::toNamespace($typeName), $primaryKey, $remoteTypeName, [ 'total' => true ]),
  39. ]
  40. ]);
  41. exit;
  42. }
  43. }