CAllCrmActivity::SynchronizeLiveFeedEvent

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CAllCrmActivity
  4. SynchronizeLiveFeedEvent
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_activity.php
  • Класс: \CAllCrmActivity
  • Вызов: CAllCrmActivity::SynchronizeLiveFeedEvent
static function SynchronizeLiveFeedEvent($activityID, $params)
{
	if(!is_array($params))
	{
		$params = array();
	}

	$processBindings = isset($params['PROCESS_BINDINGS']) ? (bool)$params['PROCESS_BINDINGS'] : false;
	$bindings = isset($params['BINDINGS']) && is_array($params['BINDINGS']) ? $params['BINDINGS'] : array();
	$hasBindings = !empty($bindings);
	if($processBindings)
	{
		CCrmSonetRelation::UnRegisterRelationsByEntity(CCrmOwnerType::Activity, $activityID, array('QUICK' => $hasBindings));
	}

	$arOwners = ($hasBindings ? $bindings : self::GetBindings($activityID));

	$slEntities = CCrmLiveFeed::GetLogEvents(
		array(),
		array(
			'ENTITY_TYPE_ID' => CCrmOwnerType::Activity,
			'ENTITY_ID' => $activityID
		),
		array('ID', 'EVENT_ID')
	);

	if(empty($slEntities))
	{
		return false;
	}

	global $DB;
	foreach($slEntities as &$slEntity)
	{
		$slID = intval($slEntity['ID']);
		$slEventType = $slEntity['EVENT_ID'];

		if(isset($params['REFRESH_DATE']) ? (bool)$params['REFRESH_DATE'] : false)
		{
			//Update LOG_UPDATE for force event to rise in global feed
			//Update LOG_DATE for force event to rise in entity feed
			CCrmLiveFeed::UpdateLogEvent(
				$slID,
				array(
					'=LOG_UPDATE' => $DB->CurrentTimeFunction(),
					'=LOG_DATE' => $DB->CurrentTimeFunction(),
					'LOG_RIGHTS' => (intval($params['START_RESPONSIBLE_ID']) != intval($params['FINAL_RESPONSIBLE_ID']) ? array('U'.$params['FINAL_RESPONSIBLE_ID']) : false)
				)
			);
		}
		else
		{
			//HACK: FAKE UPDATE FOR INVALIDATE CACHE
			CCrmLiveFeed::UpdateLogEvent(
				$slID,
				array(
					'ENTITY_TYPE_ID' => CCrmOwnerType::Activity,
					'ENTITY_ID' => $activityID,
					'LOG_RIGHTS' => (intval($params['START_RESPONSIBLE_ID']) != intval($params['FINAL_RESPONSIBLE_ID']) ? array('U'.$params['FINAL_RESPONSIBLE_ID']) : false)
				)
			);
		}

		$userID = (intval($params['EDITOR_ID']) > 0 ? $params['EDITOR_ID'] : CCrmSecurityHelper::GetCurrentUserID());
		if (
			intval($params['START_RESPONSIBLE_ID']) != intval($params['FINAL_RESPONSIBLE_ID'])
			&& CModule::IncludeModule("im")
		)
		{
			switch ($params['TYPE_ID'])
			{
				case CCrmActivityType::Call:
					$type = 'CALL';
					break;
				case CCrmActivityType::Meeting:
					$type = 'MEETING';
					break;
				default:
					$type = false;
			}

			if ($type)
			{
				$url = CCrmOwnerType::GetEntityShowPath(CCrmOwnerType::Activity, $activityID);

				$arMessageFields = array(
					"MESSAGE_TYPE" => IM_MESSAGE_SYSTEM,
					"FROM_USER_ID" => $userID,
					"NOTIFY_TYPE" => IM_NOTIFY_FROM,
					"NOTIFY_MODULE" => "crm",
					"LOG_ID" => $slID,
					//"NOTIFY_EVENT" => "activity_add",
					"NOTIFY_EVENT" => "changeAssignedBy",
					"NOTIFY_TAG" => "CRM|ACTIVITY|".$activityID
				);

				if (intval($params['START_RESPONSIBLE_ID']) != $userID)
				{
					$bHasPermissions = false;
					$perms = CCrmPerms::GetUserPermissions($params['START_RESPONSIBLE_ID']);
					foreach ($arOwners as $arOwner)
					{
						if (CCrmActivity::CheckReadPermission($arOwner["OWNER_TYPE_ID"], $arOwner["OWNER_ID"], $perms))
						{
							$bHasPermissions = true;
							break;
						}
					}

					if ($bHasPermissions)
					{
						$arMessageFields["TO_USER_ID"] = $params['START_RESPONSIBLE_ID'];
						$arMessageFields["NOTIFY_MESSAGE"] = GetMessage("CRM_ACTIVITY_".$type."_NOT_RESPONSIBLE_IM_NOTIFY", Array("#title#" => ''.htmlspecialcharsbx($params['SUBJECT']).''));
						$arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("CRM_ACTIVITY_".$type."_NOT_RESPONSIBLE_IM_NOTIFY", Array("#title#" => htmlspecialcharsbx($params['SUBJECT'])))." (".CCrmUrlUtil::ToAbsoluteUrl($url).")";

						CIMNotify::Add($arMessageFields);
					}
				}

				if (intval($params['FINAL_RESPONSIBLE_ID']) != $userID)
				{
					$bHasPermissions = false;
					$perms = CCrmPerms::GetUserPermissions($params['FINAL_RESPONSIBLE_ID']);
					foreach ($arOwners as $arOwner)
					{
						if (CCrmActivity::CheckReadPermission($arOwner["OWNER_TYPE_ID"], $arOwner["OWNER_ID"], $perms))
						{
							$bHasPermissions = true;
							break;
						}
					}

					$arMessageFields["TO_USER_ID"] = $params['FINAL_RESPONSIBLE_ID'];
					if ($bHasPermissions)
					{
						$arMessageFields["NOTIFY_MESSAGE"] = GetMessage("CRM_ACTIVITY_".$type."_RESPONSIBLE_IM_NOTIFY", Array("#title#" => ''.htmlspecialcharsbx($params['SUBJECT']).''));
						$arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("CRM_ACTIVITY_".$type."_RESPONSIBLE_IM_NOTIFY", Array("#title#" => htmlspecialcharsbx($params['SUBJECT'])))." (".CCrmUrlUtil::ToAbsoluteUrl($url).")";
					}
					else
					{
						//TODO: Add  message 'Need for permissions'
						$arMessageFields["NOTIFY_MESSAGE"] = GetMessage("CRM_ACTIVITY_".$type."_RESPONSIBLE_IM_NOTIFY", Array("#title#" => htmlspecialcharsbx($params['SUBJECT'])));
						$arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("CRM_ACTIVITY_".$type."_RESPONSIBLE_IM_NOTIFY", Array("#title#" => htmlspecialcharsbx($params['SUBJECT'])));
					}

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

		if ($processBindings && $hasBindings && Settings\Crm::isLiveFeedRecordsGenerationEnabled())
		{
			CCrmSonetRelation::RegisterRelationBundle(
				$slID,
				$slEventType,
				CCrmOwnerType::Activity,
				$activityID,
				$bindings,
				array(
					'ENTITY_TYPE_ID_KEY' => 'OWNER_TYPE_ID',
					'ENTITY_ID_KEY' => 'OWNER_ID',
					'TYPE_ID' => CCrmSonetRelationType::Ownership
				)
			);
		}
	}
	unset($slEntity);
	return true;
}

Добавить комментарий