GetRelations.php 1.3 KB

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. Lib::loadClass('Relations');
  3. class Api_Process_P5_GetRelations { // TODO: extends Api_ProcessBase
  4. static function run($args, $responseForm) {
  5. $typeName = (!empty($args['typeName'][0])) ? $args['typeName'][0] : '';
  6. if (!$typeName) throw new Api_OwsException("Missing value for 'typeName'", 501, null, 'MissingParameterValue', 'request');
  7. $primaryKey = (!empty($args['primaryKey'][0])) ? $args['primaryKey'][0] : '';
  8. if (!$primaryKey) throw new Api_OwsException("Missing value for 'primaryKey'", 501, null, 'MissingParameterValue', 'request');
  9. $remoteTypeName = (!empty($args['remoteTypeName'][0])) ? $args['remoteTypeName'][0] : '';
  10. if (!$remoteTypeName) throw new Api_OwsException("Missing value for 'remoteTypeName'", 501, null, 'MissingParameterValue', 'request');
  11. if (!Relations::isAllowedToGetRelation($userLogin, $typeName, $primaryKey, $remoteTypeName)) {
  12. throw new Api_OwsException("User is not allowed to view relations from '{$typeName}.{$primaryKey}' to '{$remoteTypeName}' ", 501, null, 'AccessDenied', 'request');
  13. }
  14. $listRelations = Relations::getRelations($typeName, $primaryKey);
  15. header('Content-Type: application/json');
  16. echo json_encode([
  17. 'type' => "success",
  18. 'msg' => "done",
  19. 'body' => [
  20. 'relations' => $listRelations,
  21. // 'total' => $total,
  22. ]
  23. ]);
  24. exit;
  25. }
  26. }