• Модуль: mail
  • Путь к файлу: ~/bitrix/modules/mail/lib/controller/secretary.php
  • Класс: BitrixMailControllerSecretary
  • Вызов: Secretary::postCalendarBackLinkComment
private function postCalendarBackLinkComment(int $messageId, int $calendarEventId): bool
{
	if (! Loader::includeModule('calendar'))
	{
		$this->addError(new Error('module calendar unloaded'));
		return false;
	}

	if (! Loader::includeModule('forum'))
	{
		$this->addError(new Error('module forum unloaded'));
		return false;
	}

	global $USER;
	$userId = (int)$USER->GetID();

	$xmlId = 'EVENT_' . $calendarEventId;

	$calendarEntry = CCalendarEvent::getEventForViewInterface($calendarEventId, [
		'eventDate' => '',
		'userId' => $userId,
	]);

	if (!$this->canBindEntities($messageId, $userId))
	{
		$this->addError(new Error(Loc::getMessage('MAIL_SECRETARY_ACCESS_DENIED')));
		return false;
	}

	if (! isset($calendarEntry['CREATED_BY']) || (int)$calendarEntry['CREATED_BY'] !== $userId)
	{
		$this->addError(new Error(Loc::getMessage('MAIL_SECRETARY_ACCESS_DENIED_CALENDAR')));
		return false;
	}

	if ($calendarEntry)
	{
		$xmlId = CCalendarEvent::getEventCommentXmlId($calendarEntry);
	}

	$feedParams = [
		'type' => 'EV', // BitrixSocialnetworkLivefeedForumPost::getForumTypeMap()
		'id' => $calendarEventId,
		'xml_id' => $xmlId,
	];

	$forumId = self::getForumId(array_merge($feedParams, [
		'SITE_ID' => SITE_ID,
	]));

	if (!$forumId)
	{
		$this->addError(new Error('forum id error'));
		return false;
	}

	$feed = new BitrixForumCommentsFeed(
		$forumId,
		$feedParams,
		$userId
	);

	$link = BitrixMailIntegrationIntranetSecretary::getMessageUrlForCalendarEvent($messageId, $calendarEventId);
	$commentMessage = Loc::getMessage('MAIL_SECRETARY_POST_MESSAGE_CALENDAR_EVENT', [
		'#LINK#' => $link,
	]);

	$forumMessageFields = [
		'POST_MESSAGE' => $commentMessage,
	];
	$forumComment = $feed->add($forumMessageFields);

	if (!$forumComment)
	{
		$this->addError(new Error('forum comment error'));
		return false;
	}

	// TODO post to social network feed
	// if (! Loader::includeModule('socialnetwork'))
	// {
	// 	$this->addError(new Error('module socialnetwork unloaded'));
	// 	return null;
	// }

	return true;
}