Beispiel #1
0
 function FormatEvent_Task2($arFields, $arParams, $bMail = false)
 {
     if ($bMail && strlen($arFields["MAIL_LANGUAGE_ID"]) > 0) {
         IncludeModuleLangFile(__FILE__, $arFields["MAIL_LANGUAGE_ID"]);
     }
     // Prevent module versions dependency between tasks and socialnetwork
     if (CModule::IncludeModule('tasks') && method_exists('CTaskNotifications', 'FormatTask4SocialNetwork')) {
         // Code moved out to tasks, use it
         if ($bMail && strlen($arFields["MAIL_LANGUAGE_ID"]) > 0) {
             IncludeModuleLangFile(__FILE__, LANGUAGE_ID);
         }
         return CTaskNotifications::FormatTask4SocialNetwork($arFields, $arParams, $bMail);
     }
     // Code wasn't moved out to tasks yet, use current function
     $GLOBALS['APPLICATION']->SetAdditionalCSS("/bitrix/js/tasks/css/tasks.css");
     $arFields["PARAMS"] = unserialize($arFields["~PARAMS"]);
     $arResult = array("EVENT" => $arFields, "CREATED_BY" => CSocNetLogTools::FormatEvent_GetCreatedBy($arFields, $arParams, $bMail), "ENTITY" => CSocNetLogTools::FormatEvent_GetEntity($arFields, $arParams, $bMail), "EVENT_FORMATTED" => array());
     if (!$bMail) {
         $arResult["AVATAR_SRC"] = CSocNetLogTools::FormatEvent_CreateAvatar($arFields, $arParams);
     }
     if (!$bMail && $arParams["MOBILE"] != "Y" && array_key_exists("URL", $arFields) && strlen($arFields["URL"]) > 0) {
         $task_tmp = '<a href="' . $arFields["URL"] . '" onclick="if (taskIFramePopup.isLeftClick(event)) {taskIFramePopup.view(' . $arFields["SOURCE_ID"] . '); return false;}">' . $arFields["TITLE"] . '</a>';
     } else {
         $task_tmp = $arFields["TITLE"];
     }
     $title_tmp = str_replace("#TITLE#", $task_tmp, GetMessage("SONET_GL_EVENT_TITLE_TASK"));
     if ($arFields["PARAMS"] && $arFields["PARAMS"]["CREATED_BY"]) {
         $suffix = is_array($GLOBALS["arExtranetUserID"]) && in_array($arFields["PARAMS"]["CREATED_BY"], $GLOBALS["arExtranetUserID"]) ? GetMessage("SONET_LOG_EXTRANET_SUFFIX") : "";
         $rsUser = CUser::GetByID(intval($arFields["PARAMS"]["CREATED_BY"]));
         if ($arUser = $rsUser->Fetch()) {
             $title_tmp .= " (" . str_replace("#USER_NAME#", CUser::FormatName(CSite::GetNameFormat(false), $arUser) . $suffix, GetMessage("SONET_GL_EVENT_TITLE_TASK_CREATED")) . ")";
         }
     }
     if ($bMail) {
         $title = str_replace(array("#TASK#", "#ENTITY#", "#CREATED_BY#"), array($title_tmp, $arResult["ENTITY"]["FORMATTED"], $bMail ? $arResult["CREATED_BY"]["FORMATTED"] : ""), GetMessage("SONET_GL_EVENT_TITLE_" . ($arFields["ENTITY_TYPE"] == SONET_SUBSCRIBE_ENTITY_GROUP ? "GROUP" : "USER") . "_TASK_MAIL"));
     } else {
         $title = $title_tmp;
         if (!is_array($arFields["PARAMS"]) || !array_key_exists("TYPE", $arFields["PARAMS"]) || strlen($arFields["PARAMS"]["TYPE"]) <= 0) {
             $arFields["PARAMS"]["TYPE"] = "DEFAULT";
         }
         switch ($arFields["CREATED_BY_PERSONAL_GENDER"]) {
             case "M":
                 $suffix = "_M";
                 break;
             case "F":
                 $suffix = "_F";
                 break;
             default:
                 $suffix = "";
         }
         $title_24 = str_replace("#TITLE#", $task_tmp, GetMessage("SONET_GL_EVENT_TITLE_TASK_" . strtoupper($arFields["PARAMS"]["TYPE"]) . "_24" . $suffix));
     }
     if (!$bMail && (in_array($arFields["PARAMS"]["TYPE"], array("create", "status")) || $arFields["PARAMS"]["TYPE"] == "modify" && is_array($arFields["PARAMS"]["CHANGED_FIELDS"])) && CModule::IncludeModule("tasks")) {
         $rsTask = CTasks::GetByID($arFields["SOURCE_ID"], false);
         if ($arTask = $rsTask->Fetch()) {
             $task_datetime = $arTask["CHANGED_DATE"];
             if ($arFields["PARAMS"]["TYPE"] == "create") {
                 if ($arParams["MOBILE"] == "Y") {
                     $title_24 = GetMessage("SONET_GL_TASKS2_NEW_TASK_MESSAGE");
                     $message_24_1 = $task_tmp;
                 } else {
                     $message = $message_24_1 = GetMessage("SONET_GL_TASKS2_NEW_TASK_MESSAGE");
                     $message_24_2 = $changes_24 = "";
                 }
             } elseif ($arFields["PARAMS"]["TYPE"] == "modify") {
                 $arChangesFields = $arFields["PARAMS"]["CHANGED_FIELDS"];
                 $changes_24 = implode(", ", CTaskNotifications::__Fields2Names($arChangesFields));
                 if ($arParams["MOBILE"] == "Y") {
                     $title_24 = GetMessage("SONET_GL_TASKS2_TASK_CHANGED_MESSAGE_24_1");
                     $message_24_1 = $task_tmp;
                 } else {
                     $message = str_replace("#CHANGES#", implode(", ", CTaskNotifications::__Fields2Names($arChangesFields)), GetMessage("SONET_GL_TASKS2_TASK_CHANGED_MESSAGE"));
                     $message_24_1 = GetMessage("SONET_GL_TASKS2_TASK_CHANGED_MESSAGE_24_1");
                     $message_24_2 = GetMessage("SONET_GL_TASKS2_TASK_CHANGED_MESSAGE_24_2");
                 }
             } elseif ($arFields["PARAMS"]["TYPE"] == "status") {
                 $message = GetMessage("SONET_GL_TASKS2_TASK_STATUS_MESSAGE_" . $arTask["STATUS"]);
                 $message_24_1 = GetMessage("SONET_GL_TASKS2_TASK_STATUS_MESSAGE_" . $arTask["STATUS"] . "_24");
                 if ($arTask["STATUS"] == 7) {
                     $message = str_replace("#TASK_DECLINE_REASON#", $arTask["DECLINE_REASON"], $message);
                     $message_24_2 = GetMessage("SONET_GL_TASKS2_TASK_STATUS_MESSAGE_" . $arTask["STATUS"] . "_24_2");
                     $changes_24 = $arTask["DECLINE_REASON"];
                 } elseif ($arTask["STATUS"] == 4) {
                     $message_24_2 = GetMessage("SONET_GL_TASKS2_TASK_STATUS_MESSAGE_" . $arTask["STATUS"] . "_24_2");
                     $changes_24 = GetMessage("SONET_GL_TASKS2_TASK_STATUS_MESSAGE_4_24_CHANGES");
                 } else {
                     $message_24_2 = $changes_24 = "";
                 }
             }
             ob_start();
             $GLOBALS['APPLICATION']->IncludeComponent("bitrix:tasks.task.livefeed", $arParams["MOBILE"] == "Y" ? 'mobile' : '', array("MOBILE" => $arParams["MOBILE"] == "Y" ? "Y" : "N", "TASK" => $arTask, "MESSAGE" => $message, "MESSAGE_24_1" => $message_24_1, "MESSAGE_24_2" => $message_24_2, "CHANGES_24" => $changes_24, "NAME_TEMPLATE" => $arParams["NAME_TEMPLATE"], "PATH_TO_USER" => $arParams["PATH_TO_USER"]), null, array("HIDE_ICONS" => "Y"));
             $arFields["MESSAGE"] = ob_get_contents();
             ob_end_clean();
         }
     }
     if ($arParams["MOBILE"] == "Y") {
         $arResult["EVENT_FORMATTED"] = array("TITLE" => $title, "TITLE_24" => $title_24, "MESSAGE" => htmlspecialcharsbx($arFields["MESSAGE"]), "DESCRIPTION" => $message_24_1, "DESCRIPTION_STYLE" => "task");
     } else {
         $arResult["EVENT_FORMATTED"] = array("TITLE" => $title, "TITLE_24" => $title_24, "MESSAGE" => $bMail ? str_replace(array("<nobr>", "</nobr>"), array("", ""), $arFields["TEXT_MESSAGE"]) : $arFields["MESSAGE"], "SHORT_MESSAGE" => $bMail ? str_replace(array("<nobr>", "</nobr>"), array("", ""), $arFields["TEXT_MESSAGE"]) : $arFields["~MESSAGE"], "IS_MESSAGE_SHORT" => true, "STYLE" => "tasks-info");
         if (!$bMail && strlen($task_datetime) > 0) {
             $arResult["EVENT_FORMATTED"]["LOG_DATE_FORMAT"] = $task_datetime;
         }
     }
     if ($bMail) {
         $url = CSocNetLogTools::FormatEvent_GetURL($arFields);
         if (strlen($url) > 0) {
             $arResult["EVENT_FORMATTED"]["URL"] = $url;
         }
     } elseif ($arFields["ENTITY_TYPE"] == SONET_SUBSCRIBE_ENTITY_GROUP) {
         $arResult["EVENT_FORMATTED"]["DESTINATION"] = array(array("STYLE" => "sonetgroups", "TITLE" => $arResult["ENTITY"]["FORMATTED"]["NAME"], "URL" => $arResult["ENTITY"]["FORMATTED"]["URL"], "IS_EXTRANET" => is_array($GLOBALS["arExtranetGroupID"]) && in_array($arFields["ENTITY_ID"], $GLOBALS["arExtranetGroupID"])));
     }
     if ($bMail && strlen($arFields["MAIL_LANGUAGE_ID"]) > 0) {
         IncludeModuleLangFile(__FILE__, LANGUAGE_ID);
     }
     return $arResult;
 }
 public static function FormatTask4SocialNetwork($arFields, $arParams, $bMail = false)
 {
     /** @global CMain $APPLICATION */
     global $APPLICATION;
     $task_datetime = null;
     if (!CModule::IncludeModule('socialnetwork')) {
         return false;
     }
     $APPLICATION->SetAdditionalCSS('/bitrix/js/tasks/css/tasks.css');
     if (isset($arFields['~PARAMS']) && $arFields['~PARAMS']) {
         $arFields['PARAMS'] = unserialize($arFields['~PARAMS']);
     } elseif (isset($arFields['PARAMS']) && $arFields['PARAMS']) {
         $arFields['PARAMS'] = unserialize($arFields['PARAMS']);
     } else {
         $arFields['PARAMS'] = array();
     }
     $arResult = array('EVENT' => $arFields, 'CREATED_BY' => CSocNetLogTools::FormatEvent_GetCreatedBy($arFields, $arParams, $bMail), 'ENTITY' => CSocNetLogTools::FormatEvent_GetEntity($arFields, $arParams, $bMail), 'EVENT_FORMATTED' => array(), 'CACHED_CSS_PATH' => '/bitrix/js/tasks/css/tasks.css');
     if (!$bMail) {
         $arResult["AVATAR_SRC"] = CSocNetLogTools::FormatEvent_CreateAvatar($arFields, $arParams);
     }
     if (!$bMail && $arParams["MOBILE"] != "Y" && array_key_exists("URL", $arFields) && strlen($arFields["URL"]) > 0) {
         $taskHtmlTitle = '<a href="' . $arFields["URL"] . '" onclick="if (taskIFramePopup.isLeftClick(event)) {taskIFramePopup.view(' . $arFields["SOURCE_ID"] . '); return false;}">' . $arFields["TITLE"] . '</a>';
     } else {
         $taskHtmlTitle = $arFields["TITLE"];
     }
     $actorUserId = null;
     $actorUserName = '';
     $actorMaleSuffix = '';
     $eventTitlePhraseSuffix = '_DEFAULT';
     if (isset($arParams['NAME_TEMPLATE'])) {
         $nameTemplate = $arParams['NAME_TEMPLATE'];
     } else {
         $nameTemplate = CSite::GetNameFormat();
     }
     if (isset($arFields["PARAMS"], $arFields['PARAMS']['TYPE'])) {
         if ($arFields["PARAMS"]["TYPE"] === "create") {
             $eventTitlePhraseSuffix = '_CREATE_24';
             if (isset($arFields["PARAMS"]["CREATED_BY"])) {
                 $actorUserId = $arFields["PARAMS"]["CREATED_BY"];
             }
         } elseif ($arFields["PARAMS"]["TYPE"] === 'modify') {
             $eventTitlePhraseSuffix = '_MODIFY_24';
             if (isset($arFields["PARAMS"]["CHANGED_BY"])) {
                 $actorUserId = $arFields["PARAMS"]["CHANGED_BY"];
             }
         } elseif ($arFields["PARAMS"]["TYPE"] === 'status') {
             $eventTitlePhraseSuffix = '_STATUS_24';
             if (isset($arFields["PARAMS"]["CHANGED_BY"])) {
                 $actorUserId = $arFields["PARAMS"]["CHANGED_BY"];
             }
         } elseif ($arFields["PARAMS"]["TYPE"] === 'comment') {
             $eventTitlePhraseSuffix = '';
         }
     }
     if ($actorUserId) {
         $rsUser = CUser::GetList($by = 'id', $order = 'asc', array('ID_EQUAL_EXACT' => (int) $actorUserId), array('FIELDS' => array('ID', 'NAME', 'LAST_NAME', 'SECOND_NAME', 'LOGIN', 'PERSONAL_GENDER')));
         if ($arUser = $rsUser->fetch()) {
             if (isset($arUser['PERSONAL_GENDER'])) {
                 switch ($arUser['PERSONAL_GENDER']) {
                     case "F":
                     case "M":
                         $actorMaleSuffix = '_' . $arUser['PERSONAL_GENDER'];
                         break;
                 }
             }
             $actorUserName = CUser::FormatName($nameTemplate, $arUser);
         }
     }
     $eventTitleTemplate = GetMessage('TASKS_SONET_GL_EVENT_TITLE_TASK' . $eventTitlePhraseSuffix . $actorMaleSuffix);
     $eventTitle = str_replace(array('#USER_NAME#', '#TITLE#'), array($actorUserName, $taskHtmlTitle), $eventTitleTemplate);
     $eventTitleWoTaskName = str_replace(array('#USER_NAME#', '#TITLE#'), array($actorUserName, ''), $eventTitleTemplate);
     $title_tmp = str_replace("#TITLE#", $taskHtmlTitle, GetMessage("TASKS_SONET_GL_EVENT_TITLE_TASK"));
     if ($arFields["PARAMS"] && $arFields["PARAMS"]["CREATED_BY"]) {
         $suffix = is_array($GLOBALS["arExtranetUserID"]) && in_array($arFields["PARAMS"]["CREATED_BY"], $GLOBALS["arExtranetUserID"]) ? GetMessage("TASKS_SONET_LOG_EXTRANET_SUFFIX") : "";
         $rsUser = CUser::GetList($by = 'id', $order = 'asc', array('ID_EQUAL_EXACT' => (int) $arFields['PARAMS']['CREATED_BY']), array('FIELDS' => array('PERSONAL_GENDER', 'ID', 'NAME', 'LAST_NAME', 'SECOND_NAME', 'LOGIN')));
         if ($arUser = $rsUser->Fetch()) {
             $title_tmp .= " (" . str_replace("#USER_NAME#", CUser::FormatName(CSite::GetNameFormat(false), $arUser) . $suffix, GetMessage("TASKS_SONET_GL_EVENT_TITLE_TASK_CREATED")) . ")";
         }
     }
     if ($bMail) {
         $title = str_replace(array("#TASK#", "#ENTITY#", "#CREATED_BY#"), array($title_tmp, $arResult["ENTITY"]["FORMATTED"], $bMail ? $arResult["CREATED_BY"]["FORMATTED"] : ""), GetMessage("SONET_GL_EVENT_TITLE_" . ($arFields["ENTITY_TYPE"] == SONET_SUBSCRIBE_ENTITY_GROUP ? "GROUP" : "USER") . "_TASK_MAIL"));
     } else {
         $title = $title_tmp;
         $title_24 = $eventTitle;
     }
     if (!$bMail && in_array($arFields["PARAMS"]["TYPE"], array("create", "status", 'modify', 'comment'), true)) {
         if (!(isset($arFields['PARAMS']['CHANGED_FIELDS']) && is_array($arFields['PARAMS']['CHANGED_FIELDS']))) {
             $arFields['PARAMS']['CHANGED_FIELDS'] = array();
         }
         $rsTask = CTasks::GetByID($arFields["SOURCE_ID"], false);
         if ($arTask = $rsTask->Fetch()) {
             $task_datetime = $arTask["CHANGED_DATE"];
             if ($arFields["PARAMS"]["TYPE"] == "create") {
                 if ($arParams["MOBILE"] == "Y") {
                     $title_24 = GetMessage("TASKS_SONET_GL_TASKS2_NEW_TASK_MESSAGE");
                     $message_24_1 = $taskHtmlTitle;
                 } else {
                     $message = $message_24_1 = $eventTitle;
                     $message_24_2 = $changes_24 = "";
                 }
             } elseif ($arFields["PARAMS"]["TYPE"] == "modify") {
                 $arChangesFields = $arFields["PARAMS"]["CHANGED_FIELDS"];
                 $changes_24 = implode(", ", CTaskNotifications::__Fields2Names($arChangesFields));
                 if ($arParams["MOBILE"] == "Y") {
                     $title_24 = GetMessage("TASKS_SONET_GL_TASKS2_TASK_CHANGED_MESSAGE_24_1");
                     $message_24_1 = $taskHtmlTitle;
                 } else {
                     $message = str_replace("#CHANGES#", implode(", ", CTaskNotifications::__Fields2Names($arChangesFields)), GetMessage("TASKS_SONET_GL_TASKS2_TASK_CHANGED_MESSAGE"));
                     $message_24_1 = $eventTitle;
                     $message_24_2 = GetMessage("TASKS_SONET_GL_TASKS2_TASK_CHANGED_MESSAGE_24_2");
                 }
             } elseif ($arFields["PARAMS"]["TYPE"] == "status") {
                 $message = GetMessage("TASKS_SONET_GL_TASKS2_TASK_STATUS_MESSAGE_" . $arTask["STATUS"]);
                 $message_24_1 = $eventTitle;
                 if ($arTask["STATUS"] == CTasks::STATE_DECLINED) {
                     $message = str_replace("#TASK_DECLINE_REASON#", $arTask["DECLINE_REASON"], $message);
                     $message_24_2 = GetMessage("TASKS_SONET_GL_TASKS2_TASK_STATUS_MESSAGE_" . $arTask["STATUS"] . "_24_2");
                     $changes_24 = $arTask["DECLINE_REASON"];
                 } else {
                     $message_24_2 = $changes_24 = $message;
                 }
             } elseif ($arFields['PARAMS']['TYPE'] === 'comment') {
                 $message_24_1 = $eventTitle;
                 $message_24_2 = $changes_24 = $message = '';
             }
             $prevRealStatus = false;
             if (isset($arFields['PARAMS']['PREV_REAL_STATUS'])) {
                 $prevRealStatus = $arFields['PARAMS']['PREV_REAL_STATUS'];
             }
             ob_start();
             $GLOBALS['APPLICATION']->IncludeComponent("bitrix:tasks.task.livefeed", $arParams["MOBILE"] == "Y" ? 'mobile' : '', array("MOBILE" => $arParams["MOBILE"] == "Y" ? "Y" : "N", "TASK" => $arTask, "MESSAGE" => $message, "MESSAGE_24_1" => $message_24_1, "MESSAGE_24_2" => $message_24_2, "CHANGES_24" => $changes_24, "NAME_TEMPLATE" => $arParams["NAME_TEMPLATE"], "PATH_TO_USER" => $arParams["PATH_TO_USER"], 'TYPE' => $arFields["PARAMS"]["TYPE"], 'task_tmp' => $taskHtmlTitle, 'taskHtmlTitle' => $taskHtmlTitle, 'PREV_REAL_STATUS' => $prevRealStatus), null, array("HIDE_ICONS" => "Y"));
             $arFields["MESSAGE"] = ob_get_contents();
             ob_end_clean();
         }
     }
     if ($arParams["MOBILE"] == "Y") {
         $arResult["EVENT_FORMATTED"] = array("TITLE" => '', "TITLE_24" => $eventTitleWoTaskName, "MESSAGE" => htmlspecialcharsbx($arFields['MESSAGE']), "DESCRIPTION" => $arFields['TITLE'], "DESCRIPTION_STYLE" => 'task');
     } else {
         $strMessage = $strShortMessage = '';
         if ($bMail) {
             $strMessage = $strShortMessage = str_replace(array('<nobr>', '</nobr>'), array('', ''), $arFields['TEXT_MESSAGE']);
         } else {
             $strMessage = $arFields['MESSAGE'];
             $strShortMessage = $arFields['~MESSAGE'];
         }
         $arResult["EVENT_FORMATTED"] = array("TITLE" => $title, "MESSAGE" => $strMessage, "SHORT_MESSAGE" => $strShortMessage, "IS_MESSAGE_SHORT" => true, "STYLE" => 'tasks-info', "COMMENT_URL" => !$bMail ? $arFields['~URL'] . (strpos($arFields['~URL'], '?') > 0 ? '&' : '?') . 'MID=#ID##com#ID#' : '');
     }
     if ($bMail) {
         $url = CSocNetLogTools::FormatEvent_GetURL($arFields);
         if (strlen($url) > 0) {
             $arResult["EVENT_FORMATTED"]["URL"] = $url;
         }
     } elseif ($arFields["ENTITY_TYPE"] == SONET_SUBSCRIBE_ENTITY_GROUP) {
         $arResult["EVENT_FORMATTED"]["DESTINATION"] = array(array("STYLE" => "sonetgroups", "TITLE" => $arResult["ENTITY"]["FORMATTED"]["NAME"], "URL" => $arResult["ENTITY"]["FORMATTED"]["URL"], "IS_EXTRANET" => is_array($GLOBALS["arExtranetGroupID"]) && in_array($arFields["ENTITY_ID"], $GLOBALS["arExtranetGroupID"])));
     }
     if (!$bMail && strlen($task_datetime) > 0) {
         $arResult["EVENT_FORMATTED"]["LOG_DATE_FORMAT"] = $task_datetime;
     }
     return $arResult;
 }