diff --git a/migration/21.04/2104.sql b/migration/21.04/2104.sql new file mode 100644 index 0000000000000000000000000000000000000000..e23016251dc981cc9c2ef86e798e5c29cc45e370 --- /dev/null +++ b/migration/21.04/2104.sql @@ -0,0 +1,25 @@ +-- *************************************************************************-- +-- -- +-- -- +-- Model migration script - 20.10 to 21.04 -- +-- -- +-- -- +-- *************************************************************************-- +UPDATE parameters SET param_value_string = '21.04.1' WHERE id = 'database_version'; + +DROP TABLE IF EXISTS attachment_types; +CREATE TABLE attachment_types +( + id SERIAL NOT NULL, + type_id text NOT NULL, + label text NOT NULL, + visible BOOLEAN NOT NULL, + email_link BOOLEAN NOT NULL, + signable BOOLEAN NOT NULL, + icon text, + chrono BOOLEAN NOT NULL, + version_enabled BOOLEAN NOT NULL, + new_version_default BOOLEAN NOT NULL, + CONSTRAINT attachment_types_pkey PRIMARY KEY (id) +) +WITH (OIDS=FALSE); diff --git a/migration/21.04/migrate.sh b/migration/21.04/migrate.sh new file mode 100644 index 0000000000000000000000000000000000000000..1beecc30387cfb3dda9cf477f47f71dffdbb37ea --- /dev/null +++ b/migration/21.04/migrate.sh @@ -0,0 +1,2 @@ +#!/bin/sh +php ./migrateAttachmentTypes.php diff --git a/migration/21.04/migrateAttachmentTypes.php b/migration/21.04/migrateAttachmentTypes.php new file mode 100644 index 0000000000000000000000000000000000000000..99b3d3ef0f93994e0946b4bf099d878abbeeb74b --- /dev/null +++ b/migration/21.04/migrateAttachmentTypes.php @@ -0,0 +1,65 @@ +<?php + +require '../../vendor/autoload.php'; + +chdir('../..'); + +$customs = scandir('custom'); + + +foreach ($customs as $custom) { + if (in_array($custom, ['custom.json', 'custom.xml', '.', '..'])) { + continue; + } + + \SrcCore\models\DatabasePDO::reset(); + new \SrcCore\models\DatabasePDO(['customId' => $custom]); + $GLOBALS['customId'] = $custom; + + $language = \SrcCore\models\CoreConfigModel::getLanguage(); + if (file_exists("custom/{$custom}/src/core/lang/lang-{$language}.php")) { + require_once("custom/{$custom}/src/core/lang/lang-{$language}.php"); + } + require_once("src/core/lang/lang-{$language}.php"); + + $migrated = 0; + $attachmentTypesXml = []; + + $loadedXml = \SrcCore\models\CoreConfigModel::getXmlLoaded(['path' => 'apps/maarch_entreprise/xml/entreprise.xml']); + if ($loadedXml) { + $attachmentTypesXML = $loadedXml->attachment_types; + if (count($attachmentTypesXML) > 0) { + foreach ($attachmentTypesXML->type as $value) { + $label = defined((string)$value->label) ? constant((string)$value->label) : (string)$value->label; + $attachmentTypesXml[(string)$value->id] = [ + 'label' => $label, + 'icon' => (string)$value['icon'], + 'sign' => (empty($value['sign']) || (string)$value['sign'] == 'true') ? 'true' : 'false', + 'chrono' => (empty($value['with_chrono']) || (string)$value['with_chrono'] == 'true') ? 'true' : 'false', + 'attachInMail' => (!empty($value['attach_in_mail']) && (string)$value['attach_in_mail'] == 'true') ? 'true' : 'false', + 'show' => (empty($value->attributes()->show) || (string)$value->attributes()->show == 'true') ? 'true' : 'false' + ]; + } + } + } + + if (!empty($attachmentTypesXml)) { + foreach ($attachmentTypesXml as $key => $typeXml) { + $type = [ + 'type_id' => $key, + 'label' => $typeXml['label'], + 'visible' => $typeXml['show'], + 'email_link' => $typeXml['attachInMail'], + 'signable' => $typeXml['sign'], + 'icon' => $typeXml['icon'], + 'chrono' => $typeXml['chrono'], + 'version_enabled' => 'true', + 'new_version_default' => 'true' + ]; + + \Attachment\models\AttachmentTypeModel::create($type); + $migrated++; + } + } + printf("Migration types de pièces jointes (CUSTOM {$custom}) : {$migrated} types migré(s).\n"); +} diff --git a/sql/data_fr.sql b/sql/data_fr.sql index 20909e4870e78da9041c6584a580e19ffafce821..5008fc927d061dc8050d071a9a65d014d21cafc0 100755 --- a/sql/data_fr.sql +++ b/sql/data_fr.sql @@ -1773,3 +1773,13 @@ INSERT INTO registered_mail_issuing_sites_entities (site_id, entity_id) VALUES ( INSERT INTO registered_mail_number_range (type, tracking_account_number, range_start, range_end, creator, creation_date, status, current_number) VALUES ('2C', 'SuiviNumber', 1, 10, 23, '2020-09-14 14:38:09.008644', 'OK', 1); INSERT INTO registered_mail_number_range (type, tracking_account_number, range_start, range_end, creator, creation_date, status, current_number) VALUES ('RW', 'SuiviNumberInternational', 1, 10, 23, '2020-09-14 14:39:32.972626', 'OK', 1); INSERT INTO registered_mail_number_range (type, tracking_account_number, range_start, range_end, creator, creation_date, status, current_number) VALUES ('2D', 'suiviNumber', 1, 10, 23, '2020-09-14 14:39:16.779322', 'OK', 1); + +/* Attachment types */ +INSERT INTO attachment_types (id, type_id, label, visible, email_link, signable, icon, chrono, version_enabled, new_version_default) VALUES (2, 'response_project', 'Projet de réponse', true, true, true, 'R', true, true, true); +INSERT INTO attachment_types (id, type_id, label, visible, email_link, signable, icon, chrono, version_enabled, new_version_default) VALUES (3, 'signed_response', 'Réponse signée', false, true, false, '', true, true, true); +INSERT INTO attachment_types (id, type_id, label, visible, email_link, signable, icon, chrono, version_enabled, new_version_default) VALUES (4, 'simple_attachment', 'Pièce jointe', true, false, false, 'PJ', false, true, true); +INSERT INTO attachment_types (id, type_id, label, visible, email_link, signable, icon, chrono, version_enabled, new_version_default) VALUES (5, 'incoming_mail_attachment', 'Pièce jointe capturée', true, false, false, '', false, true, true); +INSERT INTO attachment_types (id, type_id, label, visible, email_link, signable, icon, chrono, version_enabled, new_version_default) VALUES (6, 'outgoing_mail', 'Courrier départ spontané', true, false, true, 'DS', true, true, true); +INSERT INTO attachment_types (id, type_id, label, visible, email_link, signable, icon, chrono, version_enabled, new_version_default) VALUES (7, 'summary_sheet', 'Fiche de liaison', false, false, false, '', true, true, true); +INSERT INTO attachment_types (id, type_id, label, visible, email_link, signable, icon, chrono, version_enabled, new_version_default) VALUES (8, 'acknowledgement_record_management', 'Accusé de réception (Archivage)', false, false, false, '', true, true, true); +INSERT INTO attachment_types (id, type_id, label, visible, email_link, signable, icon, chrono, version_enabled, new_version_default) VALUES (9, 'reply_record_management', 'Réponse au transfert (Archivage)', false, false, false, '', true, true, true); diff --git a/sql/structure.sql b/sql/structure.sql index 6b4fd08b15cbee81a6e9b603c1f0e90c9958ae17..ad8039d6a9495454f79b59bac390936d020dec68 100755 --- a/sql/structure.sql +++ b/sql/structure.sql @@ -1502,6 +1502,7 @@ CREATE TABLE attachment_types email_link BOOLEAN NOT NULL, signable BOOLEAN NOT NULL, icon text, + chrono BOOLEAN NOT NULL, version_enabled BOOLEAN NOT NULL, new_version_default BOOLEAN NOT NULL, CONSTRAINT attachment_types_pkey PRIMARY KEY (id) diff --git a/src/app/action/controllers/ActionMethodController.php b/src/app/action/controllers/ActionMethodController.php index c726884213900a95b6f74299b64429c7a5537bea..0a5fadb1f034de0dfdc07d2eef8fba463c3f84e8 100644 --- a/src/app/action/controllers/ActionMethodController.php +++ b/src/app/action/controllers/ActionMethodController.php @@ -19,6 +19,7 @@ use Action\models\ResMarkAsReadModel; use Alfresco\controllers\AlfrescoController; use Attachment\controllers\AttachmentController; use Attachment\models\AttachmentModel; +use Attachment\models\AttachmentTypeModel; use Convert\controllers\ConvertPdfController; use Convert\models\AdrModel; use Docserver\controllers\DocserverController; @@ -369,10 +370,10 @@ class ActionMethodController $resourceIn = !empty($integrations['inSignatureBook']); $signableAttachmentsTypes = []; - $attachmentsTypes = AttachmentModel::getAttachmentsTypesByXML(); - foreach ($attachmentsTypes as $key => $type) { - if ($type['sign']) { - $signableAttachmentsTypes[] = $key; + $attachmentsTypes = AttachmentTypeModel::get(['select' => ['type_id', 'signable']]); + foreach ($attachmentsTypes as $type) { + if ($type['signable']) { + $signableAttachmentsTypes[] = $type['type_id']; } } diff --git a/src/app/action/controllers/PreProcessActionController.php b/src/app/action/controllers/PreProcessActionController.php index cb5cf93c9972d597b71676ff328e53cde6b2f7f8..27c7bf3af87b95d0f11232cba68555907f5c920b 100755 --- a/src/app/action/controllers/PreProcessActionController.php +++ b/src/app/action/controllers/PreProcessActionController.php @@ -15,6 +15,7 @@ namespace Action\controllers; use AcknowledgementReceipt\models\AcknowledgementReceiptModel; use Action\models\ActionModel; use Attachment\models\AttachmentModel; +use Attachment\models\AttachmentTypeModel; use Basket\models\BasketModel; use Basket\models\GroupBasketRedirectModel; use Configuration\models\ConfigurationModel; @@ -455,8 +456,9 @@ class PreProcessActionController 'data' => [$resId] ]); - $attachmentTypes = AttachmentModel::getAttachmentsTypesByXML(); - + $attachmentTypes = AttachmentTypeModel::get(['select' => ['type_id', 'signable']]); + $attachmentTypes = array_column($attachmentTypes, 'signable', 'type_id'); + if (empty($attachments) && empty($integratedResource)) { $additionalsInfos['noAttachment'][] = ['alt_identifier' => $noAttachmentsResource['alt_identifier'], 'res_id' => $resId, 'reason' => 'noAttachmentInSignatoryBook']; } else { @@ -480,7 +482,7 @@ class PreProcessActionController $additionalsInfos['noAttachment'][] = ['alt_identifier' => $noAttachmentsResource['alt_identifier'], 'res_id' => $resIdAttachment, 'reason' => 'fileDoesNotExists']; break; } - if ($attachmentTypes[$value['attachment_type']]['sign']) { + if ($attachmentTypes[$value['attachment_type']]) { $hasSignableAttachment = true; } } @@ -987,10 +989,10 @@ class PreProcessActionController } $signableAttachmentsTypes = []; - $attachmentsTypes = AttachmentModel::getAttachmentsTypesByXML(); - foreach ($attachmentsTypes as $key => $type) { - if ($type['sign']) { - $signableAttachmentsTypes[] = $key; + $attachmentsTypes = AttachmentTypeModel::get(['select' => ['type_id', 'signable']]); + foreach ($attachmentsTypes as $type) { + if ($type['signable']) { + $signableAttachmentsTypes[] = $type['type_id']; } } @@ -1052,10 +1054,10 @@ class PreProcessActionController $body['resources'] = PreProcessActionController::getNonLockedResources(['resources' => $body['resources'], 'userId' => $GLOBALS['id']]); $signableAttachmentsTypes = []; - $attachmentsTypes = AttachmentModel::getAttachmentsTypesByXML(); - foreach ($attachmentsTypes as $key => $type) { - if ($type['sign']) { - $signableAttachmentsTypes[] = $key; + $attachmentsTypes = AttachmentTypeModel::get(['select' => ['type_id', 'signable']]); + foreach ($attachmentsTypes as $type) { + if ($type['signable']) { + $signableAttachmentsTypes[] = $type['type_id']; } } @@ -1115,10 +1117,10 @@ class PreProcessActionController $body['resources'] = PreProcessActionController::getNonLockedResources(['resources' => $body['resources'], 'userId' => $GLOBALS['id']]); $signableAttachmentsTypes = []; - $attachmentsTypes = AttachmentModel::getAttachmentsTypesByXML(); - foreach ($attachmentsTypes as $key => $type) { - if ($type['sign']) { - $signableAttachmentsTypes[] = $key; + $attachmentsTypes = AttachmentTypeModel::get(['select' => ['type_id', 'signable']]); + foreach ($attachmentsTypes as $type) { + if ($type['signable']) { + $signableAttachmentsTypes[] = $type['type_id']; } } @@ -1187,10 +1189,10 @@ class PreProcessActionController $body['resources'] = PreProcessActionController::getNonLockedResources(['resources' => $body['resources'], 'userId' => $GLOBALS['id']]); $signableAttachmentsTypes = []; - $attachmentsTypes = AttachmentModel::getAttachmentsTypesByXML(); - foreach ($attachmentsTypes as $key => $type) { - if ($type['sign']) { - $signableAttachmentsTypes[] = $key; + $attachmentsTypes = AttachmentTypeModel::get(['select' => ['type_id', 'signable']]); + foreach ($attachmentsTypes as $type) { + if ($type['signable']) { + $signableAttachmentsTypes[] = $type['type_id']; } } diff --git a/src/app/attachment/controllers/AttachmentController.php b/src/app/attachment/controllers/AttachmentController.php index cb25ff59e16a49df962fc1aae5678d000a3a6c4f..8ea0be72723f59e841deb32ff4c683f7517b4af9 100755 --- a/src/app/attachment/controllers/AttachmentController.php +++ b/src/app/attachment/controllers/AttachmentController.php @@ -15,6 +15,7 @@ namespace Attachment\controllers; use Attachment\models\AttachmentModel; +use Attachment\models\AttachmentTypeModel; use Contact\models\ContactModel; use ContentManagement\controllers\MergeController; use Convert\controllers\ConvertPdfController; @@ -110,9 +111,10 @@ class AttachmentController $attachment['typistLabel'] = $typist['firstname']. ' ' .$typist['lastname']; $attachment['modifiedBy'] = UserModel::getLabelledUserById(['id' => $attachment['modifiedBy']]); - $attachmentsTypes = AttachmentModel::getAttachmentsTypesByXML(); - if (!empty($attachmentsTypes[$attachment['type']]['label'])) { - $attachment['typeLabel'] = $attachmentsTypes[$attachment['type']]['label']; + $attachmentsTypes = AttachmentTypeModel::get(['select' => ['type_id', 'label']]); + $attachmentsTypes = array_column($attachmentsTypes, 'label', 'type_id'); + if (!empty($attachmentsTypes[$attachment['type']])) { + $attachment['typeLabel'] = $attachmentsTypes[$attachment['type']]; } $oldVersions = []; @@ -173,7 +175,8 @@ class AttachmentController return $response->withStatus(400)->withJson(['errors' => 'Can not update attachment use for record_management']); } - $attachmentsTypes = AttachmentModel::getAttachmentsTypesByXML(); + $attachmentsTypes = AttachmentTypeModel::get(['select' => ['type_id']]); + $attachmentsTypes = array_column($attachmentsTypes, null, 'type_id'); if (empty($attachmentsTypes[$body['type']])) { return $response->withStatus(400)->withJson(['errors' => 'Body type does not exist']); } @@ -303,7 +306,8 @@ class AttachmentController 'limit' => (int)$queryParams['limit'] ?? 0 ]); - $attachmentsTypes = AttachmentModel::getAttachmentsTypesByXML(); + $attachmentsTypes = AttachmentTypeModel::get(['select' => ['type_id', 'label']]); + $attachmentsTypes = array_column($attachmentsTypes, 'label', 'type_id'); foreach ($attachments as $key => $attachment) { if ($attachment['modificationDate'] == $attachment['creationDate']) { $attachments[$key]['modificationDate'] = null; @@ -315,8 +319,8 @@ class AttachmentController } $attachments[$key]['modifiedBy'] = UserModel::getLabelledUserById(['id' => $attachment['modifiedBy']]); - if (!empty($attachmentsTypes[$attachment['type']]['label'])) { - $attachments[$key]['typeLabel'] = $attachmentsTypes[$attachment['type']]['label']; + if (!empty($attachmentsTypes[$attachment['type']])) { + $attachments[$key]['typeLabel'] = $attachmentsTypes[$attachment['type']]; } if ($attachment['status'] == 'SIGN') { @@ -904,7 +908,8 @@ class AttachmentController return ['errors' => 'Body resIdMaster is out of perimeter']; } - $attachmentsTypes = AttachmentModel::getAttachmentsTypesByXML(); + $attachmentsTypes = AttachmentTypeModel::get(['select' => ['type_id']]); + $attachmentsTypes = array_column($attachmentsTypes, 'type_id', 'type_id'); if (empty($attachmentsTypes[$body['type']])) { return ['errors' => 'Body type does not exist']; } diff --git a/src/app/attachment/models/AttachmentTypeModel.php b/src/app/attachment/models/AttachmentTypeModel.php index b2f6582be11a2cc08d6db90ad364c2e77129f964..34bb8587ddad98f52256acbac723b1eb6c49b4f4 100644 --- a/src/app/attachment/models/AttachmentTypeModel.php +++ b/src/app/attachment/models/AttachmentTypeModel.php @@ -60,8 +60,8 @@ class AttachmentTypeModel public static function create(array $args) { - ValidatorModel::notEmpty($args, ['type_id', 'label', 'visible', 'email_link', 'signable', 'version_enabled', 'new_version_default']); - ValidatorModel::stringType($args, ['type_id', 'label', 'visible', 'email_link', 'signable', 'version_enabled', 'new_version_default', 'icon']); + ValidatorModel::notEmpty($args, ['type_id', 'label', 'visible', 'email_link', 'signable', 'version_enabled', 'new_version_default', 'chrono']); + ValidatorModel::stringType($args, ['type_id', 'label', 'visible', 'email_link', 'signable', 'version_enabled', 'new_version_default', 'chrono', 'icon']); $nextSequenceId = DatabaseModel::getNextSequenceValue(['sequenceId' => 'attachment_types_id_seq']); @@ -75,6 +75,7 @@ class AttachmentTypeModel 'email_link' => $args['email_link'], 'signable' => $args['signable'], 'icon' => $args['icon'], + 'chrono' => $args['chrono'], 'version_enabled' => $args['version_enabled'], 'new_version_default' => $args['new_version_default'], ] diff --git a/src/app/email/controllers/EmailController.php b/src/app/email/controllers/EmailController.php index c546b01a4d29b77e88948f92bb6d71c27fbfa065..31d4a820a7ab1b27af11ccd62061f96293f3d234 100644 --- a/src/app/email/controllers/EmailController.php +++ b/src/app/email/controllers/EmailController.php @@ -395,7 +395,8 @@ class EmailController } $attachments = []; - $attachmentTypes = AttachmentModel::getAttachmentsTypesByXML(); + $attachmentTypes = AttachmentModel::get(['select' => ['type_id', 'label', 'email_link']]); + $attachmentTypes = array_column($attachmentTypes, null, 'type_id'); $rawAttachments = AttachmentModel::get([ 'select' => ['res_id', 'title', 'identifier', 'attachment_type', 'typist', 'format', 'filesize', 'status'], 'where' => ['res_id_master = ?', 'attachment_type not in (?)', 'status not in (?)'], @@ -433,7 +434,7 @@ class EmailController 'chrono' => $attachment['identifier'], 'label' => $attachment['title'], 'typeLabel' => $attachmentTypes[$attachment['attachment_type']]['label'], - 'attachInMail' => $attachmentTypes[$attachment['attachment_type']]['attachInMail'], + 'attachInMail' => $attachmentTypes[$attachment['attachment_type']]['email_link'], 'convertedDocument' => $convertedDocument, 'creator' => UserModel::getLabelledUserById(['id' => $attachment['typist']]), 'format' => $attachment['format'], diff --git a/src/app/external/alfresco/controllers/AlfrescoController.php b/src/app/external/alfresco/controllers/AlfrescoController.php index d6d0d29e4cc95370d53952827496fceba62c4939..e79ee9bd89e2dccc9260408f307b260f33a936cb 100644 --- a/src/app/external/alfresco/controllers/AlfrescoController.php +++ b/src/app/external/alfresco/controllers/AlfrescoController.php @@ -15,6 +15,7 @@ namespace Alfresco\controllers; use Attachment\models\AttachmentModel; +use Attachment\models\AttachmentTypeModel; use Configuration\models\ConfigurationModel; use Contact\controllers\ContactController; use Contact\models\ContactModel; @@ -794,8 +795,9 @@ class AlfrescoController if (!empty($alfrescoParameters['mapping']['attachment'])) { foreach ($alfrescoParameters['mapping']['attachment'] as $key => $alfrescoParameter) { if ($alfrescoParameter == 'typeLabel') { - $attachmentsTypes = AttachmentModel::getAttachmentsTypesByXML(); - $properties[$key] = $attachmentsTypes[$attachment['attachment_type']]['label']; + $attachmentsTypes = AttachmentTypeModel::get(['select' => ['type_id', 'label']]); + $attachmentsTypes = array_column($attachmentsTypes, 'label', 'type_id'); + $properties[$key] = $attachmentsTypes[$attachment['attachment_type']]; } else { $properties[$key] = $attachment[$alfrescoParameter]; } diff --git a/src/app/external/externalSignatoryBook/controllers/FastParapheurController.php b/src/app/external/externalSignatoryBook/controllers/FastParapheurController.php index 5d3b611a6d8db94c41bb8efcdd9a0c81f3dc7a52..24cea7721ec6381219134365bdb5bbef68e46581 100755 --- a/src/app/external/externalSignatoryBook/controllers/FastParapheurController.php +++ b/src/app/external/externalSignatoryBook/controllers/FastParapheurController.php @@ -16,6 +16,7 @@ namespace ExternalSignatoryBook\controllers; use Attachment\models\AttachmentModel; +use Attachment\models\AttachmentTypeModel; use Convert\controllers\ConvertPdfController; use Convert\models\AdrModel; use Docserver\models\DocserverModel; @@ -167,9 +168,10 @@ class FastParapheurController 'data' => [$aArgs['resIdMaster'], ['signed_response']] ]); - $attachmentTypes = AttachmentModel::getAttachmentsTypesByXML(); + $attachmentTypes = AttachmentTypeModel::get(['select' => ['type_id', 'signable']]); + $attachmentTypes = array_column($attachmentTypes, 'signable', 'type_id'); foreach ($attachments as $key => $value) { - if (!$attachmentTypes[$value['attachment_type']]['sign']) { + if (!$attachmentTypes[$value['attachment_type']]) { $annexeAttachmentPath = DocserverModel::getByDocserverId(['docserverId' => $value['docserver_id'], 'select' => ['path_template', 'docserver_type_id']]); $value['filePath'] = $annexeAttachmentPath['path_template'] . str_replace('#', DIRECTORY_SEPARATOR, $value['path']) . $value['filename']; diff --git a/src/app/external/externalSignatoryBook/controllers/IParapheurController.php b/src/app/external/externalSignatoryBook/controllers/IParapheurController.php index 4fc6ffaa95d09c0ca9e2479947e07771b560e7f5..81065fccd75da8db061bb1020c0581f28cf35029 100755 --- a/src/app/external/externalSignatoryBook/controllers/IParapheurController.php +++ b/src/app/external/externalSignatoryBook/controllers/IParapheurController.php @@ -16,6 +16,7 @@ namespace ExternalSignatoryBook\controllers; use Attachment\models\AttachmentModel; +use Attachment\models\AttachmentTypeModel; use Convert\controllers\ConvertPdfController; use Convert\models\AdrModel; use Docserver\models\DocserverModel; @@ -104,9 +105,10 @@ class IParapheurController 'data' => [$aArgs['resIdMaster'], ['signed_response']] ]); - $attachmentTypes = AttachmentModel::getAttachmentsTypesByXML(); + $attachmentTypes = AttachmentTypeModel::get(['select' => ['type_id', 'signable']]); + $attachmentTypes = array_column($attachmentTypes, 'signable', 'type_id'); foreach ($attachments as $key => $value) { - if (!$attachmentTypes[$value['attachment_type']]['sign']) { + if (!$attachmentTypes[$value['attachment_type']]) { $adrInfo = AdrModel::getConvertedDocumentById(['resId' => $value['res_id'], 'collId' => 'attachments_coll', 'type' => 'PDF']); $annexeAttachmentPath = DocserverModel::getByDocserverId(['docserverId' => $adrInfo['docserver_id'], 'select' => ['path_template']]); $value['filePath'] = $annexeAttachmentPath['path_template'] . str_replace('#', DIRECTORY_SEPARATOR, $adrInfo['path']) . $adrInfo['filename']; diff --git a/src/app/external/externalSignatoryBook/controllers/IxbusController.php b/src/app/external/externalSignatoryBook/controllers/IxbusController.php index d6f56e168d058d52eec7eaa0045a44a65e4f9572..d08fde2b0ff26233392e4781963272f7992bb111 100755 --- a/src/app/external/externalSignatoryBook/controllers/IxbusController.php +++ b/src/app/external/externalSignatoryBook/controllers/IxbusController.php @@ -15,6 +15,7 @@ namespace ExternalSignatoryBook\controllers; use Attachment\models\AttachmentModel; +use Attachment\models\AttachmentTypeModel; use Convert\controllers\ConvertPdfController; use Docserver\models\DocserverModel; use Docserver\models\DocserverTypeModel; @@ -197,9 +198,10 @@ class IxbusController 'data' => [$aArgs['resIdMaster'], ['incoming_mail_attachment', 'signed_response']] ]); - $attachmentTypes = AttachmentModel::getAttachmentsTypesByXML(); + $attachmentTypes = AttachmentTypeModel::get(['select' => ['type_id', 'signable']]); + $attachmentTypes = array_column($attachmentTypes, 'signable', 'type_id'); foreach ($attachments as $key => $value) { - if (!$attachmentTypes[$value['attachment_type']]['sign']) { + if (!$attachmentTypes[$value['attachment_type']]) { unset($attachments[$key]); } } diff --git a/src/app/external/externalSignatoryBook/controllers/MaarchParapheurController.php b/src/app/external/externalSignatoryBook/controllers/MaarchParapheurController.php index 5c07346b6482269af6457528e9eb64f0146a2b12..acfdb9718fbec45f3a59b35a75304a0dc2e6d5aa 100755 --- a/src/app/external/externalSignatoryBook/controllers/MaarchParapheurController.php +++ b/src/app/external/externalSignatoryBook/controllers/MaarchParapheurController.php @@ -15,6 +15,7 @@ namespace ExternalSignatoryBook\controllers; use Attachment\models\AttachmentModel; +use Attachment\models\AttachmentTypeModel; use Contact\controllers\ContactController; use Convert\controllers\ConvertPdfController; use Convert\models\AdrModel; @@ -242,9 +243,10 @@ class MaarchParapheurController return ['error' => 'No attachment to send']; } else { $nonSignableAttachments = []; - $attachmentTypes = AttachmentModel::getAttachmentsTypesByXML(); + $attachmentTypes = AttachmentTypeModel::get(['select' => ['type_id', 'signable']]); + $attachmentTypes = array_column($attachmentTypes, 'signable', 'type_id'); foreach ($attachments as $key => $value) { - if (!$attachmentTypes[$value['attachment_type']]['sign']) { + if (!$attachmentTypes[$value['attachment_type']]) { $adrInfo = ConvertPdfController::getConvertedPdfById(['resId' => $value['res_id'], 'collId' => 'attachments_coll']); if (empty($adrInfo['docserver_id']) || strtolower(pathinfo($adrInfo['filename'], PATHINFO_EXTENSION)) != 'pdf') { return ['error' => 'Attachment ' . $value['res_id'] . ' is not converted in pdf']; diff --git a/src/app/external/messageExchange/controllers/SendMessageExchangeController.php b/src/app/external/messageExchange/controllers/SendMessageExchangeController.php index bf70f5d0adf94ffbdaa6d4cb2685a06d5c465a2f..9468c171fb0d7fd11c4230a3eed1f2272793e8bb 100755 --- a/src/app/external/messageExchange/controllers/SendMessageExchangeController.php +++ b/src/app/external/messageExchange/controllers/SendMessageExchangeController.php @@ -15,6 +15,7 @@ namespace MessageExchange\controllers; use Attachment\models\AttachmentModel; +use Attachment\models\AttachmentTypeModel; use Contact\models\ContactModel; use Docserver\models\DocserverModel; use Doctype\models\DoctypeModel; @@ -175,11 +176,12 @@ class SendMessageExchangeController $AttachmentsInfo = []; if (!empty($body['joinAttachment'])) { $AttachmentsInfo = AttachmentModel::get(['select' => ['*'], 'where' => ['res_id in (?)'], 'data' => [$body['joinAttachment']]]); - $attachmentTypes = AttachmentModel::getAttachmentsTypesByXML(); + $attachmentTypes = AttachmentTypeModel::get(['select' => ['type_id', 'label']]); + $attachmentTypes = array_column($attachmentTypes, 'label', 'type_id'); foreach ($AttachmentsInfo as $key => $value) { $AttachmentsInfo[$key]['Title'] = $value['title']; $AttachmentsInfo[$key]['OriginatingAgencyArchiveUnitIdentifier'] = $value['identifier']; - $AttachmentsInfo[$key]['DocumentType'] = $attachmentTypes[$value['attachment_type']]['label']; + $AttachmentsInfo[$key]['DocumentType'] = $attachmentTypes[$value['attachment_type']]; $AttachmentsInfo[$key]['tablenameExchangeMessage'] = 'res_attachments'; } } diff --git a/src/app/resource/controllers/FolderPrintController.php b/src/app/resource/controllers/FolderPrintController.php index 46eb83bcf5b6859e4da32a1b293510281779f529..7a0ac054c852bae3b8f5e01137b29dc09b15279e 100755 --- a/src/app/resource/controllers/FolderPrintController.php +++ b/src/app/resource/controllers/FolderPrintController.php @@ -16,6 +16,7 @@ namespace Resource\controllers; use AcknowledgementReceipt\models\AcknowledgementReceiptModel; use Attachment\models\AttachmentModel; +use Attachment\models\AttachmentTypeModel; use Contact\controllers\ContactController; use Contact\models\ContactModel; use Convert\controllers\ConvertPdfController; @@ -748,8 +749,9 @@ class FolderPrintController $status = StatusModel::getById(['id' => $attachment['status'], 'select' => ['label_status']]); $status = $status['label_status']; - $attachmentTypes = AttachmentModel::getAttachmentsTypesByXML(); - $attachmentType = $attachmentTypes[$attachment['attachment_type']]['label']; + $attachmentTypes = AttachmentTypeModel::get(['select' => ['type_id', 'signable']]); + $attachmentTypes = array_column($attachmentTypes, 'label', 'type_id'); + $attachmentType = $attachmentTypes[$attachment['attachment_type']]; $creationDate = new \DateTime($attachment['creation_date']); $creationDate = $creationDate->format('d-m-Y H:i'); diff --git a/src/app/resource/controllers/StoreController.php b/src/app/resource/controllers/StoreController.php index 9ce2ac77e2ac563061ec8c45b436a58831a63246..be67493a6d692fd30ce2de26592c11edf5ee1f9d 100755 --- a/src/app/resource/controllers/StoreController.php +++ b/src/app/resource/controllers/StoreController.php @@ -16,6 +16,7 @@ namespace Resource\controllers; use Attachment\models\AttachmentModel; +use Attachment\models\AttachmentTypeModel; use ContentManagement\controllers\MergeController; use CustomField\models\CustomFieldModel; use Docserver\controllers\DocserverController; @@ -378,8 +379,9 @@ class StoreController public static function prepareAttachmentStorage(array $args) { - $attachmentsTypes = AttachmentModel::getAttachmentsTypesByXML(); - if ($attachmentsTypes[$args['type']]['chrono'] && empty($args['chrono'])) { + $attachmentsTypes = AttachmentTypeModel::get(['select' => ['type_id', 'chrono']]); + $attachmentsTypes = array_column($attachmentsTypes, 'chrono', 'type_id'); + if ($attachmentsTypes[$args['type']] && empty($args['chrono'])) { $resource = ResModel::getById(['select' => ['destination', 'type_id'], 'resId' => $args['resIdMaster']]); $args['chrono'] = ChronoModel::getChrono(['id' => 'outgoing', 'entityId' => $resource['destination'], 'typeId' => $resource['type_id'], 'resId' => $args['resIdMaster']]); } @@ -435,8 +437,9 @@ class StoreController public static function prepareUpdateAttachmentStorage(array $args) { $attachment = AttachmentModel::getById(['id' => $args['id'], 'select' => ['identifier', 'res_id_master']]); - $attachmentsTypes = AttachmentModel::getAttachmentsTypesByXML(); - if ($attachmentsTypes[$args['type']]['chrono'] && empty($attachment['identifier'])) { + $attachmentsTypes = AttachmentTypeModel::get(['select' => ['type_id', 'chrono']]); + $attachmentsTypes = array_column($attachmentsTypes, 'chrono', 'type_id'); + if ($attachmentsTypes[$args['type']] && empty($attachment['identifier'])) { $resource = ResModel::getById(['select' => ['destination', 'type_id'], 'resId' => $attachment['res_id_master']]); $chrono = ChronoModel::getChrono(['id' => 'outgoing', 'entityId' => $resource['destination'], 'typeId' => $resource['type_id'], 'resId' => $attachment['res_id_master']]); } diff --git a/src/app/signatureBook/controllers/SignatureBookController.php b/src/app/signatureBook/controllers/SignatureBookController.php index 4bb34c98205639d0a4a27b2269f77b87c2e02afa..46ce954eb884928f6d5e19929a37cc4c444200b8 100755 --- a/src/app/signatureBook/controllers/SignatureBookController.php +++ b/src/app/signatureBook/controllers/SignatureBookController.php @@ -15,6 +15,7 @@ namespace SignatureBook\controllers; use Attachment\models\AttachmentModel; +use Attachment\models\AttachmentTypeModel; use Basket\models\BasketModel; use Basket\models\GroupBasketModel; use Basket\models\RedirectBasketModel; @@ -169,13 +170,14 @@ class SignatureBookController ValidatorModel::notEmpty($args, ['resId', 'userId']); ValidatorModel::intVal($args, ['resId', 'userId']); - $attachmentTypes = AttachmentModel::getAttachmentsTypesByXML(); + $attachmentTypes = AttachmentTypeModel::get(['select' => ['type_id', 'label', 'icon', 'signable']]); + $attachmentTypes = array_column($attachmentTypes, null, 'type_id'); $orderBy = "CASE attachment_type WHEN 'response_project' THEN 1"; $c = 2; - foreach ($attachmentTypes as $key => $value) { - if ($value['sign'] && $key != 'response_project') { - $orderBy .= " WHEN '{$key}' THEN {$c}"; + foreach ($attachmentTypes as $value) { + if ($value['signable'] && $value['type_id'] != 'response_project') { + $orderBy .= " WHEN '{$value['type_id']}' THEN {$c}"; ++$c; } } @@ -249,7 +251,7 @@ class SignatureBookController $attachments[$key]['viewerNoSignId'] = $viewerNoSignId; $attachments[$key]['attachment_type'] = $attachmentTypes[$value['attachment_type']]['label']; $attachments[$key]['icon'] = $attachmentTypes[$value['attachment_type']]['icon']; - $attachments[$key]['sign'] = $attachmentTypes[$value['attachment_type']]['sign']; + $attachments[$key]['sign'] = $attachmentTypes[$value['attachment_type']]['signable']; $attachments[$key]['signed'] = $value['status'] == 'SIGN'; $attachments[$key]['viewerId'] = $viewerId; @@ -352,12 +354,13 @@ class SignatureBookController 'data' => [$resIds] ]); - $attachmentTypes = AttachmentModel::getAttachmentsTypesByXML(); + $attachmentTypes = AttachmentTypeModel::get(['select' => ['type_id', 'signable']]); + $attachmentTypes = array_column($attachmentTypes, 'signable', 'type_id'); foreach ($attachmentsInResList as $value) { if ($resListForAttachments[$value['res_id_master']] === null) { $resListForAttachments[$value['res_id_master']] = true; } - if ($attachmentTypes[$value['attachment_type']]['sign'] && ($value['status'] == 'TRA' || $value['status'] == 'A_TRA')) { + if ($attachmentTypes[$value['attachment_type']] && ($value['status'] == 'TRA' || $value['status'] == 'A_TRA')) { $resListForAttachments[$value['res_id_master']] = false; } } diff --git a/src/app/template/controllers/TemplateController.php b/src/app/template/controllers/TemplateController.php index a0adb772d1ae5ccdb010e57715890f9ce602986e..3b72445d0b45bcf32dbcb70b6c34962402c544e1 100755 --- a/src/app/template/controllers/TemplateController.php +++ b/src/app/template/controllers/TemplateController.php @@ -15,6 +15,7 @@ namespace Template\controllers; use Attachment\models\AttachmentModel; +use Attachment\models\AttachmentTypeModel; use ContentManagement\controllers\MergeController; use Convert\controllers\ConvertPdfController; use Docserver\controllers\DocserverController; @@ -84,13 +85,13 @@ class TemplateController } } - $attachmentModelsTmp = AttachmentModel::getAttachmentsTypesByXML(); + $attachmentModelsTmp = AttachmentTypeModel::get(['select' => ['type_id', 'label', 'visible']]); $attachmentTypes = []; - foreach ($attachmentModelsTmp as $key => $value) { - if ($value['show']) { + foreach ($attachmentModelsTmp as $value) { + if ($value['visible']) { $attachmentTypes[] = [ 'label' => $value['label'], - 'id' => $key + 'id' => $value['type_id'] ]; } } @@ -380,13 +381,13 @@ class TemplateController return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); } - $attachmentModelsTmp = AttachmentModel::getAttachmentsTypesByXML(); + $attachmentModelsTmp = AttachmentTypeModel::get(['select' => ['type_id', 'label', 'visible']]); $attachmentTypes = []; - foreach ($attachmentModelsTmp as $key => $value) { - if ($value['show']) { + foreach ($attachmentModelsTmp as $value) { + if ($value['visible']) { $attachmentTypes[] = [ 'label' => $value['label'], - 'id' => $key + 'id' => $value['type_id'] ]; } }