CreateRelations.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. Lib::loadClass('Relations');
  3. class Api_Process_P5_CreateRelations { // 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. try {
  14. Relations::isAllowedToCreateRelation($userLogin = User::getLogin(), $typeName, $primaryKey, $remoteTypeName);
  15. Relations::createRelations($typeName, $primaryKey, $remoteTypeName, $listRemotePrimaryKeys);
  16. // $listRelations = Relations::getRelations($typeName, $primaryKey, $remoteTypeName);
  17. // $totalRelations = count($listRelations);
  18. } catch (HttpException $e) {
  19. DBG::log($e);
  20. throw new Api_OwsException($e->getMessage(), $e->getCode(), null, Http::getStatusText($e->getCode()), 'request');
  21. } catch (Exception $e) {
  22. DBG::log($e);
  23. throw new Api_OwsException("User is not allowed to read relations from '{$typeName}.{$primaryKey}' to '{$remoteTypeName}'.\n" . $e->getMessage(), 501, null, 'AccessDenied', 'request');
  24. }
  25. header('Content-Type: application/json');
  26. echo json_encode([
  27. 'type' => "success",
  28. 'msg' => "done",
  29. // 'body' => [
  30. // 'relations' => $listRelations,
  31. // 'total' => $total,
  32. // ]
  33. ]);
  34. exit;
  35. }
  36. }