| 1234567891011121314151617181920212223242526272829303132333435 |
- <?php
- Lib::loadClass('Relations');
- class Api_Process_P5_CreateRelation { // TODO: extends Api_ProcessBase
- static function run($args, $responseForm) {
- $typeName = (!empty($args['typeName'][0])) ? $args['typeName'][0] : '';
- if (!$typeName) throw new Api_OwsException("Missing value for 'typeName'", 501, null, 'MissingParameterValue', 'request');
- $primaryKey = (!empty($args['primaryKey'][0])) ? $args['primaryKey'][0] : '';
- if (!$primaryKey) throw new Api_OwsException("Missing value for 'primaryKey'", 501, null, 'MissingParameterValue', 'request');
- $remoteTypeName = (!empty($args['remoteTypeName'][0])) ? $args['remoteTypeName'][0] : '';
- if (!$remoteTypeName) throw new Api_OwsException("Missing value for 'remoteTypeName'", 501, null, 'MissingParameterValue', 'request');
- $listRemotePrimaryKeys = (!empty($args['primaryKey'])) ? $args['remotePrimaryKey'] : [];
- if (empty($listRemotePrimaryKeys)) throw new Api_OwsException("Missing value for 'remotePrimaryKey'", 501, null, 'MissingParameterValue', 'request');
- if (!Relations::isAllowedToCreateRelation($userLogin, $typeName, $primaryKey, $remoteTypeName)) {
- throw new Api_OwsException("User is not allowed to create relation from '{$typeName}.{$primaryKey}' to '{$remoteTypeName}' ", 501, null, 'AccessDenied', 'request');
- }
- Relations::createRelations($typeName, $primaryKey, $remoteTypeName, $listRemotePrimaryKeys);
- $listSelectedState = Relations::getRelations($typeName, $primaryKey);
- header('Content-Type: application/json');
- echo json_encode([
- 'type' => "success",
- 'msg' => "done",
- // 'body' => [
- // 'relations' => $listRelations,
- // 'total' => $total,
- // ]
- ]);
- exit;
- }
- }
|