PMCORE-1596 The files attached in the cases notes needs to send in the email notification.

This commit is contained in:
Roly Rudy Gutierrez Pinto
2020-06-11 11:49:54 -04:00
parent 3ddf8abc7c
commit 536c3588da
6 changed files with 204 additions and 16 deletions

View File

@@ -1,6 +1,7 @@
<?php
use ProcessMaker\Core\System;
use ProcessMaker\Model\Documents;
use ProcessMaker\Util\DateTime;
/**
@@ -186,15 +187,14 @@ class AppNotes extends BaseAppNotes
* @see AppNotes->addCaseNote()
* @see AppNotes->postNewNote()
* @see workflow/engine/src/ProcessMaker/Util/helpers.php::postNote()
*/
public function sendNoteNotification ($appUid, $usrUid, $noteContent, $noteRecipients, $from = '', $delIndex = 0)
*/
public function sendNoteNotification($appUid, $usrUid, $noteContent, $noteRecipients, $from = '', $delIndex = 0)
{
try {
$configuration = System::getEmailConfiguration();
$msgError = "";
if (! isset( $configuration['MESS_ENABLED'] ) || $configuration['MESS_ENABLED'] != '1') {
if (!isset($configuration['MESS_ENABLED']) || $configuration['MESS_ENABLED'] != '1') {
$msgError = "The default configuration wasn't defined";
$configuration['MESS_ENGINE'] = '';
}
@@ -211,20 +211,27 @@ class AppNotes extends BaseAppNotes
$cases = new Cases();
$fieldCase = $cases->loadCase($appUid, $delIndex);
$configNoteNotification['subject'] = G::LoadTranslation('ID_MESSAGE_SUBJECT_NOTE_NOTIFICATION') . " @#APP_TITLE ";
//Define the body for the notification
$configNoteNotification['body'] = $this->getBodyCaseNote($authorName, $noteContent);
$body = nl2br(G::replaceDataField($configNoteNotification['body'], $fieldCase, 'mysql', false));
$attachFileLinks = $this->getAttachedFilesFromTheCaseNote($appUid);
if (!empty($attachFileLinks)) {
$body = $body . "<br>" . G::LoadTranslation('ID_ATTACHED_FILES') . ":&nbsp;" . implode("<br>", $attachFileLinks) . ".";
}
$users = new Users();
$recipientsArray = explode(",", $noteRecipients);
foreach ($recipientsArray as $recipientUid) {
$userInfo = $users->load($recipientUid);
$to = ((($userInfo['USR_FIRSTNAME'] != '') || ($userInfo['USR_LASTNAME'] != '')) ? $userInfo['USR_FIRSTNAME'] . ' ' . $userInfo['USR_LASTNAME'] . ' ' : '') . '<' . $userInfo['USR_EMAIL'] . '>';
$ifUserNameDefined = $userInfo['USR_FIRSTNAME'] != '' || $userInfo['USR_LASTNAME'] != '';
$to = ($ifUserNameDefined ? $userInfo['USR_FIRSTNAME'] . ' ' . $userInfo['USR_LASTNAME'] . ' ' : '') . '<' . $userInfo['USR_EMAIL'] . '>';
$spool = new SpoolRun();
$spool->setConfig($configuration);
$messageArray = AppMessage::buildMessageRow(
$parameters = [
'',
$appUid,
$delIndex,
@@ -244,7 +251,8 @@ class AppNotes extends BaseAppNotes
(isset($fieldCase['APP_NUMBER'])) ? $fieldCase['APP_NUMBER'] : 0,
(isset($fieldCase['PRO_ID'])) ? $fieldCase['PRO_ID'] : 0,
(isset($fieldCase['TAS_ID'])) ? $fieldCase['TAS_ID'] : 0
);
];
$messageArray = AppMessage::buildMessageRow(...$parameters);
$spool->create($messageArray);
if ($msgError == '') {
@@ -252,14 +260,29 @@ class AppNotes extends BaseAppNotes
$spool->sendMail();
}
}
}
//Send derivation notification - End
} catch (Exception $exception) {
throw $exception;
}
}
/**
* Get attached files from the case note, this require appUid.
* @param string $appUid
* @return array
*/
public function getAttachedFilesFromTheCaseNote(string $appUid): array
{
$attachFileLinks = [];
$url = System::getServerMainPath();
$result = Documents::getAttachedFilesFromTheCaseNote($appUid);
$result->each(function($item) use($url, &$attachFileLinks) {
$href = $url . "/cases/casesShowCaseNotes?a={$item->APP_DOC_UID}=&v={$item->DOC_VERSION}";
$attachFileLinks[] = "<a href='{$href}'>{$item->APP_DOC_FILENAME}</a>";
});
return $attachFileLinks;
}
public function addCaseNote($applicationUid, $userUid, $note, $sendMail)
{
$response = $this->postNewNote($applicationUid, $userUid, $note, false);