public static function OnBeforeTaskAdd(&$arTaskFields) { //Search for undefined or default title $title = isset($arTaskFields['TITLE']) ? trim($arTaskFields['TITLE']) : ''; if ($title !== '' && preg_match('/^\\s*CRM\\s*:\\s*$/i', $title) !== 1) { return; } $arTaskOwners = isset($arTaskFields['UF_CRM_TASK']) ? $arTaskFields['UF_CRM_TASK'] : array(); if (!is_array($arTaskOwners)) { $arTaskOwners = array($arTaskOwners); } $arOwnerData = array(); if (self::TryResolveUserFieldOwners($arTaskOwners, $arOwnerData, CCrmUserType::GetTaskBindingField())) { $arOwnerInfo = $arOwnerData[0]; $arTaskFields['TITLE'] = 'CRM: ' . CCrmOwnerType::GetCaption(CCrmOwnerType::ResolveID($arOwnerInfo['OWNER_TYPE_NAME']), $arOwnerInfo['OWNER_ID']); } }
public static function OnBeforeSocNetLogEntryGetRights($arEntryParams, &$arRights) { if ((!isset($arEntryParams["ENTITY_TYPE"]) || !isset($arEntryParams["ENTITY_ID"])) && isset($arEntryParams["LOG_ID"]) && intval($arEntryParams["LOG_ID"]) > 0) { if ($arLog = CSocNetLog::GetByID($arEntryParams["LOG_ID"])) { $arEntryParams["ENTITY_TYPE"] = $arLog["ENTITY_TYPE"]; $arEntryParams["ENTITY_ID"] = $arLog["ENTITY_ID"]; $arEntryParams["EVENT_ID"] = $arLog["EVENT_ID"]; } } if (!isset($arEntryParams["ENTITY_TYPE"]) || !in_array($arEntryParams["ENTITY_TYPE"], CCrmLiveFeedEntity::GetAll()) || !isset($arEntryParams["ENTITY_ID"])) { return true; } if ($arEntryParams["ENTITY_TYPE"] == CCrmLiveFeedEntity::Activity) { if (!isset($arEntryParams["ACTIVITY"])) { $arActivity = CCrmActivity::GetByID($arEntryParams["ENTITY_ID"]); if (!$arActivity) { return true; } $arEntryParams["ACTIVITY"] = $arActivity; $arEntryParams["ACTIVITY"]["COMMUNICATIONS"] = CCrmActivity::GetCommunications($arActivity["ID"]); } $arRights[] = CCrmLiveFeedEntity::GetByEntityTypeID($arEntryParams["ACTIVITY"]["OWNER_TYPE_ID"]) . $arEntryParams["ACTIVITY"]["OWNER_ID"]; $ownerEntityCode = $arEntryParams["ACTIVITY"]["OWNER_TYPE_ID"] . "_" . $arEntryParams["ACTIVITY"]["OWNER_ID"]; if (!empty($arEntryParams["ACTIVITY"]["COMMUNICATIONS"])) { foreach ($arEntryParams["ACTIVITY"]["COMMUNICATIONS"] as $arActivityCommunication) { if ($arActivityCommunication["ENTITY_TYPE_ID"] . "_" . $arActivityCommunication["ENTITY_ID"] == $ownerEntityCode) { $arRights[] = CCrmLiveFeedEntity::GetByEntityTypeID($arActivityCommunication["ENTITY_TYPE_ID"]) . $arActivityCommunication["ENTITY_ID"]; } } } if ($arEntryParams["ACTIVITY"]["TYPE_ID"] == CCrmActivityType::Task && intval($arEntryParams["ACTIVITY"]["ASSOCIATED_ENTITY_ID"]) > 0 && CModule::IncludeModule("tasks")) { $dbTask = CTasks::GetByID($arEntryParams["ACTIVITY"]["ASSOCIATED_ENTITY_ID"], false); if ($arTaskFields = $dbTask->Fetch()) { $arTaskOwners = isset($arTaskFields['UF_CRM_TASK']) ? $arTaskFields['UF_CRM_TASK'] : array(); $arOwnerData = array(); if (!is_array($arTaskOwners)) { $arTaskOwners = array($arTaskOwners); } $arFields['BINDINGS'] = array(); if (CCrmActivity::TryResolveUserFieldOwners($arTaskOwners, $arOwnerData, CCrmUserType::GetTaskBindingField())) { foreach ($arOwnerData as $arOwnerInfo) { $arRights[] = CCrmLiveFeedEntity::GetByEntityTypeID(CCrmOwnerType::ResolveID($arOwnerInfo['OWNER_TYPE_NAME'])) . $arOwnerInfo['OWNER_ID']; } } } } } elseif ($arEntryParams["ENTITY_TYPE"] == CCrmLiveFeedEntity::Invoice) { if (!isset($arEntryParams["INVOICE"])) { $arInvoice = CCrmInvoice::GetByID($arEntryParams["ENTITY_ID"]); if (!$arInvoice) { return true; } $arEntryParams["INVOICE"] = $arInvoice; } if (intval($arEntryParams["INVOICE"]["UF_CONTACT_ID"]) > 0) { $arRights[] = CCrmLiveFeedEntity::Contact . $arEntryParams["INVOICE"]["UF_CONTACT_ID"]; } if (intval($arEntryParams["INVOICE"]["UF_COMPANY_ID"]) > 0) { $arRights[] = CCrmLiveFeedEntity::Company . $arEntryParams["INVOICE"]["UF_COMPANY_ID"]; } if (intval($arEntryParams["INVOICE"]["UF_DEAL_ID"]) > 0) { $arRights[] = CCrmLiveFeedEntity::Deal . $arEntryParams["INVOICE"]["UF_DEAL_ID"]; } } else { $arRights[] = $arEntryParams["ENTITY_TYPE"] . $arEntryParams["ENTITY_ID"]; if (in_array($arEntryParams["EVENT_ID"], array("crm_lead_message", "crm_deal_message", "crm_contact_message", "crm_company_message"))) { $dbRight = CSocNetLogRights::GetList(array(), array("LOG_ID" => $arEntryParams["LOG_ID"])); while ($arRight = $dbRight->Fetch()) { $arRights[] = $arRight["GROUP_CODE"]; } } } return false; }