private static function RegisterOwnershipRelations($logEntityID, $logEventID, &$fields) { $entityTypeID = isset($fields['ENTITY_TYPE_ID']) ? intval($fields['ENTITY_TYPE_ID']) : CCrmOwnerType::Undefined; if (!CCrmOwnerType::IsDefined($entityTypeID)) { return; } $entityID = isset($fields['ENTITY_ID']) ? intval($fields['ENTITY_ID']) : 0; if ($entityID < 0) { return; } $parents = isset($fields['PARENTS']) && is_array($fields['PARENTS']) ? $fields['PARENTS'] : array(); if (!empty($fields['PARENTS'])) { $parentOptions = isset($fields['PARENT_OPTIONS']) && is_array($fields['PARENT_OPTIONS']) ? $fields['PARENT_OPTIONS'] : array(); $parentOptions['TYPE_ID'] = CCrmSonetRelationType::Ownership; CCrmSonetRelation::RegisterRelationBundle($logEntityID, $logEventID, $entityTypeID, $entityID, $parents, $parentOptions); } else { $parentEntityTypeID = isset($fields['PARENT_ENTITY_TYPE_ID']) ? intval($fields['PARENT_ENTITY_TYPE_ID']) : CCrmOwnerType::Undefined; $parentEntityID = isset($fields['PARENT_ENTITY_ID']) ? intval($fields['PARENT_ENTITY_ID']) : 0; if (CCrmOwnerType::IsDefined($parentEntityTypeID) && $parentEntityID > 0) { CCrmSonetRelation::RegisterRelation($logEntityID, $logEventID, $entityTypeID, $entityID, $parentEntityTypeID, $parentEntityID, CCrmSonetRelationType::Ownership, 1); } } }
private 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())); } else { //HACK: FAKE UPDATE FOR INVALIDATE CACHE CCrmLiveFeed::UpdateLogEvent($slID, array('ENTITY_TYPE_ID' => CCrmOwnerType::Activity, 'ENTITY_ID' => $activityID)); } /* 'START_RESPONSIBLE_ID' => $arPrevEntity['RESPONSIBLE_ID'], 'FINAL_RESPONSIBLE_ID' => $responsibleID */ $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 = "/crm/stream/?log_id=#log_id#"; $url = str_replace(array("#log_id#"), array($slID), $url); $serverName = (CMain::IsHTTPS() ? "https" : "http") . "://" . (defined("SITE_SERVER_NAME") && strlen(SITE_SERVER_NAME) > 0 ? SITE_SERVER_NAME : COption::GetOptionString("main", "server_name", "")); $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_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#" => '<a href="' . $url . '">' . htmlspecialcharsbx($params['SUBJECT']) . '</a>')); $arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("CRM_ACTIVITY_" . $type . "_NOT_RESPONSIBLE_IM_NOTIFY", array("#title#" => htmlspecialcharsbx($params['SUBJECT']))) . " (" . $serverName . $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; } } if ($bHasPermissions) { $arMessageFields["TO_USER_ID"] = $params['FINAL_RESPONSIBLE_ID']; $arMessageFields["NOTIFY_MESSAGE"] = GetMessage("CRM_ACTIVITY_" . $type . "_RESPONSIBLE_IM_NOTIFY", array("#title#" => '<a href="' . $url . '">' . htmlspecialcharsbx($params['SUBJECT']) . '</a>')); $arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("CRM_ACTIVITY_" . $type . "_RESPONSIBLE_IM_NOTIFY", array("#title#" => htmlspecialcharsbx($params['SUBJECT']))) . " (" . $serverName . $url . ")"; CIMNotify::Add($arMessageFields); } } } } if ($processBindings && $hasBindings) { 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; }
private static function SynchronizeLiveFeedEvent($invoiceID, $params) { $invoiceID = intval($invoiceID); if ($invoiceID <= 0) { return; } if (!is_array($params)) { $params = array(); } $processParents = isset($params['PROCESS_PARENTS']) ? (bool) $params['PROCESS_PARENTS'] : false; $parents = isset($params['PARENTS']) && is_array($params['PARENTS']) ? $params['PARENTS'] : array(); $hasParents = !empty($parents); if ($processParents) { CCrmSonetRelation::UnRegisterRelationsByEntity(CCrmOwnerType::Invoice, $invoiceID, array('QUICK' => $hasParents)); } $userID = CCrmSecurityHelper::GetCurrentUserID(); $startResponsibleID = isset($params['START_RESPONSIBLE_ID']) ? intval($params['START_RESPONSIBLE_ID']) : 0; $finalResponsibleID = isset($params['FINAL_RESPONSIBLE_ID']) ? intval($params['FINAL_RESPONSIBLE_ID']) : 0; $enableMessages = ($startResponsibleID > 0 || $finalResponsibleID > 0) && IsModuleInstalled('im') && CModule::IncludeModule('im'); $topic = isset($params['TOPIC']) ? $params['TOPIC'] : $invoiceID; $slEntities = CCrmLiveFeed::GetLogEvents(array(), array('ENTITY_TYPE_ID' => CCrmOwnerType::Invoice, 'ENTITY_ID' => $invoiceID), array('ID', 'EVENT_ID')); 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 global $DB; CCrmLiveFeed::UpdateLogEvent($slID, array('=LOG_UPDATE' => $DB->CurrentTimeFunction(), '=LOG_DATE' => $DB->CurrentTimeFunction())); } else { //HACK: FAKE UPDATE FOR INVALIDATE CACHE CCrmLiveFeed::UpdateLogEvent($slID, array('ENTITY_TYPE_ID' => CCrmOwnerType::Invoice, 'ENTITY_ID' => $invoiceID)); } if ($processParents && $hasParents) { CCrmSonetRelation::RegisterRelationBundle($slID, $slEventType, CCrmOwnerType::Invoice, $invoiceID, $parents, array('TYPE_ID' => CCrmSonetRelationType::Ownership)); } if ($enableMessages) { $messageFields = array('MESSAGE_TYPE' => IM_MESSAGE_SYSTEM, 'FROM_USER_ID' => $userID, 'NOTIFY_TYPE' => IM_NOTIFY_FROM, 'NOTIFY_MODULE' => 'crm', 'LOG_ID' => $slID, 'NOTIFY_EVENT' => 'invoice_responsible_changed', 'NOTIFY_TAG' => "CRM|INVOICE|{$invoiceID}"); $eventUrl = CCrmLiveFeed::GetShowUrl($slID); if ($startResponsibleID > 0 && $startResponsibleID !== $userID) { $messageFields['TO_USER_ID'] = $startResponsibleID; $messageFields['NOTIFY_MESSAGE'] = GetMessage('CRM_INVOICE_NOT_RESPONSIBLE_IM_NOTIFY', array('#title#' => '<a href="' . htmlspecialcharsbx($eventUrl) . '">' . htmlspecialcharsbx($topic) . '</a>')); $messageFields['NOTIFY_MESSAGE_OUT'] = GetMessage('CRM_INVOICE_NOT_RESPONSIBLE_IM_NOTIFY', array('#title#' => htmlspecialcharsbx($topic))) . " (" . CCrmUrlUtil::ToAbsoluteUrl($eventUrl) . ")"; CIMNotify::Add($messageFields); } if ($finalResponsibleID > 0 && $finalResponsibleID !== $userID) { $messageFields['TO_USER_ID'] = $finalResponsibleID; $messageFields['NOTIFY_MESSAGE'] = GetMessage('CRM_INVOICE_RESPONSIBLE_IM_NOTIFY', array('#title#' => '<a href="' . htmlspecialcharsbx($eventUrl) . '">' . htmlspecialcharsbx($topic) . '</a>')); $messageFields['NOTIFY_MESSAGE_OUT'] = GetMessage('CRM_INVOICE_RESPONSIBLE_IM_NOTIFY', array('#title#' => htmlspecialcharsbx($topic))) . " (" . CCrmUrlUtil::ToAbsoluteUrl($eventUrl) . ")"; CIMNotify::Add($messageFields); } } } unset($slEntity); }