• Модуль: intranet
  • Путь к файлу: ~/bitrix/modules/intranet/classes/general/event_calendar.php
  • Класс: CEventCalendar
  • Вызов: CEventCalendar::SendRemindAgent
static function SendRemindAgent($iblockId, $eventId, $userId, $pathToPage, $ownerType, $ownerId)
{
	if (!CModule::IncludeModule("iblock"))
		return;
	if (!CModule::IncludeModule("socialnetwork"))
		return;

	if (!isset($GLOBALS["USER"]) || !is_object($GLOBALS["USER"]))
	{
		$bTmpUser = True;
		$GLOBALS["USER"] = new CUser;
	}

	$rsEvent = CIBlockElement::GetList(
		array(),
		array(
			"IBLOCK_ID" => $iblockId,
			"ACTIVE" => "Y",
			"ID" => $eventId,
			"CHECK_PERMISSIONS" => "N",
		),
		false,
		false,
		array("ID", "ACTIVE_FROM", "NAME", "IBLOCK_ID", "CREATED_BY", "IBLOCK_SECTION_ID")
	);
	if ($arEvent = $rsEvent->Fetch())
	{
		$MESS = GetMessage('EC_EVENT_REMINDER', Array('#EVENT_NAME#' => $arEvent["NAME"], '#DATE_FROM#' => $arEvent["ACTIVE_FROM"]));
		// Get Calendar Info:
		$rsCalendar = CIBlockSection::GetList(array('ID' => 'ASC'),
			array(
				"ID" => $arEvent['IBLOCK_SECTION_ID'],
				"IBLOCK_ID" => $iblockId,
				"ACTIVE" => "Y",
				"CHECK_PERMISSIONS" => "N"
			)
		);
		if (!$arCalendar = $rsCalendar->Fetch())
			return false;
		$calendarName = $arCalendar['NAME'];

		if ($ownerType == 'USER' && $ownerId == $userId)
		{
			$MESS .= ' '.GetMessage('EC_EVENT_REMINDER_IN_PERSONAL', Array('#CALENDAR_NAME#' => $calendarName));
		}
		else if($ownerType == 'USER')
		{
			// Get user name
			$dbUser = CUser::GetByID($ownerId);
			if (!$arUser = $dbUser->Fetch())
				return;
			$ownerName = $arUser["NAME"]." ".$arUser["LAST_NAME"];
			$MESS .= ' '.GetMessage('EC_EVENT_REMINDER_IN_USER', Array('#CALENDAR_NAME#' => $calendarName, '#USER_NAME#' => $ownerName));
		}
		else if($ownerType == 'GROUP')
		{
			// Get group name
			if (!$arGroup = CSocNetGroup::GetByID($ownerId))
				return;
			$ownerName = $arGroup["NAME"];
			$MESS .= ' '.GetMessage('EC_EVENT_REMINDER_IN_GROUP', Array('#CALENDAR_NAME#' => $calendarName, '#GROUP_NAME#' => $ownerName));
		}
		else
		{
			// Get iblock name
			$rsIblock = CIBlock::GetList(array(), array("ID"=>$iblockId, "CHECK_PERMISSIONS" => 'N'));
			if(!$arIblock = $rsIblock->Fetch())
				return;
			$iblockName = $arIblock['NAME'];
			$MESS .= ' '.GetMessage('EC_EVENT_REMINDER_IN_COMMON', Array('#CALENDAR_NAME#' => $calendarName, '#IBLOCK_NAME#' => $iblockName));
		}
		$MESS .= "n".GetMessage('EC_EVENT_REMINDER_DETAIL', Array('#URL_VIEW#' => $pathToPage));

		$arMessageFields = array(
			"=DATE_CREATE" => $GLOBALS["DB"]->CurrentTimeFunction(),
			"MESSAGE_TYPE" => SONET_MESSAGE_SYSTEM,
			"FROM_USER_ID" => $arEvent["CREATED_BY"],
			"TO_USER_ID" => $userId,
			"MESSAGE" => $MESS
		);
		CSocNetMessages::Add($arMessageFields);

		$db_events = GetModuleEvents("intranet", "OnRemindEventCalendar");
		while($arEvent = $db_events->Fetch())
			ExecuteModuleEventEx($arEvent, array(
				array(
					'iblockId' => $iblockId,
					'eventId' => $eventId,
					'userId' => $userId,
					'pathToPage' => $pathToPage,
					'ownerType' => $ownerType,
					'ownerId' => $ownerId
				)
			));
	}
	if ($bTmpUser)
		unset($GLOBALS["USER"]);
}