GetRelations.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. } catch (HttpException $e) {
  16. DBG::log($e);
  17. throw new Api_OwsException($e->getMessage(), $e->getCode(), null, Http::getStatusText($e->getCode()), 'request');
  18. } catch (Exception $e) {
  19. DBG::log($e);
  20. throw new Api_OwsException("User is not allowed to read relations from '{$typeName}.{$primaryKey}' to '{$remoteTypeName}'.\n" . $e->getMessage(), 501, null, 'AccessDenied', 'request');
  21. }
  22. header('Content-Type: application/json');
  23. echo json_encode([
  24. 'type' => "success",
  25. 'msg' => "done",
  26. 'body' => [
  27. 'relations' => $listRelations,
  28. // 'total' => $total,
  29. ]
  30. ]);
  31. exit;
  32. }
  33. }