21 if (! Loader::includeModule(
'intranet'))
25 return parent::processBeforeAction($action);
36 'createChatFromMessage' => [
38 new \Bitrix\Main\Engine\ActionFilter\HttpMethod([
'POST']),
39 new \Bitrix\Main\Engine\ActionFilter\Csrf(),
44 new \Bitrix\Main\Engine\ActionFilter\HttpMethod([
'POST']),
45 new \Bitrix\Main\Engine\ActionFilter\Csrf(),
48 'getCalendarEventDataFromMessage' => [
50 new \Bitrix\Main\Engine\ActionFilter\HttpMethod([
'POST']),
51 new \Bitrix\Main\Engine\ActionFilter\Csrf(),
56 if (Loader::includeModule(
'intranet'))
58 $config[
'createChatFromMessage'][
'+prefilters'][] = new \Bitrix\Intranet\ActionFilter\IntranetUser();
59 $config[
'onCalendarSave'][
'+prefilters'][] = new \Bitrix\Intranet\ActionFilter\IntranetUser();
60 $config[
'getCalendarEventDataFromMessage'][
'+prefilters'][] = new \Bitrix\Intranet\ActionFilter\IntranetUser();
75 if (!Loader::includeModule(
'im'))
81 $userId = $USER->GetID();
83 if (!$this->canBindEntities($messageId, (
int)$userId))
89 $message = \Bitrix\Mail\Integration\Intranet\Secretary::getMessage($messageId);
90 $messageData = $message->toArray();
91 $messageData[
'USER_IDS'] = [$USER->GetID()];
93 if ($chatId = \
Bitrix\Intranet\Secretary::getChatIdIfExists($messageId,
'MAIL'))
96 if (! \
Bitrix\Intranet\Secretary::isUserInChat($chatId, $userId))
98 \Bitrix\Intranet\Secretary::addUserToChat($chatId, $userId,
false);
105 $lockName =
"chat_create_mail_{$messageId}";
109 Loc::getMessage(
'MAIL_SECRETARY_CREATE_CHAT_LOCK_ERROR'),
'lock_error')
114 $chatId = \Bitrix\Intranet\Secretary::createMailChat($messageData, $userId);
119 if (Loader::includeModule(
'pull'))
121 $mailboxId = \Bitrix\Mail\Integration\Intranet\Secretary::getMailboxIdForMessage($messageId);
125 \CPullWatch::addToStack(
126 'mail_mailbox_' . $mailboxId,
128 'module_id' =>
'mail',
129 'command' =>
'messageBindingCreated',
131 'messageId' => $messageId,
132 'mailboxId' => $mailboxId,
134 'entityId' => $chatId,
135 'bindingEntityLink' =>
136 \CComponentEngine::makePathFromTemplate(
137 '/online/?IM_DIALOG=chat#chat_id#',
139 'chat_id' => $chatId,
153 if ($this->provideAccessToMessage($messageId, $calendarEventId))
155 if ($this->postCalendarBackLinkComment($messageId, $calendarEventId))
157 $this->assignCreatedCalendarLabelToMessage($messageId, $calendarEventId);
166 $this->
addError(
new Error(
'secretary: grant access to message failed'));
178 private function assignCreatedCalendarLabelToMessage(
int $messageId,
int $calendarEventId): bool
180 if (Loader::includeModule(
'pull'))
182 $mailboxId = \Bitrix\Mail\Integration\Intranet\Secretary::getMailboxIdForMessage($messageId);
188 $userPage = \Bitrix\Main\Config\Option::get(
'socialnetwork',
'user_page',
'/company/personal/', SITE_ID);
190 \CPullWatch::addToStack(
191 'mail_mailbox_' . $mailboxId,
193 'module_id' =>
'mail',
194 'command' =>
'messageBindingCreated',
196 'messageId' => $messageId,
197 'mailboxId' => $mailboxId,
199 'entityId' => $calendarEventId,
200 'bindingEntityLink' =>
201 \CComponentEngine::makePathFromTemplate(
202 $userPage .
'user/#user_id#/calendar/?EVENT_ID=#event_id#',
204 'user_id' => $USER->getId(),
205 'event_id' => $calendarEventId,
226 private function provideAccessToMessage(
int $messageId,
int $calendarEventId): bool
229 $userId = $USER->GetID();
231 return \Bitrix\Mail\Integration\Intranet\Secretary::provideAccessToMessage(
247 private function postCalendarBackLinkComment(
int $messageId,
int $calendarEventId): bool
249 if (! Loader::includeModule(
'calendar'))
255 if (! Loader::includeModule(
'forum'))
264 $xmlId =
'EVENT_' . $calendarEventId;
266 $calendarEntry = \CCalendarEvent::getEventForViewInterface($calendarEventId, [
271 if (!$this->canBindEntities($messageId, $userId))
277 if (! isset($calendarEntry[
'CREATED_BY']) || (
int)$calendarEntry[
'CREATED_BY'] !== $userId)
285 $xmlId = \CCalendarEvent::getEventCommentXmlId($calendarEntry);
290 'id' => $calendarEventId,
294 $forumId = self::getForumId(array_merge($feedParams, [
295 'SITE_ID' => SITE_ID,
304 $feed = new \Bitrix\Forum\Comments\Feed(
310 $link = \Bitrix\Mail\Integration\Intranet\Secretary::getMessageUrlForCalendarEvent($messageId, $calendarEventId);
311 $commentMessage =
Loc::getMessage(
'MAIL_SECRETARY_POST_MESSAGE_CALENDAR_EVENT', [
315 $forumMessageFields = [
316 'POST_MESSAGE' => $commentMessage,
318 $forumComment = $feed->add($forumMessageFields);
346 if (! Loader::includeModule(
'intranet'))
353 if (!$this->canBindEntities($messageId, (
int)$USER->getId()))
359 $message = \Bitrix\Mail\Integration\Intranet\Secretary::getMessage($messageId);
360 $address = new \Bitrix\Main\Mail\Address($message->getFrom());
362 '#SUBJECT#' => htmlspecialcharsbx($message->getSubject()),
363 '#FROM#' => htmlspecialcharsbx($message->getFrom()),
364 '#DATE#' => $message->getDate()->toString(),
365 '#LINK_FROM#' =>
'mailto:' . htmlspecialcharsbx($address->getEmail()),
366 '#LINK#' => \
Bitrix\
Mail\Integration\Intranet\Secretary::getDirectMessageUrl($message->getId()),
372 'name' => htmlspecialcharsbx($message->getSubject()),
375 'isNewEvent' => !$isIcal,
381 private static function getForumId($params = [])
386 isset($params[
'SITE_ID'])
387 && $params[
'SITE_ID'] <>
''
392 if (isset($params[
'type']))
394 if ($params[
'type'] ===
'TK')
396 $result = Option::get(
'tasks',
'task_forum_id', 0, $siteId);
400 && Loader::includeModule(
'forum')
403 $res = ForumTable::getList([
405 '=XML_ID' =>
'intranet_tasks',
407 'select' => [
'ID' ],
409 if ($forumFields = $res->fetch())
411 $result = (int)$forumFields[
'ID'];
415 elseif ($params[
'type'] ===
'WF')
417 $result = Option::get(
'bizproc',
'forum_id', 0, $siteId);
419 if ((
int)$result <= 0)
421 $res = ForumTable::getList([
423 '=XML_ID' =>
'bizproc_workflow',
425 'select' => [
'ID' ],
427 if ($forumFields = $res->fetch())
429 $result = (int)$forumFields[
'ID'];
433 elseif (in_array($params[
'type'], [
'TM',
'TR' ]))
435 $result = Option::get(
'timeman',
'report_forum_id', 0, $siteId);
438 $params[
'type'] ===
'EV'
439 && Loader::includeModule(
'calendar')
442 $calendarSettings = \CCalendar::getSettings();
443 $result = $calendarSettings[
"forum_id"];
446 $params[
'type'] ===
'PH'
447 && Loader::includeModule(
'forum')
450 $res = ForumTable::getList(array(
452 '=XML_ID' =>
'PHOTOGALLERY_COMMENTS'
454 'select' => array(
'ID')
456 if ($forumFields = $res->fetch())
458 $result = (int)$forumFields[
'ID'];
461 elseif ($params[
'type'] ===
'IBLOCK')
463 $result = Option::get(
'wiki',
'socnet_forum_id', 0, $siteId);
467 $res = ForumTable::getList(array(
469 '=XML_ID' =>
'USERS_AND_GROUPS'
471 'select' => array(
'ID')
473 if ($forumFields = $res->fetch())
475 $result = (int)$forumFields[
'ID'];
490 private function canBindEntities(
int $messageId,
int $userId): bool
492 return \Bitrix\Mail\MessageAccess::createByMessageId($messageId, $userId)->canModifyMessage();
static getConnection($name="")
static getMessage($code, $replace=null, $language=null)