...Человеческий поиск в разработке...
- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/classes/general/restservice_invoice.php
- Класс: \CCrmInvoiceRestService
- Вызов: CCrmInvoiceRestService::tryInternalizeDiskFileField
static function tryInternalizeDiskFileField(&$fields, $fieldName, $multiple = false) { if(!isset($fields[$fieldName])) { return false; } $result = array(); $values = $multiple && self::isIndexedArray($fields[$fieldName]) ? $fields[$fieldName] : array($fields[$fieldName]); foreach($values as &$v) { if(!self::isAssociativeArray($v)) { continue; } $fileID = isset($v['id']) ? intval($v['id']) : 0; $removeElement = isset($v['remove']) && is_string($v['remove']) && mb_strtoupper($v['remove']) === 'Y'; $fileData = isset($v['fileData']) ? $v['fileData'] : ''; if(!self::isIndexedArray($fileData)) { continue; } $fileDataLength = count($fileData); if($fileDataLength === 0) { continue; } if($fileDataLength === 1) { $fileName = ''; $fileContent = $fileData[0]; } else { $fileName = $fileData[0]; $fileContent = $fileData[1]; } if(is_string($fileContent) && $fileContent !== '') { $folder = DiskManager::ensureFolderCreated(StorageFileType::Rest); if(!$folder) { throw new RestException('Could not create disk folder for rest files.'); } $fileInfo = CRestUtil::saveFile($fileContent, $fileName); if(is_array($fileInfo)) { $file = $folder->uploadFile( $fileInfo, array('NAME' => $fileName, 'CREATED_BY' => self::getCurrentUserID()), array(), true ); unlink($fileInfo['tmp_name']); if(!$file) { throw new RestException('Could not create disk file.'); } $result[] = array('FILE_ID' => $file->getId()); } } elseif($fileID > 0 && $removeElement) { $result[] = array('OLD_FILE_ID' => $fileID, 'DELETE' => true); } } unset($v); if($multiple) { $fields[$fieldName] = $result; return true; } elseif(!empty($result)) { $fields[$fieldName] = $result[0]; return true; } unset($fields[$fieldName]); return false; }