From fa64eea5da577b4e1e3a2fe75bf69157fd591d6c Mon Sep 17 00:00:00 2001 From: Guillaume Heurtier <guillaume.heurtier@maarch.org> Date: Fri, 27 Dec 2019 17:26:04 +0100 Subject: [PATCH] FEAT #12428 TIME 0:20 added limit on contact in notifications --- modules/templates/datasources/letterbox_events.php | 6 ++++-- modules/templates/datasources/mlb_notes_content.php | 10 ++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/modules/templates/datasources/letterbox_events.php b/modules/templates/datasources/letterbox_events.php index 9da30cb131d..bfe7fd58428 100755 --- a/modules/templates/datasources/letterbox_events.php +++ b/modules/templates/datasources/letterbox_events.php @@ -112,10 +112,12 @@ foreach ($events as $event) { $resourceContacts = ResourceContactModel::get([ 'where' => ['res_id = ?', "mode='sender'", "type='contact'"], 'data' => [$res['res_id']], + 'limit' => 1 ]); + $resourceContacts = $resourceContacts[0]; - foreach ($resourceContacts as $resourceContact) { - $contact = ContactModel::getById(['id' => $resourceContact['item_id'], 'select' => ['*']]); + if (!empty($resourceContacts)) { + $contact = ContactModel::getById(['id' => $resourceContacts['item_id'], 'select' => ['*']]); $postalAddress = ContactController::getContactAfnor($contact); unset($postalAddress[0]); diff --git a/modules/templates/datasources/mlb_notes_content.php b/modules/templates/datasources/mlb_notes_content.php index 0e7a0359858..64347ba34ac 100755 --- a/modules/templates/datasources/mlb_notes_content.php +++ b/modules/templates/datasources/mlb_notes_content.php @@ -93,8 +93,10 @@ foreach ($events as $event) { $resourceContacts = ResourceContactModel::get([ 'where' => ['res_id = ?', "type = 'contact'", "mode = 'sender'"], - 'data' => [$resId] + 'data' => [$resId], + 'limit' => 1 ]); + $resourceContacts = $resourceContacts[0]; if ($event->table_name == 'notes') { $datasources['res_letterbox'][0]['linktodoc'] = $note['linktodoc']; @@ -103,11 +105,11 @@ foreach ($events as $event) { $labelledUser = UserModel::getLabelledUserById(['id' => $note['user_id']]); $creationDate = TextFormatModel::formatDate($note['creation_date'], 'd/m/Y'); - $note = "{$labelledUser} : {$creationDate} : {$note['note_text']}\n"; + $note = "{$labelledUser} {$creationDate} : {$note['note_text']}\n"; } - foreach ($resourceContacts as $resourceContact) { - $contact = ContactModel::getById(['id' => $resourceContact['item_id'], 'select' => ['*']]); + if (!empty($resourceContacts)) { + $contact = ContactModel::getById(['id' => $resourceContacts['item_id'], 'select' => ['*']]); $datasources['contact'][] = $contact; } -- GitLab