Newer
Older
<?php
/**
* Copyright Maarch since 2008 under licence GPLv3.
* See LICENCE.txt file at the root folder for more details.
* This file is part of Maarch software.
*
*/
/**
* @brief Send Message Exchange Review Controller
* @author dev@maarch.org
*/
namespace MessageExchange\controllers;
use Attachment\models\AttachmentModel;
use Contact\models\ContactModel;
use Docserver\models\DocserverModel;
use Doctype\models\DoctypeModel;
use Entity\models\EntityModel;
use ExportSeda\controllers\SendMessageController;
use Group\controllers\PrivilegeController;
use History\controllers\HistoryController;
use MessageExchange\controllers\ReceiveMessageExchangeController;
use Note\models\NoteModel;
use Resource\controllers\ResController;
use Resource\models\ResModel;
use Respect\Validation\Validator;
use SrcCore\models\TextFormatModel;
use Status\models\StatusModel;
use User\models\UserModel;
use Slim\Http\Request;
use Slim\Http\Response;
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
class SendMessageExchangeController
{
public static function saveMessageExchange($aArgs = [])
{
$dataObject = $aArgs['dataObject'];
$oData = new \stdClass();
$oData->messageId = MessageExchangeModel::generateUniqueId();
$oData->date = $dataObject->Date;
$oData->MessageIdentifier = new \stdClass();
$oData->MessageIdentifier->value = $dataObject->MessageIdentifier->value;
$oData->TransferringAgency = new \stdClass();
$oData->TransferringAgency->Identifier = new \stdClass();
$oData->TransferringAgency->Identifier->value = $dataObject->TransferringAgency->Identifier->value;
$oData->ArchivalAgency = new \stdClass();
$oData->ArchivalAgency->Identifier = new \stdClass();
$oData->ArchivalAgency->Identifier->value = $dataObject->ArchivalAgency->Identifier->value;
$oData->archivalAgreement = new \stdClass();
$oData->archivalAgreement->value = ""; // TODO : ???
$replyCode = "";
if (!empty($dataObject->ReplyCode)) {
$replyCode = $dataObject->ReplyCode;
}
$oData->replyCode = new \stdClass();
$oData->replyCode = $replyCode;
$dataObject = self::cleanBase64Value(['dataObject' => $dataObject]);
$aDataExtension = [
'status' => 'W',
'fullMessageObject' => $dataObject,
'resIdMaster' => $aArgs['res_id_master'],
'SenderOrgNAme' => $dataObject->TransferringAgency->OrganizationDescriptiveMetadata->Contact[0]->DepartmentName,
'RecipientOrgNAme' => $dataObject->ArchivalAgency->OrganizationDescriptiveMetadata->Name,
'filePath' => $aArgs['file_path'],
];
$messageId = MessageExchangeModel::insertMessage([
"data" => $oData,
"type" => $aArgs['type'],
"dataExtension" => $aDataExtension,
"userId" => $aArgs['userId']
]);
return $messageId;
}
protected static function cleanBase64Value($aArgs = [])
{
$dataObject = $aArgs['dataObject'];
$aCleanDataObject = [];
if (!empty($dataObject->DataObjectPackage->BinaryDataObject)) {
foreach ($dataObject->DataObjectPackage->BinaryDataObject as $key => $value) {
$value->Attachment->value = "";
$aCleanDataObject[$key] = $value;
}
$dataObject->DataObjectPackage->BinaryDataObject = $aCleanDataObject;
}
return $dataObject;
}
public static function createMessageExchange(Request $request, Response $response, array $args)
{
if (!PrivilegeController::hasPrivilege(['privilegeId' => 'manage_numeric_package', 'userId' => $GLOBALS['id']])) {
return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']);
}
if (!Validator::intVal()->validate($args['resId']) || !ResController::hasRightByResId(['resId' => [$args['resId']], 'userId' => $GLOBALS['id']])) {
return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']);
}
$body = $request->getParsedBody();
$errors = self::control($body);
if (!empty($errors)) {
return $response->withStatus(400)->withJson(['errors' => $errors]);
}
/***************** GET MAIL INFOS *****************/
$AllUserEntities = EntityModel::getWithUserEntities(['where' => ['user_id = ?', 'business_id != \'\''], 'data' => [$GLOBALS['userId']]]);
foreach ($AllUserEntities as $value) {
if ($value['id'] == $body['senderEmail']) {
$TransferringAgencyInformations = $value;
break;
}
}
if (empty($TransferringAgencyInformations)) {
return $response->withStatus(400)->withJson(['errors' => "no sender"]);
$AllInfoMainMail = ResModel::getById(['select' => ['*'], 'resId' => $args['resId']]);
$doctype = DoctypeModel::getById(['select' => ['description'], 'id' => $AllInfoMainMail['type_id']]);
$tmpMainExchangeDoc = explode("__", $body['mainExchangeDoc']);
$MainExchangeDoc = ['tablename' => $tmpMainExchangeDoc[0], 'res_id' => $tmpMainExchangeDoc[1]];
$fileInfo = [];
if (!empty($body['joinFile']) || $MainExchangeDoc['tablename'] == 'res_letterbox') {
$AllInfoMainMail['Title'] = $AllInfoMainMail['subject'];
$AllInfoMainMail['OriginatingAgencyArchiveUnitIdentifier'] = $AllInfoMainMail['alt_identifier'];
$AllInfoMainMail['DocumentType'] = $doctype['description'];
$AllInfoMainMail['tablenameExchangeMessage'] = 'res_letterbox';
$fileInfo = [$AllInfoMainMail];
}
if ($MainExchangeDoc['tablename'] == 'res_attachments') {
$body['joinAttachment'][] = $MainExchangeDoc['res_id'];
}
/**************** GET ATTACHMENTS INFOS ***************/
$AttachmentsInfo = [];
if (!empty($body['joinAttachment'])) {
$AttachmentsInfo = AttachmentModel::get(['select' => ['*'], 'where' => ['res_id in (?)'], 'data' => [$body['joinAttachment']]]);
$attachmentTypes = AttachmentModel::getAttachmentsTypesByXML();
foreach ($AttachmentsInfo as $key => $value) {
$AttachmentsInfo[$key]['Title'] = $value['title'];
$AttachmentsInfo[$key]['OriginatingAgencyArchiveUnitIdentifier'] = $value['identifier'];
$AttachmentsInfo[$key]['DocumentType'] = $attachmentTypes[$value['attachment_type']]['label'];
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
$AttachmentsInfo[$key]['tablenameExchangeMessage'] = 'res_attachments';
}
}
$aAllAttachment = $AttachmentsInfo;
/******************* GET NOTE INFOS **********************/
$aComments = self::generateComments([
'resId' => $args['resId'],
'notes' => $body['notes'],
'body' => $body['content'],
'TransferringAgencyInformations' => $TransferringAgencyInformations]);
/*********** ORDER ATTACHMENTS IN MAIL ***************/
if ($MainExchangeDoc['tablename'] == 'res_letterbox') {
$mainDocument = $fileInfo;
$aMergeAttachment = array_merge($fileInfo, $aAllAttachment);
} else {
foreach ($aAllAttachment as $key => $value) {
if ($value['res_id'] == $MainExchangeDoc['res_id'] && $MainExchangeDoc['tablename'] == $value['tablenameExchangeMessage']) {
if ($AllInfoMainMail['category_id'] == 'outgoing') {
$aOutgoingMailInfo = $AllInfoMainMail;
$aOutgoingMailInfo['Title'] = $AllInfoMainMail['subject'];
$aOutgoingMailInfo['OriginatingAgencyArchiveUnitIdentifier'] = $AllInfoMainMail['alt_identifier'];
$aOutgoingMailInfo['DocumentType'] = $AllInfoMainMail['type_label'];
$aOutgoingMailInfo['tablenameExchangeMessage'] = $AllInfoMainMail['tablenameExchangeMessage'];
$mainDocument = [$aOutgoingMailInfo];
} else {
$mainDocument = [$aAllAttachment[$key]];
}
$firstAttachment = [$aAllAttachment[$key]];
unset($aAllAttachment[$key]);
}
}
$aMergeAttachment = array_merge($firstAttachment, $fileInfo, $aAllAttachment);
}
$mainDocument[0]['Title'] = '[CAPTUREM2M]'.$body['object'];
foreach ($body['contacts'] as $contactId) {
/******** GET ARCHIVAl INFORMATIONs **************/
$communicationType = ContactModel::getById(['select' => ['communication_means'], 'id' => $contactId]);
$aArchivalAgencyCommunicationType = json_decode($communicationType['communication_means'], true);
if (!empty($aArchivalAgencyCommunicationType)) {
if (!empty($aArchivalAgencyCommunicationType['email'])) {
$ArchivalAgencyCommunicationType['type'] = 'email';
$ArchivalAgencyCommunicationType['value'] = $aArchivalAgencyCommunicationType['email'];
} else {
$ArchivalAgencyCommunicationType['type'] = 'url';
$ArchivalAgencyCommunicationType['value'] = rtrim($aArchivalAgencyCommunicationType['url'], "/");
}
}
$ArchivalAgencyContactInformations = ContactModel::getById(['select' => ['*'], 'id' => $contactId]);
/******** GENERATE MESSAGE EXCHANGE OBJECT *********/
$dataObject = self::generateMessageObject([
'Comment' => $aComments,
'ArchivalAgency' => [
'CommunicationType' => $ArchivalAgencyCommunicationType,
'ContactInformations' => $ArchivalAgencyContactInformations
],
'TransferringAgency' => [
'EntitiesInformations' => $TransferringAgencyInformations
],
'attachment' => $aMergeAttachment,
'res' => $mainDocument,
'mainExchangeDocument' => $MainExchangeDoc
]);
/******** GENERATION DU BORDEREAU */
$filePath = SendMessageController::generateMessageFile(['messageObject' => $dataObject, 'type' => 'ArchiveTransfer']);
/******** SAVE MESSAGE *********/
$messageExchangeReturn = self::saveMessageExchange(['dataObject' => $dataObject, 'res_id_master' => $args['resId'], 'file_path' => $filePath, 'type' => 'ArchiveTransfer', 'userId' => $GLOBALS['userId']]);
if (!empty($messageExchangeReturn['error'])) {
return $response->withStatus(400)->withJson(['errors' => $messageExchangeReturn['error']]);
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
} else {
$messageId = $messageExchangeReturn['messageId'];
}
self::saveUnitIdentifier(['attachment' => $aMergeAttachment, 'notes' => $body['notes'], 'messageId' => $messageId]);
HistoryController::add([
'tableName' => 'res_letterbox',
'recordId' => $args['resId'],
'eventType' => 'UP',
'eventId' => 'resup',
'info' => _NUMERIC_PACKAGE_ADDED . _ON_DOC_NUM
. $args['resId'] . ' ('.$messageId.') : "' . TextFormatModel::cutString(['string' => $mainDocument[0]['Title'], 'max' => 254]),
'userId' => $GLOBALS['userId']
]);
HistoryController::add([
'tableName' => 'message_exchange',
'recordId' => $messageId,
'eventType' => 'ADD',
'eventId' => 'messageexchangeadd',
'info' => _NUMERIC_PACKAGE_ADDED . ' (' . $messageId . ')',
'userId' => $GLOBALS['userId']
]);
/******** ENVOI *******/
$res = SendMessageController::send($dataObject, $messageId, 'ArchiveTransfer');
if ($res['status'] == 1) {
$errors = [];
array_push($errors, "L'envoi a échoué");
array_push($errors, $res['content']);
return $response->withStatus(400)->withJson(['errors' => $errors]);
return $response->withStatus(200);
}
protected static function control($aArgs = [])
{
$errors = [];
if (empty($aArgs['mainExchangeDoc'])) {
array_push($errors, 'wrong format for mainExchangeDoc');
}
if (empty($aArgs['object'])) {
array_push($errors, 'Body object is empty');
}
if (empty($aArgs['joinFile']) && empty($aArgs['joinAttachment']) && empty($aArgs['mainExchangeDoc'])) {
array_push($errors, 'no attachment');
}
if (empty($aArgs['contacts'])) {
array_push($errors, 'body contacts is empty');
}
if (empty($aArgs['senderEmail'])) {
array_push($errors, 'Body senderEmail is empty');
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
}
return $errors;
}
protected static function generateComments($aArgs = [])
{
$aReturn = [];
$entityRoot = EntityModel::getEntityRootById(['entityId' => $aArgs['TransferringAgencyInformations']['entity_id']]);
$userInfo = UserModel::getById(['id' => $GLOBALS['id'], 'select' => ['firstname', 'lastname', 'mail']]);
$headerNote = $userInfo['firstname'] . ' ' . $userInfo['lastname'] . ' (' . $entityRoot['entity_label'] . ' - ' . $aArgs['TransferringAgencyInformations']['entity_label'] . ' - ' .$userInfo['mail'].') : ';
$oBody = new \stdClass();
$oBody->value = $headerNote . ' ' . $aArgs['body'];
array_push($aReturn, $oBody);
if (!empty($aArgs['notes'])) {
$notes = NoteModel::getByResId([
'select' => ['notes.id', 'notes.user_id', 'notes.creation_date', 'notes.note_text', 'users.firstname', 'users.lastname', 'users_entities.entity_id'],
'resId' => $aArgs['resId']
]);
if (!empty($notes)) {
foreach ($notes as $value) {
if (!in_array($value['id'], $aArgs['notes'])) {
continue;
}
$oComment = new \stdClass();
$date = new \DateTime($value['creation_date']);
$additionalUserInfos = '';
if (!empty($value['entity_id'])) {
$entityRoot = EntityModel::getEntityRootById(['entityId' => $value['entity_id']]);
$userEntity = EntityModel::getByEntityId(['entityId' => $value['entity_id']]);
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
$additionalUserInfos = ' ('.$entityRoot['entity_label'].' - '.$userEntity['entity_label'].')';
}
$oComment->value = $value['firstname'].' '.$value['lastname'].' - '.$date->format('d-m-Y H:i:s'). $additionalUserInfos . ' : '.$value['note_text'];
array_push($aReturn, $oComment);
}
}
}
return $aReturn;
}
public static function generateMessageObject($aArgs = [])
{
$date = new \DateTime;
$messageObject = new \stdClass();
$messageObject->Comment = $aArgs['Comment'];
$messageObject->Date = $date->format(\DateTime::ATOM);
$messageObject->MessageIdentifier = new \stdClass();
$messageObject->MessageIdentifier->value = 'ArchiveTransfer_'.date("Ymd_His").'_'.$GLOBALS['userId'];
/********* BINARY DATA OBJECT PACKAGE *********/
$messageObject->DataObjectPackage = new \stdClass();
$messageObject->DataObjectPackage->BinaryDataObject = self::getBinaryDataObject($aArgs['attachment']);
/********* DESCRIPTIVE META DATA *********/
$messageObject->DataObjectPackage->DescriptiveMetadata = self::getDescriptiveMetaDataObject($aArgs);
/********* ARCHIVAL AGENCY *********/
$messageObject->ArchivalAgency = self::getArchivalAgencyObject(['ArchivalAgency' => $aArgs['ArchivalAgency']]);
/********* TRANSFERRING AGENCY *********/
$channelType = $messageObject->ArchivalAgency->OrganizationDescriptiveMetadata->Communication[0]->Channel;
$messageObject->TransferringAgency = self::getTransferringAgencyObject(['TransferringAgency' => $aArgs['TransferringAgency'], 'ChannelType' => $channelType]);
return $messageObject;
}
public static function getBinaryDataObject($aArgs = [])
{
$aReturn = [];
foreach ($aArgs as $key => $value) {
if (!empty($value['tablenameExchangeMessage'])) {
$binaryDataObjectId = $value['tablenameExchangeMessage'] . "_" . $key . "_" . $value['res_id'];
} else {
$binaryDataObjectId = $value['res_id'];
}
$binaryDataObject = new \stdClass();
$binaryDataObject->id = $binaryDataObjectId;
$binaryDataObject->MessageDigest = new \stdClass();
$binaryDataObject->MessageDigest->value = $value['fingerprint'];
$binaryDataObject->MessageDigest->algorithm = "sha256";
$binaryDataObject->Size = $value['filesize'];
$uri = str_replace("##", DIRECTORY_SEPARATOR, $value['path']);
$uri = str_replace("#", DIRECTORY_SEPARATOR, $uri);
$docServers = DocserverModel::getByDocserverId(['docserverId' => $value['docserver_id']]);
$binaryDataObject->Attachment = new \stdClass();
$binaryDataObject->Attachment->uri = '';
$binaryDataObject->Attachment->filename = basename($value['filename']);
$binaryDataObject->Attachment->value = base64_encode(file_get_contents($docServers['path_template'] . $uri . '/'. $value['filename']));
$binaryDataObject->FormatIdentification = new \stdClass();
$binaryDataObject->FormatIdentification->MimeType = mime_content_type($docServers['path_template'] . $uri . $value['filename']);
array_push($aReturn, $binaryDataObject);
}
return $aReturn;
}
public static function getDescriptiveMetaDataObject($aArgs = [])
{
$DescriptiveMetadataObject = new \stdClass();
$DescriptiveMetadataObject->ArchiveUnit = [];
$documentArchiveUnit = new \stdClass();
$documentArchiveUnit->id = 'mail_1';
$documentArchiveUnit->Content = self::getContent([
'DescriptionLevel' => 'File',
'Title' => $aArgs['res'][0]['Title'],
'OriginatingSystemId' => $aArgs['res'][0]['res_id'],
'OriginatingAgencyArchiveUnitIdentifier' => $aArgs['res'][0]['OriginatingAgencyArchiveUnitIdentifier'],
'DocumentType' => $aArgs['res'][0]['DocumentType'],
'Status' => $aArgs['res'][0]['status'],
'Writer' => $aArgs['res'][0]['typist'],
'CreatedDate' => $aArgs['res'][0]['creation_date'],
]);
$documentArchiveUnit->ArchiveUnit = [];
foreach ($aArgs['attachment'] as $key => $value) {
$attachmentArchiveUnit = new \stdClass();
$attachmentArchiveUnit->id = 'archiveUnit_'.$value['tablenameExchangeMessage'] . "_" . $key . "_" . $value['res_id'];
$attachmentArchiveUnit->Content = self::getContent([
'DescriptionLevel' => 'Item',
'Title' => $value['Title'],
'OriginatingSystemId' => $value['res_id'],
'OriginatingAgencyArchiveUnitIdentifier' => $value['OriginatingAgencyArchiveUnitIdentifier'],
'DocumentType' => $value['DocumentType'],
'Status' => $value['status'],
'Writer' => $value['typist'],
'CreatedDate' => $value['creation_date'],
]);
$dataObjectReference = new \stdClass();
$dataObjectReference->DataObjectReferenceId = $value['tablenameExchangeMessage'].'_'.$key.'_'.$value['res_id'];
$attachmentArchiveUnit->DataObjectReference = [$dataObjectReference];
array_push($documentArchiveUnit->ArchiveUnit, $attachmentArchiveUnit);
}
array_push($DescriptiveMetadataObject->ArchiveUnit, $documentArchiveUnit);
return $DescriptiveMetadataObject;
}
public static function getContent($aArgs = [])
{
$contentObject = new \stdClass();
$contentObject->DescriptionLevel = $aArgs['DescriptionLevel'];
$contentObject->Title = [$aArgs['Title']];
$contentObject->OriginatingSystemId = $aArgs['OriginatingSystemId'];
$contentObject->OriginatingAgencyArchiveUnitIdentifier = $aArgs['OriginatingAgencyArchiveUnitIdentifier'];
$contentObject->DocumentType = $aArgs['DocumentType'];
$contentObject->Status = StatusModel::getById(['id' => $aArgs['Status']])['label_status'];
$userInfos = UserModel::getById(['id' => $aArgs['Writer']]);
$writer = new \stdClass();
$writer->FirstName = $userInfos['firstname'];
$writer->BirthName = $userInfos['lastname'];
$contentObject->Writer = [$writer];
$contentObject->CreatedDate = date("Y-m-d", strtotime($aArgs['CreatedDate']));
return $contentObject;
}
public static function getArchivalAgencyObject($aArgs = [])
{
$archivalAgencyObject = new \stdClass();
$archivalAgencyObject->Identifier = new \stdClass();
$externalId = json_decode($aArgs['ArchivalAgency']['ContactInformations']['external_id'], true);
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
$archivalAgencyObject->Identifier->value = $externalId['m2m'];
$archivalAgencyObject->OrganizationDescriptiveMetadata = new \stdClass();
$archivalAgencyObject->OrganizationDescriptiveMetadata->Name = trim($aArgs['ArchivalAgency']['ContactInformations']['company'] . ' ' . $aArgs['ArchivalAgency']['ContactInformations']['lastname'] . ' ' . $aArgs['ArchivalAgency']['ContactInformations']['firstname']);
if (isset($aArgs['ArchivalAgency']['CommunicationType']['type'])) {
$arcCommunicationObject = new \stdClass();
$arcCommunicationObject->Channel = $aArgs['ArchivalAgency']['CommunicationType']['type'];
if ($aArgs['ArchivalAgency']['CommunicationType']['type'] == 'url') {
$postUrl = '/rest/saveNumericPackage';
}
$arcCommunicationObject->value = $aArgs['ArchivalAgency']['CommunicationType']['value'].$postUrl;
$archivalAgencyObject->OrganizationDescriptiveMetadata->Communication = [$arcCommunicationObject];
}
$contactObject = new \stdClass();
$contactObject->DepartmentName = $aArgs['ArchivalAgency']['ContactInformations']['department'];
$contactObject->PersonName = $aArgs['ArchivalAgency']['ContactInformations']['lastname'] . " " . $aArgs['ArchivalAgency']['ContactInformations']['firstname'];
$addressObject = new \stdClass();
$addressObject->CityName = $aArgs['ArchivalAgency']['ContactInformations']['address_town'];
$addressObject->Country = $aArgs['ArchivalAgency']['ContactInformations']['address_country'];
$addressObject->Postcode = $aArgs['ArchivalAgency']['ContactInformations']['address_postcode'];
$addressObject->PostOfficeBox = $aArgs['ArchivalAgency']['ContactInformations']['address_number'];
$addressObject->StreetName = $aArgs['ArchivalAgency']['ContactInformations']['address_street'];
$contactObject->Address = [$addressObject];
$communicationContactPhoneObject = new \stdClass();
$communicationContactPhoneObject->Channel = 'phone';
$communicationContactPhoneObject->value = $aArgs['ArchivalAgency']['ContactInformations']['phone'];
$communicationContactEmailObject = new \stdClass();
$communicationContactEmailObject->Channel = 'email';
$communicationContactEmailObject->value = $aArgs['ArchivalAgency']['ContactInformations']['email'];
$contactObject->Communication = [$communicationContactPhoneObject, $communicationContactEmailObject];
$archivalAgencyObject->OrganizationDescriptiveMetadata->Contact = [$contactObject];
return $archivalAgencyObject;
}
public static function getTransferringAgencyObject($aArgs = [])
{
$TransferringAgencyObject = new \stdClass();
$TransferringAgencyObject->Identifier = new \stdClass();
$TransferringAgencyObject->Identifier->value = $aArgs['TransferringAgency']['EntitiesInformations']['business_id'];
$TransferringAgencyObject->OrganizationDescriptiveMetadata = new \stdClass();
$entityRoot = EntityModel::getEntityRootById(['entityId' => $aArgs['TransferringAgency']['EntitiesInformations']['entity_id']]);
$TransferringAgencyObject->OrganizationDescriptiveMetadata->LegalClassification = $entityRoot['entity_label'];
$TransferringAgencyObject->OrganizationDescriptiveMetadata->Name = $aArgs['TransferringAgency']['EntitiesInformations']['entity_label'];
$TransferringAgencyObject->OrganizationDescriptiveMetadata->UserIdentifier = $GLOBALS['userId'];
$traCommunicationObject = new \stdClass();
$aDefaultConfig = ReceiveMessageExchangeController::readXmlConfig();
$traCommunicationObject->Channel = $aArgs['ChannelType'];
$traCommunicationObject->value = rtrim($aDefaultConfig['m2m_communication_type'][$aArgs['ChannelType']], "/");
$TransferringAgencyObject->OrganizationDescriptiveMetadata->Communication = [$traCommunicationObject];
$userInfo = UserModel::getById(['id' => $GLOBALS['id'], 'select' => ['firstname', 'lastname', 'mail', 'phone']]);
$contactUserObject = new \stdClass();
$contactUserObject->DepartmentName = $aArgs['TransferringAgency']['EntitiesInformations']['entity_label'];
$contactUserObject->PersonName = $userInfo['firstname'] . " " . $userInfo['lastname'];
$communicationUserPhoneObject = new \stdClass();
$communicationUserPhoneObject->Channel = 'phone';
$communicationUserPhoneObject->value = $userInfo['phone'];
$communicationUserEmailObject = new \stdClass();
$communicationUserEmailObject->Channel = 'email';
$communicationUserEmailObject->value = $userInfo['mail'];
$contactUserObject->Communication = [$communicationUserPhoneObject, $communicationUserEmailObject];
$TransferringAgencyObject->OrganizationDescriptiveMetadata->Contact = [$contactUserObject];
return $TransferringAgencyObject;
}
public static function saveUnitIdentifier($aArgs = [])
{
foreach ($aArgs['attachment'] as $key => $value) {
$disposition = "attachment";
if ($key == 0) {
$disposition = "body";
}
MessageExchangeModel::insertUnitIdentifier([
'messageId' => $aArgs['messageId'],
'tableName' => $value['tablenameExchangeMessage'],
'resId' => $value['res_id'],
'disposition' => $disposition
]);
}
if (!empty($aArgs['notes'])) {
foreach ($aArgs['notes'] as $value) {
MessageExchangeModel::insertUnitIdentifier([
'messageId' => $aArgs['messageId'],
'tableName' => "notes",
'resId' => $value,
'disposition' => "note"
]);
}
}
return true;
}