From 9c159768e9f3b2d11a90b1028c0b5091b2113531 Mon Sep 17 00:00:00 2001 From: Damien <damien.burel@maarch.org> Date: Thu, 14 Nov 2019 11:08:26 +0100 Subject: [PATCH] FEAT #11691 TIME 0:45 Get chrono if needed + merge add --- core/class/PrintControler.php | 2 +- .../controllers/MergeController.php | 7 +++++++ .../resource/controllers/StoreController.php | 15 ++++++++++++--- .../controllers/SummarySheetController.php | 2 +- src/app/user/models/UserModelAbstract.php | 17 +++++++++-------- 5 files changed, 30 insertions(+), 13 deletions(-) diff --git a/core/class/PrintControler.php b/core/class/PrintControler.php index ba37c565a8b..702fc23b79e 100644 --- a/core/class/PrintControler.php +++ b/core/class/PrintControler.php @@ -260,7 +260,7 @@ class PrintControler extends PrintFunctions $pdf->MultiCell(90, 5, utf8_decode(_INITIATOR . ' : ' . $resultEntity->entity_label . " (" . $this->array_print[$cpt]['initiator'] . ")"), 0, 'C', false); } elseif($this->array_print[$cpt]['typist'] <> '') { - $primaryEntity = \User\models\UserModel::getPrimaryEntityById(['id' => $this->array_print[$cpt]['typist']]); + $primaryEntity = \User\models\UserModel::getPrimaryEntityById(['id' => $this->array_print[$cpt]['typist'], 'select' => ['users_entities.entity_id', 'entities.entity_label']]); $pdf->MultiCell(90, 5, utf8_decode(_INITIATOR . ' : ' . $primaryEntity['entity_label'] . " (" . $primaryEntity['entity_id'] . ")"), 0, 'C', false); } diff --git a/src/app/contentManagement/controllers/MergeController.php b/src/app/contentManagement/controllers/MergeController.php index 59fbdf77f55..b7ffe15f424 100644 --- a/src/app/contentManagement/controllers/MergeController.php +++ b/src/app/contentManagement/controllers/MergeController.php @@ -135,12 +135,14 @@ class MergeController $resource["initiator_{$key}"] = $value; } } + $initiator['path'] = EntityModel::getEntityPathByEntityId(['entityId' => $resource['initiator'], 'path' => '']); if (!empty($initiator['parent_entity_id'])) { $parentInitiator = EntityModel::getByEntityId(['entityId' => $initiator['parent_entity_id'], 'select' => ['*']]); } } if (!empty($resource['destination'])) { $destination = EntityModel::getByEntityId(['entityId' => $resource['destination'], 'select' => ['*']]); + $destination['path'] = EntityModel::getEntityPathByEntityId(['entityId' => $resource['destination'], 'path' => '']); if (!empty($destination['parent_entity_id'])) { $parentDestination = EntityModel::getByEntityId(['entityId' => $destination['parent_entity_id'], 'select' => ['*']]); } @@ -154,6 +156,10 @@ class MergeController //User $currentUser = UserModel::getById(['id' => $args['userId'], 'select' => ['firstname', 'lastname', 'phone', 'mail', 'initials']]); + $currentUserPrimaryEntity = UserModel::getPrimaryEntityById(['id' => $args['userId'], 'select' => ['entities.*', 'users_entities.user_role as role']]); + if (!empty($currentUserPrimaryEntity)) { + $currentUserPrimaryEntity['path'] = EntityModel::getEntityPathByEntityId(['entityId' => $currentUserPrimaryEntity['entity_id'], 'path' => '']); + } //Visas $visas = ''; @@ -253,6 +259,7 @@ class MergeController $dataToBeMerge['parentDestination'] = empty($parentDestination) ? [] : $parentDestination; $dataToBeMerge['attachment'] = $attachment; $dataToBeMerge['user'] = $currentUser; + $dataToBeMerge['userPrimaryEntity'] = $currentUserPrimaryEntity; $dataToBeMerge['visas'] = $visas; $dataToBeMerge['opinions'] = $opinions; $dataToBeMerge['copies'] = $copies; diff --git a/src/app/resource/controllers/StoreController.php b/src/app/resource/controllers/StoreController.php index 802a9775700..265717bf8a2 100755 --- a/src/app/resource/controllers/StoreController.php +++ b/src/app/resource/controllers/StoreController.php @@ -100,7 +100,7 @@ class StoreController $id = AttachmentModel::create($data); } else { - $data = StoreController::prepareUpdateAttachmentStorage($data); + $data = StoreController::prepareUpdateAttachmentStorage($data, $args['id']); $id = AttachmentModel::update(['set' => $data, 'where' => ['res_id = ?'], 'data' => [$args['id']]]); } @@ -225,9 +225,15 @@ class StoreController return $preparedData; } - public static function prepareUpdateAttachmentStorage(array $args) + public static function prepareUpdateAttachmentStorage(array $args, int $id) { - //TODO chrono if not chrono + $attachment = AttachmentModel::getById(['id' => $id, 'select' => ['identifier', 'res_id_master']]); + $attachmentsTypes = AttachmentModel::getAttachmentsTypesByXML(); + if ($attachmentsTypes[$args['type']]['chrono'] && 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']]); + } + $preparedData = [ 'title' => $args['title'] ?? null, 'attachment_type' => $args['type'], @@ -235,6 +241,9 @@ class StoreController 'modification_date' => 'CURRENT_TIMESTAMP' ]; + if (!empty($chrono)) { + $preparedData['identifier'] = $chrono; + } if (!empty($args['docserver_id'])) { $preparedData = array_merge($preparedData, [ 'format' => $args['format'], diff --git a/src/app/resource/controllers/SummarySheetController.php b/src/app/resource/controllers/SummarySheetController.php index e3d507bdcef..7360cb1bc8a 100755 --- a/src/app/resource/controllers/SummarySheetController.php +++ b/src/app/resource/controllers/SummarySheetController.php @@ -292,7 +292,7 @@ class SummarySheetController foreach ($resourcesContacts as $contactsKey => $value) { $entitiesFormat = ''; if ($value['type'] == 'user') { - $userEntity = UserModel::getPrimaryEntityById(['id' => $value['item_id']]); + $userEntity = UserModel::getPrimaryEntityById(['id' => $value['item_id'], 'select' => ['entities.entity_label']]); if (!empty($userEntity)) { $entitiesFormat = ' (' . $userEntity['entity_label'] . ')'; } diff --git a/src/app/user/models/UserModelAbstract.php b/src/app/user/models/UserModelAbstract.php index a5b2fe02d0c..234516f5c82 100755 --- a/src/app/user/models/UserModelAbstract.php +++ b/src/app/user/models/UserModelAbstract.php @@ -400,23 +400,24 @@ abstract class UserModelAbstract return $aEntity[0]; } - public static function getPrimaryEntityById(array $aArgs) + public static function getPrimaryEntityById(array $args) { - ValidatorModel::notEmpty($aArgs, ['id']); - ValidatorModel::intVal($aArgs, ['id']); + ValidatorModel::notEmpty($args, ['id', 'select']); + ValidatorModel::intVal($args, ['id']); + ValidatorModel::arrayType($args, ['select']); - $aEntity = DatabaseModel::select([ - 'select' => ['users_entities.entity_id', 'entities.entity_label', 'users_entities.user_role', 'users_entities.primary_entity'], + $entity = DatabaseModel::select([ + 'select' => $args['select'], 'table' => ['users, users_entities, entities'], 'where' => ['users.user_id = users_entities.user_id', 'users_entities.entity_id = entities.entity_id', 'users.id = ?', 'users_entities.primary_entity = ?'], - 'data' => [$aArgs['id'], 'Y'] + 'data' => [$args['id'], 'Y'] ]); - if (empty($aEntity[0])) { + if (empty($entity[0])) { return []; } - return $aEntity[0]; + return $entity[0]; } public static function getGroupsByLogin(array $aArgs) -- GitLab