private static function SetFromCalendarEvent($eventID, &$arEventFields, &$arFields) { $isNew = !(isset($arFields['ID']) && intval($arFields['ID']) > 0); $arFields['ASSOCIATED_ENTITY_ID'] = $eventID; $arEventOwners = array(); if (isset($arEventFields['UF_CRM_CAL_EVENT'])) { $arEventOwners = $arEventFields['UF_CRM_CAL_EVENT']; } else { //Try to load if not found CRM bindings $arReloadedEventFields = CCalendarEvent::GetById($eventID, false); if (isset($arReloadedEventFields['UF_CRM_CAL_EVENT'])) { $arEventOwners = $arReloadedEventFields['UF_CRM_CAL_EVENT']; } } if (!is_array($arEventOwners)) { $arEventOwners = array($arEventOwners); } $arOwnerData = array(); self::TryResolveUserFieldOwners($arEventOwners, $arOwnerData, CCrmUserType::GetCalendarEventBindingField()); if (!empty($arOwnerData)) { $arFields['OWNER_TYPE_ID'] = CCrmOwnerType::ResolveID($arOwnerData[0]['OWNER_TYPE_NAME']); $arFields['OWNER_ID'] = $arOwnerData[0]['OWNER_ID']; foreach ($arOwnerData as &$arOwnerInfo) { $arFields['BINDINGS'][] = array('OWNER_TYPE_ID' => CCrmOwnerType::ResolveID($arOwnerInfo['OWNER_TYPE_NAME']), 'OWNER_ID' => $arOwnerInfo['OWNER_ID']); } unset($arOwnerInfo); } else { $arFields['OWNER_TYPE_ID'] = 0; $arFields['OWNER_ID'] = 0; $arFields['BINDINGS'] = array(); } if ($isNew) { //Meeting by default $arFields['TYPE_ID'] = CCrmActivityType::Meeting; //Not completed for new activities. Do not change existed activities. $arFields['COMPLETED'] = 'N'; } if ($isNew || isset($arEventFields['NAME'])) { $arFields['SUBJECT'] = isset($arEventFields['NAME']) ? $arEventFields['NAME'] : ''; } $isPeriodicEvent = isset($arEventFields['RRULE']) && $arEventFields['RRULE'] !== ''; //If 'DT_FROM' is assigned set 'START_TIME' and 'END_TIME' from 'DT_FROM'. Activity deadline will be at calevent DT_FROM //Ignore 'DT_TO' if periodic event if (isset($arEventFields['DT_FROM']) && isset($arEventFields['DT_TO'])) { $arFields['START_TIME'] = $arEventFields['DT_FROM']; $arFields['END_TIME'] = !$isPeriodicEvent ? $arEventFields['DT_TO'] : $arEventFields['DT_FROM']; } elseif (isset($arEventFields['DT_FROM'])) { $arFields['START_TIME'] = $arFields['END_TIME'] = $arEventFields['DT_FROM']; } elseif (isset($arEventFields['DT_TO']) && !$isPeriodicEvent) { $arFields['START_TIME'] = $arFields['END_TIME'] = $arEventFields['DT_TO']; } if ($isNew || isset($arEventFields['CREATED_BY'])) { $arFields['RESPONSIBLE_ID'] = isset($arEventFields['CREATED_BY']) ? intval($arEventFields['CREATED_BY']) : 0; } if ($isNew || isset($arEventFields['IMPORTANCE'])) { $arFields['PRIORITY'] = CCrmActivityPriority::FromCalendarEventImportance(isset($arEventFields['IMPORTANCE']) ? $arEventFields['IMPORTANCE'] : ''); } if ($isNew || isset($arEventFields['DESCRIPTION'])) { $arFields['DESCRIPTION'] = isset($arEventFields['DESCRIPTION']) ? $arEventFields['DESCRIPTION'] : ''; } if ($isNew || isset($arEventFields['LOCATION'])) { $arFields['LOCATION'] = isset($arEventFields['LOCATION']) ? $arEventFields['LOCATION'] : ''; } if ($isNew || isset($arEventFields['REMIND'])) { $remindData = isset($arEventFields['REMIND']) ? $arEventFields['REMIND'] : array(); if (is_string($remindData)) { if ($remindData !== '') { $remindData = unserialize($remindData); } if (!is_array($remindData)) { $remindData = array(); } } if (empty($remindData)) { $arFields['NOTIFY_TYPE'] = CCrmActivityNotifyType::None; } else { $remindInfo = $remindData[0]; $remindType = CCrmActivityNotifyType::FromCalendarEventRemind(isset($remindInfo['type']) ? $remindInfo['type'] : ''); $remindValue = isset($remindInfo['count']) ? intval($remindInfo['count']) : 0; if ($remindType !== CCrmActivityNotifyType::None && $remindValue > 0) { $arFields['NOTIFY_TYPE'] = $remindType; $arFields['NOTIFY_VALUE'] = $remindValue; } } } }