Standardize code: same code for message from public and backoffice

This commit is contained in:
Laurent Destailleur 2023-01-04 18:11:40 +01:00
parent c3b293fc45
commit 6c4809bcf5

View File

@ -2369,7 +2369,7 @@ class Ticket extends CommonObject
/** /**
* Add new message on a ticket (private/public area). * Add new message on a ticket (private/public area).
* Can also send it be email if GETPOST('send_email', 'int') is set. For such email, header and footer is added. * Can also send it by email if GETPOST('send_email', 'int') is set. For such email, header and footer is added.
* *
* @param User $user User for action * @param User $user User for action
* @param string $action Action string * @param string $action Action string
@ -2438,8 +2438,13 @@ class Ticket extends CommonObject
* Send emails to assigned users (public area notification) * Send emails to assigned users (public area notification)
*/ */
if (!empty($conf->global->TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_ENABLED)) { if (!empty($conf->global->TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_ENABLED)) {
// Retrieve internal contact datas
$internal_contacts = $object->getInfosTicketInternalContact();
$assigned_user_dont_have_email = ''; $assigned_user_dont_have_email = '';
$sendto = array(); $sendto = array();
if ($this->fk_user_assign > 0) { if ($this->fk_user_assign > 0) {
$assigned_user = new User($this->db); $assigned_user = new User($this->db);
$assigned_user->fetch($this->fk_user_assign); $assigned_user->fetch($this->fk_user_assign);
@ -2449,16 +2454,21 @@ class Ticket extends CommonObject
$assigned_user_dont_have_email = $assigned_user->getFullName($langs); $assigned_user_dont_have_email = $assigned_user->getFullName($langs);
} }
} }
if (!empty($conf->global->TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_ALSO_CONTRIBUTOR)) {
$contactList = $object->liste_contact(-1, 'internal', 0, 'CONTRIBUTOR'); // Build array to display recipient list
if (is_array($contactList)) { foreach ($internal_contacts as $key => $info_sendto) {
foreach ($contactList as $contactArray) { // Avoid duplicate notifications
if (!empty($contactArray['email'])) { if ($info_sendto['id'] == $user->id) {
$sendto[] = dolGetFirstLastname($contactArray['firstname'], $contactArray['lastname']) . " <" . $contactArray['email'] . ">"; continue;
} }
if ($info_sendto['email'] != '') {
if (!empty($info_sendto['email'])) {
$sendto[] = dolGetFirstLastname($info_sendto['firstname'], $info_sendto['lastname'])." <".$info_sendto['email'].">";
} }
} }
} }
if (empty($sendto)) { if (empty($sendto)) {
if (!empty($conf->global->TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_DEFAULT_EMAIL)) { if (!empty($conf->global->TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_DEFAULT_EMAIL)) {
$sendto[] = $conf->global->TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_DEFAULT_EMAIL; $sendto[] = $conf->global->TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_DEFAULT_EMAIL;