Skip to content
Snippets Groups Projects
Commit c5b3b45d authored by Florian Azizian's avatar Florian Azizian
Browse files

FEAT #16956 TIME 2:10 Add all proof in zip file

parent 176e66ef
No related branches found
No related tags found
No related merge requests found
...@@ -444,17 +444,44 @@ class HistoryController ...@@ -444,17 +444,44 @@ class HistoryController
$documentPathToZip[] = ['path' => $historyXmlPath, 'filename' => 'maarchProof.xml']; $documentPathToZip[] = ['path' => $historyXmlPath, 'filename' => 'maarchProof.xml'];
} }
if ($queryParams['onlyProof']) { $notesWorkflow = [];
if (!empty($proofDocument)) { foreach ($workflow as $step) {
$content = $proofDocument; $workflowExternalInformations = WorkflowExternalInformationModel::getByWorkflowId(['select' => ['informations', 'firstname', 'lastname'], 'workflowId' => $step['id']]);
$format = 'pdf'; if (!empty($step['note'])) {
$mimeType = 'application/pdf'; if (empty($step['user_id'])) {
} else { if (!empty($workflowExternalInformations)) {
$content = $historyXml; $userDisplay = "{$workflowExternalInformations['firstname']} {$workflowExternalInformations['lastname']}";
$format = 'xml'; }
$mimeType = 'application/xml'; } else {
$userDisplay = UserModel::getLabelledUserById(['id' => $step['user_id']]);
}
$notesWorkflow[] = [
'creator' => $userDisplay,
'creationDate' => $step['process_date'],
'value' => $step['note']
];
} }
} else {
if (!empty($workflowExternalInformations)) {
$informations = json_decode($workflowExternalInformations['informations'], true);
if ($informations['type'] == 'yousign' && !empty($informations['yousignProcedureId'])) {
$yousignProof = YousignController::getProofByWorkflowId(['workflowId' => $step['id']]);
$archivePath = $tmpPath . 'yousignProof' . $GLOBALS['id'] . "_" . rand() . '.zip';
file_put_contents($archivePath, base64_decode($yousignProof));
$zipArchive = new \ZipArchive();
$zipArchive->open($archivePath);
$nameInArchive = $zipArchive->getNameIndex(0);
$yousignPdfProof = $zipArchive->getFromIndex(0);
$yousignPath = $tmpPath . 'yousignProof' . $GLOBALS['id'] . "_" . rand() . '.pdf';
file_put_contents($yousignPath, $yousignPdfProof);
unlink($archivePath);
$documentPathToZip[] = ['path' => $yousignPath, 'filename' => $nameInArchive];
}
}
}
if (!$queryParams['onlyProof']) {
if ($workflowCompleted && ($queryParams['eSignDocument'] ?? $hasCertificate)) { if ($workflowCompleted && ($queryParams['eSignDocument'] ?? $hasCertificate)) {
$contentType = 'ESIGN'; $contentType = 'ESIGN';
} }
...@@ -508,56 +535,20 @@ class HistoryController ...@@ -508,56 +535,20 @@ class HistoryController
if (!empty($documentNotes)) { if (!empty($documentNotes)) {
$notes[] = $documentNotes; $notes[] = $documentNotes;
} }
$notes = array_merge($notes, $notesWorkflow);
foreach ($workflow as $step) {
if (!empty($step['note'])) {
if (empty($step['user_id'])) {
$workflowExternalInformations = WorkflowExternalInformationModel::getByWorkflowId(['select' => ['firstname', 'lastname'], 'workflowId' => $step['id']]);
if (!empty($workflowExternalInformations)) {
$userDisplay = "{$workflowExternalInformations['firstname']} {$workflowExternalInformations['lastname']}";
}
} else {
$userDisplay = UserModel::getLabelledUserById(['id' => $step['user_id']]);
}
$notes[] = [
'creator' => $userDisplay,
'creationDate' => $step['process_date'],
'value' => $step['note']
];
}
$workflowExternalInformations = WorkflowExternalInformationModel::getByWorkflowId(['select' => ['informations'], 'workflowId' => $step['id']]);
if (!empty($workflowExternalInformations)) {
$informations = json_decode($workflowExternalInformations['informations'], true);
if ($informations['type'] == 'yousign' && !empty($informations['yousignProcedureId'])) {
$yousignProof = YousignController::getProofByWorkflowId(['workflowId' => $step['id']]);
$archivePath = $tmpPath . 'yousignProof' . $GLOBALS['id'] . "_" . rand() . '.zip';
file_put_contents($archivePath, base64_decode($yousignProof));
$zipArchive = new \ZipArchive();
$zipArchive->open($archivePath);
$nameInArchive = $zipArchive->getNameIndex(0);
$yousignPdfProof = $zipArchive->getFromIndex(0);
$yousignPath = $tmpPath . 'yousignProof' . $GLOBALS['id'] . "_" . rand() . '.pdf';
file_put_contents($yousignPath, $yousignPdfProof);
unlink($archivePath);
$documentPathToZip[] = ['path' => $yousignPath, 'filename' => $nameInArchive];
}
}
}
if (!empty($notes)) { if (!empty($notes)) {
$documentPathToZip[] = HistoryController::createNotesFile(['notes' => $notes]); $documentPathToZip[] = HistoryController::createNotesFile(['notes' => $notes]);
} }
}
$content = HistoryController::createZip(['documents' => $documentPathToZip]); $content = HistoryController::createZip(['documents' => $documentPathToZip]);
if (!empty($content['errors'])) { if (!empty($content['errors'])) {
return $response->withStatus(400)->withJson(['errors' => $content['errors']]); return $response->withStatus(400)->withJson(['errors' => $content['errors']]);
}
$content = $content['fileContent'];
$format = 'zip';
$mimeType = 'application/zip';
} }
$content = $content['fileContent'];
$format = 'zip';
$mimeType = 'application/zip';
HistoryController::add([ HistoryController::add([
'code' => 'OK', 'code' => 'OK',
......
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