- Модуль: voximplant
- Путь к файлу: ~/bitrix/modules/voximplant/lib/rest/helper.php
- Класс: BitrixVoximplantRestHelper
- Вызов: Helper::attachFile
static function attachFile(string $callId, File $file, string $recordUrl = null): Result
{
$result = new Result();
if (!Loader::includeModule('crm'))
{
return $result->addError(new Error("CRM is not installed"));
}
$statisticRecord = StatisticTable::getByCallId($callId);
if (!$statisticRecord)
{
return $result->addError(new Error("Call is not found in the statistic table. Looks like it is not finished yet."));
}
StatisticTable::update($statisticRecord['ID'], [
'CALL_RECORD_ID' => $file->getFileId(),
'CALL_WEBDAV_ID' => $file->getId(),
'CALL_RECORD_URL' => $recordUrl,
]);
if ($statisticRecord['CRM_ACTIVITY_ID'])
{
$activity = CCrmActivity::GetByID($statisticRecord['CRM_ACTIVITY_ID'], false);
}
else
{
$activity = CCrmActivity::GetByOriginID('VI_' . $statisticRecord['CALL_ID'], false);
}
if ($activity)
{
$activityFields = [
'STORAGE_TYPE_ID' => StorageType::Disk,
'STORAGE_ELEMENT_IDS' => [$file->getId()]
];
$updateResult = CCrmActivity::Update($activity['ID'], $activityFields, false);
if(!$updateResult)
{
return $result->addError(new Error(CCrmActivity::GetLastErrorMessage()));
}
}
return $result;
}