• Модуль: voximplant
  • Путь к файлу: ~/bitrix/modules/voximplant/lib/rest/helper.php
  • Класс: BitrixVoximplantRestHelper
  • Вызов: Helper::uploadRecord
static function uploadRecord($callId)
{
	$result = new Result();
	if (!is_array($_FILES[self::FILE_FIELD]))
	{
		$result->addError(new Error("Error: required parameter " . self::FILE_FIELD . " is not found"));
		return $result;
	}

	$fileArray = $_FILES[self::FILE_FIELD];
	$fileName = $fileArray['name'];

	$allowedExtensions = array('wav', 'mp3');
	if (!in_array(GetFileExtension($fileName), $allowedExtensions))
	{
		$result->addError(new Error("Wrong file extension. Only wav and mp3 are allowed"));
		return $result;
	}

	$statisticRecord = BitrixVoximplantStatisticTable::getByCallId($callId);
	if (!$statisticRecord)
	{
		$result->addError(new Error("Call is not found in the statistic table. Looks like it is not finished yet."));
		return $result;
	}

	$saveResult = static::saveFile($statisticRecord['CALL_START_DATE']->format("Y-m"), $fileName, $fileArray, $statisticRecord['PORTAL_USER_ID']);
	if (!$saveResult->isSuccess())
	{
		$result->addErrors($saveResult->getErrors());
		return $result;
	}
	$saveResultData = $saveResult->getData();
	$file = $saveResultData['FILE'];

	$attachResult = static::attachFile($callId, $file);
	if (!$attachResult->isSuccess())
	{
		$result->addErrors($attachResult->getErrors());
		return $result;
	}

	$result->setData([
		'FILE_ID' => $file->getId()
	]);

	return $result;
}