Skip to content
Snippets Groups Projects
Commit a6812185 authored by Guillaume Heurtier's avatar Guillaume Heurtier
Browse files

FEAT #12072 TIME 2:00 added get m2m by id

parent 01c5ba5c
No related branches found
No related tags found
No related merge requests found
...@@ -372,6 +372,7 @@ $app->put('/resources/{resId}/unsign', \SignatureBook\controllers\SignatureBookC ...@@ -372,6 +372,7 @@ $app->put('/resources/{resId}/unsign', \SignatureBook\controllers\SignatureBookC
$app->get('/resources/{resId}/acknowledgementReceipts', \AcknowledgementReceipt\controllers\AcknowledgementReceiptController::class . ':getByResId'); $app->get('/resources/{resId}/acknowledgementReceipts', \AcknowledgementReceipt\controllers\AcknowledgementReceiptController::class . ':getByResId');
$app->get('/resources/{resId}/shippings', \Shipping\controllers\ShippingController::class . ':getByResId'); $app->get('/resources/{resId}/shippings', \Shipping\controllers\ShippingController::class . ':getByResId');
$app->get('/resources/{resId}/messageExchanges', \MessageExchange\controllers\MessageExchangeController::class . ':getByResId'); $app->get('/resources/{resId}/messageExchanges', \MessageExchange\controllers\MessageExchangeController::class . ':getByResId');
$app->get('/messageExchanges/{id}', \MessageExchange\controllers\MessageExchangeController::class . ':getById');
$app->put('/res/resource/status', \Resource\controllers\ResController::class . ':updateStatus'); $app->put('/res/resource/status', \Resource\controllers\ResController::class . ':updateStatus');
$app->post('/res/list', \Resource\controllers\ResController::class . ':getList'); $app->post('/res/list', \Resource\controllers\ResController::class . ':getList');
......
...@@ -71,4 +71,122 @@ class MessageExchangeController ...@@ -71,4 +71,122 @@ class MessageExchangeController
return $response->withJson(['messageExchanges' => $messages]); return $response->withJson(['messageExchanges' => $messages]);
} }
public static function getById(Request $request, Response $response, array $args)
{
if (!Validator::stringType()->validate($args['id'])) {
return $response->withStatus(400)->withJson(['errors' => 'Query param id is not a string']);
}
$message = MessageExchangeModel::getMessageByIdentifier([
'select' => ['*'],
'messageId' => $args['id']
]);
if (empty($message[0])) {
return $response->withStatus(404)->withJson(['errors' => 'Message not found']);
}
$message = $message[0];
if (!ResController::hasRightByResId(['resId' => [$message['res_id_master']], 'userId' => $GLOBALS['id']])) {
return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']);
}
$type = $message['type'];
if (!empty($message['receptionDate'])) {
$reference = $message['reference'] . '_Reply';
$type = 'ArchiveTransfer';
} elseif ($type == 'ArchiveTransferReply') {
$reference = $message['reference'];
$type = 'ArchiveTransferReplySent';
}
$operationComments = null;
if (!empty($reference)) {
$reply = MessageExchangeModel::getMessageByReference(['reference' => $reference]);
$replyData = json_decode($reply['data'], true);
$operationComments = $replyData['Comment'];
}
$messageData = json_decode($message['data'], true);
$transferringAgencyMetaData = $messageData['TransferringAgency']['OrganizationDescriptiveMetadata'];
$from = $transferringAgencyMetaData['Contact'][0]['PersonName'] . ' (' . $transferringAgencyMetaData['Name'] . ')';
$archivalAgency = $messageData['ArchivalAgency'];
$archivalAgencyMetaData = $archivalAgency['OrganizationDescriptiveMetadata'] ?? null;
$communicationType = $archivalAgencyMetaData['Communication'][0]['value'] ?? null;
$contactInfo = $archivalAgencyMetaData['Name'] . ' - <b>' . $archivalAgency['Identifier']['value'] . '</b> - ' . $archivalAgencyMetaData['Contact'][0]['PersonName'];
if (!empty($archivalAgencyMetaData['Contact'][0]['Address'][0])) {
$addressInfo = $archivalAgencyMetaData['Contact'][0]['Address'][0]['PostOfficeBox']
. ' ' . $archivalAgencyMetaData['Contact'][0]['Address'][0]['StreetName']
. ' ' . $archivalAgencyMetaData['Contact'][0]['Address'][0]['Postcode']
. ' ' . $archivalAgencyMetaData['Contact'][0]['Address'][0]['CityName']
. ' ' . $archivalAgencyMetaData['Contact'][0]['Address'][0]['Country'];
$contactInfo .= ', ' . $addressInfo;
}
$body = $messageData['Comment'][0]['value'] ?? null;
$object = $messageData['DataObjectPackage']['DescriptiveMetadata']['ArchiveUnit'][0]['Content']['Title'][0] ?? null;
$unitIdentifier = MessageExchangeModel::getUnitIdentifierByMessageId(['messageId' => $args['id']]);
$notes = [];
$attachments = [];
$resMasterAttached = false;
$disposition = [];
foreach ($unitIdentifier as $unit) {
if ($unit['tablename'] == 'notes') {
$notes[] = $unit['res_id'];
}
if ($unit['tablename'] == 'res_attachments') {
$attachments[] = $unit['res_id'];
}
if ($unit['tablename'] == 'res_letterbox') {
$resMasterAttached = true;
}
if ($unit['disposition'] == 'body') {
$disposition = $unit;
}
}
$messageType = 'm2m_' . strtoupper($type);
$user = UserModel::getLabelledUserById(['login' => $message['account_id']]);
$sender = $user . ' (' . $message['sender_org_name'] . ')';
$recipient = $message['recipient_org_name'] . ' (' . $message['recipient_org_identifier'] . ')';
if ($message['status'] == 'S') {
$status = 'sent';
} elseif ($message['status'] == 'E') {
$status = 'error';
} elseif ($message['status'] == 'W') {
$status = 'wait';
} else {
$status = 'draft';
}
$messageExchange = [
'messageId' => $message['message_id'],
'creationDate' => $message['date'],
'type' => $messageType,
'sender' => $sender,
'recipient' => $recipient,
'receptionDate' => $message['reception_date'],
'operationDate' => $message['operation_date'],
'status' => $status,
'operationComments' => $operationComments,
'from' => $from,
'communicationType' => $communicationType,
'contactInfo' => $contactInfo,
'body' => $body,
'object' => $object,
'notes' => $notes,
'attachments' => $attachments,
'resMasterAttached' => $resMasterAttached,
'disposition' => $disposition
];
return $response->withJson(['messageExchange' => $messageExchange]);
}
} }
...@@ -212,4 +212,20 @@ abstract class MessageExchangeModelAbstract ...@@ -212,4 +212,20 @@ abstract class MessageExchangeModelAbstract
return ['messageId' => $messageObject->messageId]; return ['messageId' => $messageObject->messageId];
} }
public static function getUnitIdentifierByMessageId(array $args)
{
ValidatorModel::notEmpty($args, ['messageId']);
ValidatorModel::stringType($args, ['messageId']);
$messages = DatabaseModel::select([
'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'],
'table' => ['unit_identifier'],
'where' => ['message_id = ?'],
'data' => [$aArgs['message_id']]
]
);
return $messages;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment