From 82bb716a3366f1697b183a66f91dd6af3a22df30 Mon Sep 17 00:00:00 2001 From: Guillaume Heurtier <guillaume.heurtier@maarch.org> Date: Tue, 12 May 2020 17:08:51 +0200 Subject: [PATCH] FIX #13339 TIME 0:25 added resource usage count for contacts --- .../contact/controllers/ContactController.php | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/app/contact/controllers/ContactController.php b/src/app/contact/controllers/ContactController.php index 301a4625f91..68f17ac924b 100755 --- a/src/app/contact/controllers/ContactController.php +++ b/src/app/contact/controllers/ContactController.php @@ -278,6 +278,26 @@ class ContactController $filling = ContactController::getFillingRate(['contactId' => $rawContact['id']]); $contact['fillingRate'] = empty($filling) ? null : $filling; + $inResources = ResourceContactModel::get([ + 'select' => ['item_id'], + 'where' => ['item_id = ?', 'type = ?'], + 'data' => [$args['id'], 'contact'] + ]); + + $inAcknowledgementReceipts = AcknowledgementReceiptModel::get([ + 'select' => ['contact_id'], + 'where' => ['contact_id = ?'], + 'data' => [$args['id']] + ]); + + $inAttachments = AttachmentModel::get([ + 'select' => ['recipient_id'], + 'where' => ['recipient_id = ?', 'recipient_type = ?'], + 'data' => [$args['id'], 'contact'] + ]); + + $contact['usageCount'] = count($inResources) + count($inAcknowledgementReceipts) + count($inAttachments); + return $response->withJson($contact); } @@ -970,7 +990,7 @@ class ContactController return $response->withStatus(400)->withJson(['errors' => 'Body duplicates is empty or not an array']); } - $fields = ['firstname', 'lastname', 'company', 'address_number', 'address_street', 'address_additional1', 'address_additional2', + $fields = ['title', 'firstname', 'lastname', 'company', 'address_number', 'address_street', 'address_additional1', 'address_additional2', 'address_postcode', 'address_town', 'address_country', 'department', 'function', 'email', 'phone']; $master = ContactModel::getById([ -- GitLab