From c1cce7b00ede41a82d265a1d34c4c38c31869047 Mon Sep 17 00:00:00 2001 From: Damien <damien.burel@maarch.org> Date: Thu, 28 Feb 2019 16:19:55 +0100 Subject: [PATCH] FEAT #9514 Begining AR action --- .../models/AcknowledgementReceiptModel.php | 28 ++++++++ .../controllers/ActionMethodController.php | 2 + ...ctionMethodTraitAcknowledgementReceipt.php | 66 +++++++++++++++++++ .../controllers/ResourceListController.php | 2 +- .../template/models/TemplateModelAbstract.php | 2 +- 5 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 src/app/action/controllers/ActionMethodTraitAcknowledgementReceipt.php diff --git a/src/app/acknowledgementReceipt/models/AcknowledgementReceiptModel.php b/src/app/acknowledgementReceipt/models/AcknowledgementReceiptModel.php index b17ceefeaec..e587027abbb 100644 --- a/src/app/acknowledgementReceipt/models/AcknowledgementReceiptModel.php +++ b/src/app/acknowledgementReceipt/models/AcknowledgementReceiptModel.php @@ -36,6 +36,34 @@ class AcknowledgementReceiptModel return $aTemplates; } + public static function create(array $aArgs) + { + ValidatorModel::notEmpty($aArgs, ['resId', 'type', 'format', 'userId', 'contactAddressId', 'docserverId', 'path', 'filename', 'fingerprint']); + ValidatorModel::intVal($aArgs, ['resId', 'userId']); + ValidatorModel::stringType($aArgs, ['type', 'format', 'docserverId', 'path', 'filename', 'fingerprint']); + + $nextSequenceId = DatabaseModel::getNextSequenceValue(['sequenceId' => 'acknowledgement_receipts_id_seq']); + + DatabaseModel::insert([ + 'table' => 'acknowledgment_receipts', + 'columnsValues' => [ + 'id' => $nextSequenceId, + 'res_id' => $aArgs['resId'], + 'type' => $aArgs['type'], + 'format' => $aArgs['format'], + 'user_id' => $aArgs['userId'], + 'contact_address_id' => $aArgs['contactAddressId'], + 'creation_date' => 'CURRENT_TIMESTAMP', + 'docserver_id' => $aArgs['docserverId'], + 'path' => $aArgs['path'], + 'filename' => $aArgs['filename'], + 'fingerprint' => $aArgs['fingerprint'] + ] + ]); + + return $nextSequenceId; + } + public static function update(array $aArgs) { ValidatorModel::notEmpty($aArgs, ['set', 'where', 'data']); diff --git a/src/app/action/controllers/ActionMethodController.php b/src/app/action/controllers/ActionMethodController.php index 5d6f0e60b18..3c2422f0363 100644 --- a/src/app/action/controllers/ActionMethodController.php +++ b/src/app/action/controllers/ActionMethodController.php @@ -23,6 +23,8 @@ use SrcCore\models\CurlModel; class ActionMethodController { + use ActionMethodTraitAcknowledgementReceipt; + const COMPONENTS_ACTIONS = [ 'confirmAction' => null, 'closeMailAction' => 'closeMailAction', diff --git a/src/app/action/controllers/ActionMethodTraitAcknowledgementReceipt.php b/src/app/action/controllers/ActionMethodTraitAcknowledgementReceipt.php new file mode 100644 index 00000000000..ea10372249f --- /dev/null +++ b/src/app/action/controllers/ActionMethodTraitAcknowledgementReceipt.php @@ -0,0 +1,66 @@ +<?php + +/** +* Copyright Maarch since 2008 under licence GPLv3. +* See LICENCE.txt file at the root folder for more details. +* This file is part of Maarch software. + +* @brief ActionController +* @author dev <dev@maarch.org> +* @ingroup core +*/ + +namespace Action\controllers; + +use Contact\models\ContactModel; +use Resource\models\ResModel; +use SrcCore\models\DatabaseModel; +use SrcCore\models\ValidatorModel; + +trait ActionMethodTraitAcknowledgementReceipt +{ + public static function createAcknowledgementReceipts(array $aArgs) + { + ValidatorModel::notEmpty($aArgs, ['resId']); + ValidatorModel::intVal($aArgs, ['resId']); + + + $ext = ResModel::getExtById(['select' => ['category_id', 'address_id', 'is_multicontacts'], 'resId' => $aArgs['resId']]); + + if (empty($ext) || $ext['category_id'] != 'incoming') { + return []; + } + + $contactsToProcess = []; + if ($ext['is_multicontacts'] == 'Y') { + $multiContacts = DatabaseModel::select([ + 'select' => ['address_id'], + 'table' => ['contacts_res'], + 'where' => ['res_id = ?', 'mode = ?', 'address_id != ?'], + 'data' => [$aArgs['resId'], 'multi', 0] + ]); + foreach ($multiContacts as $multiContact) { + $contactsToProcess[] = $multiContact['address_id']; + } + } else { + $contactsToProcess[] = $ext['address_id']; + } + + if (empty($contactsToProcess)) { + return []; + } + + foreach ($contactsToProcess as $contactToProcess) { + $contact = ContactModel::getByAddressId(['addressId' => $contactToProcess, 'select' => ['email', 'address_street', 'address_town', 'address_postal_code']]); + + //TODO check si pas adresse + + if (!empty($contact['email'])) { + + } + } + + + return true; + } +} diff --git a/src/app/resource/controllers/ResourceListController.php b/src/app/resource/controllers/ResourceListController.php index 905f69bcd88..88ea5611569 100644 --- a/src/app/resource/controllers/ResourceListController.php +++ b/src/app/resource/controllers/ResourceListController.php @@ -641,7 +641,7 @@ class ResourceListController $methodResponses = []; foreach ($resourcesForAction as $resId) { if (!empty($method)) { - $methodResponse = ActionMethodController::$method(['id' => $aArgs['actionId'], 'resId' => $resId, 'data' => $body['data']]); + $methodResponse = ActionMethodController::$method(['resId' => $resId, 'data' => $body['data']]); if (!empty($methodResponse['errors'])) { return $response->withStatus(500)->withJson(['errors' => $methodResponse['errors']]); } diff --git a/src/app/template/models/TemplateModelAbstract.php b/src/app/template/models/TemplateModelAbstract.php index 0d8c55b8c92..f8dd436b4f4 100755 --- a/src/app/template/models/TemplateModelAbstract.php +++ b/src/app/template/models/TemplateModelAbstract.php @@ -166,7 +166,7 @@ abstract class TemplateModelAbstract { ValidatorModel::notEmpty($aArgs, ['id']); - $datasources = []; + $datasource = []; $loadedXml = CoreConfigModel::getXmlLoaded(['path' => 'modules/templates/xml/datasources.xml']); if ($loadedXml) { -- GitLab