• Модуль: voximplant
  • Путь к файлу: ~/bitrix/modules/voximplant/classes/general/vi_history.php
  • Класс: CVoxImplantHistory
  • Вызов: CVoxImplantHistory::AttachRecord
static function AttachRecord($callId, array $recordFileFields)
{
	$result = new Result();
	$arHistory = VIStatisticTable::getRow([
		'select' => ['*'],
		'filter' => ['=CALL_ID' => $callId]
	]);

	if(!$arHistory)
	{
		return $result->addError(new BitrixMainError("Call is not found", "NOT_FOUND"));
	}

	$historyID = $arHistory["ID"];
	$recordFileFields['MODULE_ID'] = 'voximplant';
	$fileId = CFile::SaveFile($recordFileFields, 'voximplant', true);

	if(!$fileId)
	{
		return $result->addError(new BitrixMainError("Could not save file", "SAVE_FILE_ERROR"));
	}

	VIStatisticTable::update($historyID, ['CALL_RECORD_ID' => $fileId]);
	$elementId = CVoxImplantDiskHelper::SaveFile($arHistory, CFile::GetFileArray($fileId));
	$elementId = (int)$elementId;
	VIStatisticTable::update($historyID, ['CALL_WEBDAV_ID' => $elementId]);

	if (VILimits::getRecordLimit() > 0)
	{
		VILimits::registerRecord();
	}

	CVoxImplantCrmHelper::AttachRecordToCall([
		'CALL_ID' => $callId,
		'CALL_RECORD_ID' => $fileId,
		'CALL_WEBDAV_ID' => $elementId,
	]);

	return $result;
}