Пример #1
0
 public static function RegisterEntity($params)
 {
     if (!CModule::IncludeModule('crm')) {
         return false;
     }
     $callId = $params['ORIGIN_ID'];
     $callerId = '';
     if (substr($callId, 0, 3) == 'VI_') {
         $callId = substr($callId, 3);
     }
     $res = VI\CallTable::getList(array('filter' => array('=CALL_ID' => $callId)));
     if ($call = $res->fetch()) {
         $callerId = $call['CALLER_ID'];
         CVoxImplantCrmHelper::AddCall(array('CALL_ID' => $call['CALL_ID'], 'PHONE_NUMBER' => $call['CALLER_ID'], 'INCOMING' => $call['INCOMING'], 'USER_ID' => $call['USER_ID'], 'DATE_CREATE' => $call['DATE_CREATE']));
         if ($call['USER_ID'] > 0) {
             $crmData = CVoxImplantCrmHelper::GetDataForPopup($callId, $call['CALLER_ID'], $call['USER_ID']);
             $pullResult = CVoxImplantIncoming::SendPullEvent(array('COMMAND' => 'update_crm', 'USER_ID' => $call['USER_ID'], 'CALL_ID' => $callId, 'CALLER_ID' => $callerId, 'CRM' => $crmData));
         }
         CVoxImplantHistory::WriteToLog(array($callId, $call), 'CRM ATTACH INIT CALL');
     } else {
         $res = VI\StatisticTable::getList(array('filter' => array('=CALL_ID' => $callId)));
         if ($history = $res->fetch()) {
             $history['USER_ID'] = $history['PORTAL_USER_ID'];
             $history['DATE_CREATE'] = $history['CALL_START_DATE'];
             CVoxImplantCrmHelper::AddCall(array('CALL_ID' => $history['CALL_ID'], 'PHONE_NUMBER' => $history['PHONE_NUMBER'], 'INCOMING' => $history['INCOMING'] == CVoxImplantMain::CALL_OUTGOING ? CVoxImplantMain::CALL_OUTGOING : CVoxImplantMain::CALL_INCOMING, 'USER_ID' => $history['USER_ID'], 'DATE_CREATE' => $history['DATE_CREATE']));
             CVoxImplantCrmHelper::UpdateCall($history);
             CVoxImplantCrmHelper::AttachRecordToCall(array('CALL_ID' => $history['CALL_ID'], 'CALL_WEBDAV_ID' => $history['CALL_WEBDAV_ID'], 'CALL_RECORD_ID' => $history['CALL_RECORD_ID']));
             CVoxImplantHistory::WriteToLog(array($callId), 'CRM ATTACH FULL CALL');
         }
     }
     return true;
 }
Пример #2
0
 public static function DownloadAgent($historyID, $recordUrl, $attachToCrm = true)
 {
     $historyID = intval($historyID);
     if (strlen($recordUrl) <= 0 || $historyID <= 0) {
         return false;
     }
     $http = new \Bitrix\Main\Web\HttpClient();
     $http->query('HEAD', $recordUrl);
     if ($http->getStatus() != 200) {
         CAgent::AddAgent("CVoxImplantHistory::DownloadAgent('{$historyID}','{$recordUrl}','{$attachToCrm}');", 'voximplant', 'N', 30, '', 'Y', ConvertTimeStamp(time() + CTimeZone::GetOffset() + 30, 'FULL'));
         return false;
     }
     $history = VI\StatisticTable::getById($historyID);
     $arHistory = $history->fetch();
     try {
         $recordFile = CFile::MakeFileArray($recordUrl);
         if (is_array($recordFile) && $recordFile['size'] && $recordFile['size'] > 0) {
             $recordFile = array_merge($recordFile, array('MODULE_ID' => 'voximplant'));
             $fileID = CFile::SaveFile($recordFile, 'voximplant');
             if (is_int($fileID) && $fileID > 0) {
                 $elementID = CVoxImplantDiskHelper::SaveFile($arHistory, CFile::GetFileArray($fileID), CSite::GetDefSite());
                 $elementID = intval($elementID);
                 if ($attachToCrm && $elementID > 0) {
                     CVoxImplantCrmHelper::AttachRecordToCall(array('CALL_ID' => $arHistory['CALL_ID'], 'CALL_RECORD_ID' => $fileID, 'CALL_WEBDAV_ID' => $elementID));
                 }
                 VI\StatisticTable::update($historyID, array('CALL_RECORD_ID' => $fileID, 'CALL_WEBDAV_ID' => $elementID));
             }
         }
     } catch (Exception $ex) {
     }
     return false;
 }