public function saveToIBProp($iblockID, $elementID, $propCode, $action = self::F_IB_IMG_PROP_APPEND) { if (true !== $this->_bRequestsComplete && true !== $this->_bDownloadsComplete) { return false; } $arProp = array(); $arErr = array(); if (is_numeric($propCode)) { $propID = intval($propCode); $propCode = Tools::getPropCodeById($iblockID, $propID, $arProp, $arErr); if ($propCode === false) { return false; } } else { $propID = Tools::getPropIdByCode($iblockID, $propCode, $arProp, $arErr); if ($propID === false) { return false; } } if (!empty($arErr)) { return false; } if ($arProp['PROPERTY_TYPE'] != 'F') { return false; } if ($arProp['MULTIPLE'] != 'Y') { return false; } $arFileList = array(); /** @var Request $Request */ foreach ($this->_arRequestList as $Request) { if ($Request->isDownloadSuccess()) { $downloadFileRelPath = $Request->getDownloadFilePath(false); $arFile = \CFile::MakeFileArray($downloadFileRelPath); if (!empty($arFile)) { $arFileList[] = $arFile; } } } if (!empty($arFileList)) { switch ($action) { case self::F_IB_IMG_PROP_REPLACE: \CIBlockElement::SetPropertyValuesEx($elementID, $iblockID, array($arProp['ID'] => $arFileList)); break; case self::F_IB_IMG_PROP_APPEND: \CIBlockElement::SetPropertyValues($elementID, $iblockID, $arFileList, $arProp['ID']); break; } } return true; }
/** * @param int $iblockID * @param int $elementID * @param int|string $propCode * @param int $action * @param string $description * @throws RequestError * @return bool */ public function saveToIBProp($iblockID, $elementID, $propCode, $action = self::F_IB_IMG_PROP_APPEND, $description = '') { if (true !== $this->_bRequestSuccess && true !== $this->_bDownloadSuccess) { return false; } $arProp = array(); $arErr = array(); if (is_numeric($propCode)) { $propID = intval($propCode); $propCode = Tools::getPropCodeById($iblockID, $propID, $arProp, $arErr); if ($propCode === false) { throw new RequestError('', RequestError::E_BX_FILE_PROP_NOT_FOUND); } } else { $propID = Tools::getPropIdByCode($iblockID, $propCode, $arProp, $arErr); if ($propID === false) { throw new RequestError('', RequestError::E_BX_FILE_PROP_NOT_FOUND); } } if ($arProp['PROPERTY_TYPE'] != 'F') { throw new RequestError('', RequestError::E_BX_FILE_PROP_WRONG_TYPE); } if ($this->_ID === null) { $this->_ID = static::generateID(); } if (!CheckDirPath(OBX_DOC_ROOT . static::DOWNLOAD_FOLDER . '/' . $this->_ID)) { throw new RequestError('', RequestError::E_PERM_DENIED); } $downloadFileRelPath = $this->getDownloadFilePath(false); if ($this->_bDownloadSuccess) { $arFile = \CFile::MakeFileArray($downloadFileRelPath); } elseif ($this->_bRequestSuccess) { $this->saveToFile($downloadFileRelPath); $arFile = \CFile::MakeFileArray($downloadFileRelPath); } $arFile['name'] = $this->_originalName . '.' . $this->_originalExt; if (is_string($description) && !empty($description)) { $arFile['description'] = $description; } switch ($action) { case self::F_IB_IMG_PROP_REPLACE: \CIBlockElement::SetPropertyValuesEx($elementID, $iblockID, array($arProp['ID'] => $arFile)); break; case self::F_IB_IMG_PROP_APPEND: \CIBlockElement::SetPropertyValues($elementID, $iblockID, $arFile, $arProp['ID']); break; } return true; }