diff --git a/src/app/external/externalSignatoryBook/controllers/MaarchParapheurController.php b/src/app/external/externalSignatoryBook/controllers/MaarchParapheurController.php index e2c15bb529758a05b3983fff9858ce0ddb72c471..8ac5bf1ab21ba56b31e23afa3f9f9924478154b9 100755 --- a/src/app/external/externalSignatoryBook/controllers/MaarchParapheurController.php +++ b/src/app/external/externalSignatoryBook/controllers/MaarchParapheurController.php @@ -75,76 +75,77 @@ class MaarchParapheurController 'data' => [$aArgs['resIdMaster']] ]); - if ($aArgs['objectSent'] == 'mail') { - if (empty($mainResource)) { - return ['error' => 'Mail does not exist']; - } + if (empty($mainResource)) { + return ['error' => 'Mail does not exist']; + } - $units = []; - $units[] = ['unit' => 'primaryInformations']; - $units[] = ['unit' => 'secondaryInformations', 'label' => _SECONDARY_INFORMATION]; - $units[] = ['unit' => 'senderRecipientInformations', 'label' => _DEST_INFORMATION]; - $units[] = ['unit' => 'diffusionList', 'label' => _DIFFUSION_LIST]; - $units[] = ['unit' => 'visaWorkflow', 'label' => _VISA_WORKFLOW]; - $units[] = ['unit' => 'opinionWorkflow', 'label' => _AVIS_WORKFLOW]; - $units[] = ['unit' => 'notes', 'label' => _NOTES_COMMENT]; - - // Data for resources - $tmpIds = [$aArgs['resIdMaster']]; - $data = []; - foreach ($units as $unit) { - if ($unit['unit'] == 'notes') { - $data['notes'] = NoteModel::get([ - 'select' => ['id', 'note_text', 'user_id', 'creation_date', 'identifier'], - 'where' => ['identifier in (?)'], - 'data' => [$tmpIds], - 'order_by' => ['identifier']]); - - $userEntities = EntityModel::getByLogin(['login' => $aArgs['userId'], 'select' => ['entity_id']]); - $data['userEntities'] = []; - foreach ($userEntities as $userEntity) { - $data['userEntities'][] = $userEntity['entity_id']; - } - } elseif ($unit['unit'] == 'opinionWorkflow') { - $data['listInstancesOpinion'] = ListInstanceModel::get([ - 'select' => ['item_id', 'process_date', 'res_id'], - 'where' => ['difflist_type = ?', 'res_id in (?)'], - 'data' => ['AVIS_CIRCUIT', $tmpIds], - 'orderBy' => ['listinstance_id'] - ]); - } elseif ($unit['unit'] == 'visaWorkflow') { - $data['listInstancesVisa'] = ListInstanceModel::get([ - 'select' => ['item_id', 'requested_signature', 'process_date', 'res_id'], - 'where' => ['difflist_type = ?', 'res_id in (?)'], - 'data' => ['VISA_CIRCUIT', $tmpIds], - 'orderBy' => ['listinstance_id'] - ]); - } elseif ($unit['unit'] == 'diffusionList') { - $data['listInstances'] = ListInstanceModel::get([ - 'select' => ['item_id', 'item_type', 'item_mode', 'res_id'], - 'where' => ['difflist_type = ?', 'res_id in (?)'], - 'data' => ['entity_id', $tmpIds], - 'orderBy' => ['listinstance_id'] - ]); - } elseif ($unit['unit'] == 'senderRecipientInformations') { - $data['mlbCollExt'] = ResModel::getExt([ - 'select' => ['category_id', 'address_id', 'exp_user_id', 'dest_user_id', 'is_multicontacts', 'res_id'], - 'where' => ['res_id in (?)'], - 'data' => [$tmpIds] - ]); + $units = []; + $units[] = ['unit' => 'primaryInformations']; + $units[] = ['unit' => 'secondaryInformations', 'label' => _SECONDARY_INFORMATION]; + $units[] = ['unit' => 'senderRecipientInformations', 'label' => _DEST_INFORMATION]; + $units[] = ['unit' => 'diffusionList', 'label' => _DIFFUSION_LIST]; + $units[] = ['unit' => 'visaWorkflow', 'label' => _VISA_WORKFLOW]; + $units[] = ['unit' => 'opinionWorkflow', 'label' => _AVIS_WORKFLOW]; + $units[] = ['unit' => 'notes', 'label' => _NOTES_COMMENT]; + + // Data for resources + $tmpIds = [$aArgs['resIdMaster']]; + $data = []; + foreach ($units as $unit) { + if ($unit['unit'] == 'notes') { + $data['notes'] = NoteModel::get([ + 'select' => ['id', 'note_text', 'user_id', 'creation_date', 'identifier'], + 'where' => ['identifier in (?)'], + 'data' => [$tmpIds], + 'order_by' => ['identifier']]); + + $userEntities = EntityModel::getByLogin(['login' => $aArgs['userId'], 'select' => ['entity_id']]); + $data['userEntities'] = []; + foreach ($userEntities as $userEntity) { + $data['userEntities'][] = $userEntity['entity_id']; } + } elseif ($unit['unit'] == 'opinionWorkflow') { + $data['listInstancesOpinion'] = ListInstanceModel::get([ + 'select' => ['item_id', 'process_date', 'res_id'], + 'where' => ['difflist_type = ?', 'res_id in (?)'], + 'data' => ['AVIS_CIRCUIT', $tmpIds], + 'orderBy' => ['listinstance_id'] + ]); + } elseif ($unit['unit'] == 'visaWorkflow') { + $data['listInstancesVisa'] = ListInstanceModel::get([ + 'select' => ['item_id', 'requested_signature', 'process_date', 'res_id'], + 'where' => ['difflist_type = ?', 'res_id in (?)'], + 'data' => ['VISA_CIRCUIT', $tmpIds], + 'orderBy' => ['listinstance_id'] + ]); + } elseif ($unit['unit'] == 'diffusionList') { + $data['listInstances'] = ListInstanceModel::get([ + 'select' => ['item_id', 'item_type', 'item_mode', 'res_id'], + 'where' => ['difflist_type = ?', 'res_id in (?)'], + 'data' => ['entity_id', $tmpIds], + 'orderBy' => ['listinstance_id'] + ]); + } elseif ($unit['unit'] == 'senderRecipientInformations') { + $data['mlbCollExt'] = ResModel::getExt([ + 'select' => ['category_id', 'address_id', 'exp_user_id', 'dest_user_id', 'is_multicontacts', 'res_id'], + 'where' => ['res_id in (?)'], + 'data' => [$tmpIds] + ]); } + } - $pdf = new Fpdi('P', 'pt'); - $pdf->setPrintHeader(false); - SummarySheetController::createSummarySheet($pdf, ['resource' => $mainResource[0], 'units' => $units, 'login' => $aArgs['userId'], 'data' => $data]); + $pdf = new Fpdi('P', 'pt'); + $pdf->setPrintHeader(false); + SummarySheetController::createSummarySheet($pdf, ['resource' => $mainResource[0], 'units' => $units, 'login' => $aArgs['userId'], 'data' => $data]); - $tmpPath = CoreConfigModel::getTmpPath(); - $filename = $tmpPath . "summarySheet_".$aArgs['resIdMaster'] . "_" . $aArgs['userId'] ."_".rand().".pdf"; - $pdf->Output($filename, 'F'); + $tmpPath = CoreConfigModel::getTmpPath(); + $filename = $tmpPath . "summarySheet_".$aArgs['resIdMaster'] . "_" . $aArgs['userId'] ."_".rand().".pdf"; + $pdf->Output($filename, 'F'); - $concatPdf = new Fpdi('P', 'pt'); - $concatPdf->setPrintHeader(false); + $concatPdf = new Fpdi('P', 'pt'); + $concatPdf->setPrintHeader(false); + + if ($aArgs['objectSent'] == 'mail') { foreach ([$filename, $arrivedMailMainfilePath] as $file) { $pageCount = $concatPdf->setSourceFile($file); for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) { @@ -222,6 +223,13 @@ class MaarchParapheurController 'title' => $mainResource[0]['subject'], 'reference' => $mainResource[0]['alt_identifier'] ]]; + + $summarySheetEncodedZip = MaarchParapheurController::createZip(['filepath' => $filename, 'filename' => "summarySheet.pdf"]); + $attachmentsData[] = [ + 'encodedDocument' => $summarySheetEncodedZip, + 'title' => "summarySheet.pdf", + 'reference' => "" + ]; } else { $attachmentsData = []; }