• Модуль: timeman
  • Путь к файлу: ~/bitrix/modules/timeman/classes/general/timeman_report_full.php
  • Класс: CReportNotifications
  • Вызов: CReportNotifications::AddCommentToIM
static function AddCommentToIM($arFields)
{
	if (
		CModule::IncludeModule("im")
		&& intval($arFields["USER_ID"]) > 0
	)
	{
		$date_text = "";
		$dbReport = CTimeManReportFull::GetByID($arFields["REPORT_ID"]);
		if ($arReport = $dbReport->Fetch())
		{
			$date_from = FormatDate("j F", MakeTimeStamp($arReport["DATE_FROM"], CSite::GetDateFormat("FULL", SITE_ID)));
			$date_to = FormatDate("j F", MakeTimeStamp($arReport["DATE_TO"], CSite::GetDateFormat("FULL", SITE_ID)));
			if ($date_from == $date_to)
				$date_text = $date_to;
			else
				$date_text = $date_from." - ".$date_to;

			$arMessageFields = array(
				"MESSAGE_TYPE" => IM_MESSAGE_SYSTEM,
				"FROM_USER_ID" => $arFields["USER_ID"],
				"NOTIFY_TYPE" => IM_NOTIFY_FROM,
				"NOTIFY_MODULE" => "timeman",
				"NOTIFY_EVENT" => "report_comment",
				"NOTIFY_TAG" => "TIMEMAN|REPORT|".$arFields["REPORT_ID"],
			);

			$arUserIDToSend = array(
				$arReport["USER_ID"]
			);

			$gender_suffix = "";
			$dbUser = CUser::GetByID($arFields["USER_ID"]);
			if ($arUser = $dbUser->Fetch())
			{
				switch ($arUser["PERSONAL_GENDER"])
				{
					case "M":
						$gender_suffix = "_M";
						break;
					case "F":
						$gender_suffix = "_F";
							break;
					default:
						$gender_suffix = "";
				}
			}

			$arManagers = CTimeMan::GetUserManagers($arReport["USER_ID"]);
			if (is_array($arManagers))
				$arUserIDToSend = array_merge($arUserIDToSend, $arManagers);

			$reports_page = COption::GetOptionString("timeman", "WORK_REPORT_PATH", "/timeman/work_report.php");

			$arUnFollowers = array();

			$rsUnFollower = CSocNetLogFollow::GetList(
				array(
					"USER_ID" => $arUserIDToSend,
					"CODE" => "L".$arFields["LOG_ID"],
					"TYPE" => "N"
				),
				array("USER_ID")
			);
			while ($arUnFollower = $rsUnFollower->Fetch())
				$arUnFollowers[] = $arUnFollower["USER_ID"];

			$arUserIDToSend = array_diff($arUserIDToSend, $arUnFollowers);

			foreach($arUserIDToSend as $user_id)
			{
				if ($arFields["USER_ID"] == $user_id)
					continue;

				$arMessageFields["TO_USER_ID"] = $user_id;
				$arTmp = CSocNetLogTools::ProcessPath(array("REPORTS_PAGE" => $reports_page), $user_id);

				$sender_type = ($arReport["USER_ID"] == $user_id ? "1" : ($arReport["USER_ID"] == $arFields["USER_ID"] ? "2" : "3"));

				$arMessageFields["NOTIFY_MESSAGE"] = GetMessage("REPORT_FULL_IM_COMMENT_".$sender_type.$gender_suffix, Array(
					"#period#" => "".htmlspecialcharsbx($date_text)."",
				));

				$arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("REPORT_FULL_IM_COMMENT_".$sender_type.$gender_suffix, Array(
					"#period#" => htmlspecialcharsbx($date_text),
				))." ( ".$arTmp["SERVER_NAME"].$arTmp["URLS"]["REPORTS_PAGE"]."#user_id=".$arReport["USER_ID"]."&report=".$arReport["ID"]." )#BR##BR#".$arFields["MESSAGE"];

				CIMNotify::Add($arMessageFields);
			}
		}
	}
}