CreateRelation.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. Lib::loadClass('Relations');
  3. class Api_Process_P5_CreateRelation { // 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. $listRemotePrimaryKeys = (!empty($args['primaryKey'])) ? $args['remotePrimaryKey'] : [];
  12. if (empty($listRemotePrimaryKeys)) throw new Api_OwsException("Missing value for 'remotePrimaryKey'", 501, null, 'MissingParameterValue', 'request');
  13. if (!Relations::isAllowedToCreateRelation($userLogin, $typeName, $primaryKey, $remoteTypeName)) {
  14. throw new Api_OwsException("User is not allowed to create relation from '{$typeName}.{$primaryKey}' to '{$remoteTypeName}' ", 501, null, 'AccessDenied', 'request');
  15. }
  16. Relations::createRelations($typeName, $primaryKey, $remoteTypeName, $listRemotePrimaryKeys);
  17. $listSelectedState = Relations::getRelations($typeName, $primaryKey);
  18. header('Content-Type: application/json');
  19. echo json_encode([
  20. 'type' => "success",
  21. 'msg' => "done",
  22. // 'body' => [
  23. // 'relations' => $listRelations,
  24. // 'total' => $total,
  25. // ]
  26. ]);
  27. exit;
  28. }
  29. }