From ac6e56402c2e7656809d8007e46f5c75b6d25dea Mon Sep 17 00:00:00 2001
From: "florian.azizian" <florian.azizian@maarch.org>
Date: Fri, 29 Jan 2021 19:06:27 +0100
Subject: [PATCH] FEAT #15450 TIME 1:10 Multiples fixes Ixbus

---
 .../controllers/IxbusController.php           | 19 +++++++++----------
 src/core/models/CurlModel.php                 |  2 +-
 2 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/src/app/external/externalSignatoryBook/controllers/IxbusController.php b/src/app/external/externalSignatoryBook/controllers/IxbusController.php
index 6ea50a7fe8f..7328e01f927 100755
--- a/src/app/external/externalSignatoryBook/controllers/IxbusController.php
+++ b/src/app/external/externalSignatoryBook/controllers/IxbusController.php
@@ -145,7 +145,7 @@ class IxbusController
 
                 $annexesAttachments[] = [
                     'filePath' => $filePath,
-                    'fileName' => $value['title']
+                    'fileName' => $value['title'] . '.pdf'
                 ];
                 unset($attachments[$key]);
             }
@@ -168,19 +168,20 @@ class IxbusController
         if (!empty($mainDocumentFilePath)) {
             $attachmentsData = [[
                 'filePath' => $mainDocumentFilePath,
-                'fileName' => $mainResource['subject']
+                'fileName' => $mainResource['subject'] . '.pdf'
             ]];
         };
 
         $attachmentsData = array_merge($annexesAttachments, $attachmentsData);
         $userInfo = IxbusController::getInfoUtilisateur(['config' => $aArgs['config'], 'login' => $aArgs['loginIxbus'], 'natureId' => $aArgs['natureId']]);
+
+        $signature = $aArgs['manSignature'] == 'manual' ? 1 : 0;
         $bodyData = [
             'nature'     => $aArgs['natureId'],
             'referent'   => $userInfo['user'],
             'circuit'    => $aArgs['messageModel'],
-            'options'    => json_encode(['confidentiel' => false, 'dateLimite' => true, 'documentModifiable' => true, 'annexesSignables' => false, 'autoriserModificationAnnexes' => false]),
+            'options'    => json_encode(['confidentiel' => false, 'dateLimite' => true, 'documentModifiable' => true, 'annexesSignables' => false, 'autoriserModificationAnnexes' => false, 'signature' => $signature]),
             'dateLimite' => $processLimitDate,
-            'signature'  => $aArgs['manSignature'] == 'manual' ? 1 : 0
         ];
 
         foreach ($attachments as $value) {
@@ -209,7 +210,7 @@ class IxbusController
                 'config'   => $aArgs['config'],
                 'folderId' => $folderId,
                 'filePath' => $filePath,
-                'fileName' => $value['title'],
+                'fileName' => $value['title'] . '.pdf',
                 'fileType' => 'principal'
             ]);
             if (!empty($addedFile['error'])) {
@@ -266,7 +267,7 @@ class IxbusController
                 'config'   => $aArgs['config'],
                 'folderId' => $folderId,
                 'filePath' => $filePath,
-                'fileName' => $mainResource['title'],
+                'fileName' => $mainResource['title'] . '.pdf',
                 'fileType' => 'principal'
             ]);
             if (!empty($addedFile['error'])) {
@@ -348,17 +349,15 @@ class IxbusController
         foreach ($aArgs['idsToRetrieve'][$version] as $resId => $value) {
             $folderData = IxbusController::getDossier(['config' => $aArgs['config'], 'folderId' => $value['external_id']]);
 
-            // Refused
             if ($folderData['data']['etat'] == 'Refusé') {
                 $aArgs['idsToRetrieve'][$version][$resId]['status'] = 'refused';
             // $notes = IxbusController::getDossier(['config' => $aArgs['config'], 'folderId' => $value['external_id']]);
                 // $aArgs['idsToRetrieve'][$version][$resId]['notes'][] = ['content' => (string)$notes->MotifRefus];
-            // Validated
             } elseif ($folderData['data']['etat'] == 'Terminé') {
                 $aArgs['idsToRetrieve'][$version][$resId]['status'] = 'validated';
                 $signedDocument = IxbusController::getDocument(['config' => $aArgs['config'], 'documentId' => $folderData['data']['documents']['principal']['identifiant']]);
-                $aArgs['idsToRetrieve'][$version][$resId]['format'] = 'pdf'; // format du fichier récupéré
-                $aArgs['idsToRetrieve'][$version][$resId]['encodedFile'] = (string)$signedDocument->Fichier;
+                $aArgs['idsToRetrieve'][$version][$resId]['format']      = 'pdf';
+                $aArgs['idsToRetrieve'][$version][$resId]['encodedFile'] = $signedDocument['encodedDocument'];
 
             // $notes = IxbusController::getAnnotations(['config' => $aArgs['config'], 'folderId' => $value['external_id']]);
                 // $aArgs['idsToRetrieve'][$version][$resId]['notes'][] = ['content' => (string)$notes->Annotation->Texte];
diff --git a/src/core/models/CurlModel.php b/src/core/models/CurlModel.php
index 7f2ce8f997d..1be32960151 100755
--- a/src/core/models/CurlModel.php
+++ b/src/core/models/CurlModel.php
@@ -328,7 +328,7 @@ class CurlModel
 
         $mime = mime_content_type($aArgs['path']);
         $info = pathinfo($aArgs['path']);
-        $name = $aArgs['path'] ?? $info['basename'];
+        $name = $aArgs['name'] ?? $info['basename'];
         $output = new \CURLFile($aArgs['path'], $mime, $name);
 
         return $output;
-- 
GitLab