Пример #1
0
 /**
  * @param string $sPath
  * @param \MailSo\Mime\Message $oMessage Message object
  * @param CHelpdeskUser $oHelpdeskThreadOwnerUser Helpdesk user object
  * @param CHelpdeskUser $oHelpdeskPostOwnerUser Helpdesk user object
  * @param CHelpdeskThread $oThread Helpdesk thread object
  * @param CHelpdeskPost $oPost Helpdesk post object
  * @param string $sSiteName
  */
 private function _addHtmlBodyAndSubjectForPostMessage($sPath, &$oMessage, $oHelpdeskThreadOwnerUser, $oHelpdeskPostOwnerUser, $oThread, $oPost, $sSiteName)
 {
     $sSubject = '';
     $oApiUsers = $this->_getApiUsers();
     $sData = $this->_getMessageTemplate($sPath, $sSubject, function ($sData) use($oHelpdeskThreadOwnerUser, $oHelpdeskPostOwnerUser, $oThread, $oPost, $sSiteName, $oApiUsers) {
         $oAccount = $oApiUsers->getAccountByEmail($oHelpdeskPostOwnerUser->resultEmail());
         $sPostOwner = \MailSo\Mime\Email::NewInstance($oHelpdeskPostOwnerUser->resultEmail(), $oHelpdeskPostOwnerUser->Name)->ToString();
         $sSubjectPrefix = '';
         if ($oThread && 0 < $oThread->PostCount - 1) {
             $sSubjectPrefix = 'Re' . (2 < $oThread->PostCount ? '[' . ($oThread->PostCount - 1) . ']' : '') . ': ';
         }
         $sAttachments = '';
         if ($oPost && is_array($oPost->Attachments) && 0 < count($oPost->Attachments)) {
             $sAttachmentsNames = array();
             foreach ($oPost->Attachments as $oAttachment) {
                 if ($oAttachment) {
                     $sAttachmentsNames[] = $oAttachment->FileName;
                 }
             }
             $sAttachments = '<br /><br />Attachments: ' . implode(', ', $sAttachmentsNames) . '<br />';
         }
         $sHelpdeskSiteName = strlen($sSiteName) === 0 ? 'Helpdesk' : $sSiteName;
         $sThreadOwner = $oHelpdeskThreadOwnerUser && \strlen($oHelpdeskThreadOwnerUser->Name) > 0 ? ' ' . $oHelpdeskThreadOwnerUser->Name : '';
         return strtr($sData, array('{{HELPDESK/POST_AGENT_SUBJECT}}' => ':SUBJECT: ' . \CApi::ClientI18N('HELPDESK/MAIL_POST_AGENT_SUBJECT', null, array("OWNER" => $sPostOwner)), '{{HELPDESK/POST_AGENT_HTML}}' => $oPost ? \MailSo\Base\HtmlUtils::ConvertPlainToHtml($oPost->Text) : '', '{{HELPDESK/POST_AGENT_ATTACHMENTS}}' => $sAttachments, '{{HELPDESK/POST_AGENT_THREAD_LINK}}' => $oThread->threadLink(), '{{HELPDESK/POST_USER_SUBJECT}}' => $sSubjectPrefix . $oThread->Subject, '{{HELPDESK/POST_USER_GREET}}' => \CApi::ClientI18N('HELPDESK/MAIL_POST_USER_GREET', null, array("OWNER" => $sPostOwner)), '{{HELPDESK/POST_USER_REMIND}}' => \CApi::ClientI18N('HELPDESK/MAIL_POST_USER_REMIND', null, array("SITE" => $sHelpdeskSiteName)), '{{HELPDESK/POST_USER_THREAD_SUBJECT_LABEL}}' => \CApi::ClientI18N('HELPDESK/MAIL_POST_USER_THREAD_SUBJECT_LABEL'), '{{HELPDESK/POST_USER_THREAD_SUBJECT}}' => $oThread->Subject, '{{HELPDESK/POST_USER_HTML}}' => $oPost ? \MailSo\Base\HtmlUtils::ConvertPlainToHtml($oPost->Text) : '', '{{HELPDESK/POST_USER_NOT_REPLY}}' => \CApi::ClientI18N('HELPDESK/MAIL_POST_USER_NOT_REPLY'), '{{HELPDESK/POST_USER_CLICK_LINK}}' => \CApi::ClientI18N('HELPDESK/MAIL_POST_USER_CLICK_LINK'), '{{HELPDESK/POST_USER_THREAD_LINK}}' => $oThread->threadLink(), '{{HELPDESK/POST_NEW_SUBJECT}}' => ':SUBJECT: ' . \CApi::ClientI18N('HELPDESK/MAIL_POST_NEW_SUBJECT'), '{{HELPDESK/POST_NEW_GREET}}' => \CApi::ClientI18N('HELPDESK/MAIL_POST_NEW_GREET', null, array("OWNER" => $sThreadOwner)), '{{HELPDESK/POST_NEW_REMIND}}' => \CApi::ClientI18N('HELPDESK/MAIL_POST_NEW_REMIND', null, array("SITE" => $sHelpdeskSiteName)), '{{HELPDESK/POST_NEW_HTML}}' => $oPost ? \MailSo\Base\HtmlUtils::ConvertPlainToHtml($oPost->Text) : '', '{{HELPDESK/POST_NEW_NOT_REPLY}}' => \CApi::ClientI18N('HELPDESK/MAIL_POST_NEW_NOT_REPLY'), '{{HELPDESK/POST_NEW_CLICK_LINK}}' => \CApi::ClientI18N('HELPDESK/MAIL_POST_NEW_CLICK_LINK'), '{{HELPDESK/POST_NEW_THREAD_LINK}}' => $oThread->threadLink(), '{{HELPDESK/POST_NOTIFICATION_SUBJECT}}' => ':SUBJECT: ' . \CApi::ClientI18N('HELPDESK/MAIL_POST_NOTIFICATION_SUBJECT'), '{{HELPDESK/POST_NOTIFICATION_GREET}}' => \CApi::ClientI18N('HELPDESK/MAIL_POST_NOTIFICATION_GREET', null, array("OWNER" => $sThreadOwner)), '{{HELPDESK/POST_NOTIFICATION_REMIND}}' => \CApi::ClientI18N('HELPDESK/MAIL_POST_NOTIFICATION_REMIND', null, array("SITE" => $sHelpdeskSiteName)), '{{HELPDESK/POST_NOTIFICATION_QUESTIONS}}' => \CApi::ClientI18N('HELPDESK/MAIL_POST_NOTIFICATION_QUESTIONS'), '{{HELPDESK/POST_NOTIFICATION_CLOSE}}' => \CApi::ClientI18N('HELPDESK/MAIL_POST_NOTIFICATION_CLOSE'), '{{HELPDESK/POST_NOTIFICATION_NOT_REPLY}}' => \CApi::ClientI18N('HELPDESK/MAIL_POST_NOTIFICATION_NOT_REPLY'), '{{HELPDESK/POST_NOTIFICATION_CLICK_LINK}}' => \CApi::ClientI18N('HELPDESK/MAIL_POST_NOTIFICATION_CLICK_LINK'), '{{HELPDESK/POST_NOTIFICATION_THREAD_LINK}}' => $oThread->threadLink()));
     });
     if (0 < strlen($sSubject)) {
         $oMessage->SetSubject($sSubject . ' [#' . $oThread->StrHelpdeskThreadHash . '#]');
     }
     if (is_string($sData) && 0 < strlen($sData)) {
         $oMessage->AddText(\MailSo\Base\HtmlUtils::ConvertHtmlToPlain($sData), false);
         $oMessage->AddHtml($sData, true);
     }
 }