コード例 #1
0
ファイル: livefeed.php プロジェクト: DarneoStudio/bitrix
 public static function CreateLogEvent(&$fields, $eventType, $options = array())
 {
     if (!CModule::IncludeModule('socialnetwork')) {
         return false;
     }
     global $APPLICATION, $DB;
     if (!is_array($options)) {
         $options = array();
     }
     $entityTypeID = isset($fields['ENTITY_TYPE_ID']) ? intval($fields['ENTITY_TYPE_ID']) : CCrmOwnerType::Undefined;
     if (!CCrmOwnerType::IsDefined($entityTypeID)) {
         $fields['ERROR'] = 'Entity type is not found';
         return false;
     }
     //$entityType = CCrmOwnerType::ResolveName($entityTypeID);
     $entityID = isset($fields['ENTITY_ID']) ? intval($fields['ENTITY_ID']) : 0;
     if ($entityID < 0) {
         $fields['ERROR'] = 'Entity ID is not found';
         return false;
     }
     $message = isset($fields['MESSAGE']) && is_string($fields['MESSAGE']) ? $fields['MESSAGE'] : '';
     $title = isset($fields['TITLE']) && is_string($fields['TITLE']) ? $fields['TITLE'] : '';
     if ($title === '') {
         $title = self::UntitledMessageStub;
     }
     $userID = isset($fields['USER_ID']) ? intval($fields['USER_ID']) : 0;
     if ($userID <= 0) {
         $userID = CCrmSecurityHelper::GetCurrentUserID();
     }
     $sourceID = isset($fields['SOURCE_ID']) ? intval($fields['SOURCE_ID']) : 0;
     /*if(!(is_int($sourceID) && $sourceID > 0))
     		{
     			$fields['ERROR'] = 'Could not find event';
     			return false;
     		}*/
     $url = isset($fields['URL']) ? $fields['URL'] : '';
     $params = isset($fields['PARAMS']) ? $fields['PARAMS'] : null;
     $liveFeedEntityType = CCrmLiveFeedEntity::GetByEntityTypeID($entityTypeID);
     $eventID = CCrmLiveFeedEvent::GetEventID($liveFeedEntityType, $eventType);
     $eventFields = array('EVENT_ID' => $eventID, '=LOG_DATE' => $DB->CurrentTimeFunction(), 'TITLE' => $title, 'MESSAGE' => $message, 'TEXT_MESSAGE' => '', 'MODULE_ID' => $eventID == 'crm_activity_add' ? 'crm_shared' : 'crm', 'CALLBACK_FUNC' => false, 'ENABLE_COMMENTS' => 'Y', 'PARAMS' => is_array($params) && !empty($params) ? serialize($params) : '', 'USER_ID' => $userID, 'ENTITY_TYPE' => $liveFeedEntityType, 'ENTITY_ID' => $entityID, 'SOURCE_ID' => $sourceID, 'URL' => $url, 'UF_SONET_LOG_DOC' => !empty($fields["UF_SONET_LOG_DOC"]) ? $fields["UF_SONET_LOG_DOC"] : false, 'UF_SONET_LOG_FILE' => !empty($fields["UF_SONET_LOG_DOC"]) ? $fields["UF_SONET_LOG_FILE"] : false);
     $sendMessage = isset($options['SEND_MESSAGE']) && is_bool($options['SEND_MESSAGE']) ? $options['SEND_MESSAGE'] : false;
     $logEventID = CSocNetLog::Add($eventFields, $sendMessage);
     if (is_int($logEventID) && $logEventID > 0) {
         $arUpdateFields = array('RATING_TYPE_ID' => 'LOG_ENTRY', 'RATING_ENTITY_ID' => $logEventID);
         CSocNetLog::Update($logEventID, $arUpdateFields);
         self::RegisterOwnershipRelations($logEventID, $eventID, $fields);
         $eventFields["LOG_ID"] = $logEventID;
         CCrmLiveFeed::CounterIncrement($eventFields);
         return $logEventID;
     }
     $ex = $APPLICATION->GetException();
     $fields['ERROR'] = $ex->GetString();
     return false;
 }