private function loadData() { if (empty($this->arParams['PARAMS']['arUserField'])) { return array(); } $userId = $this->getUser()->getId(); $values = $this->arParams['PARAMS']['arUserField']['VALUE']; if (!is_array($this->arParams['PARAMS']['arUserField']['VALUE'])) { $values = array($values); } $urlManager = \Bitrix\Disk\Driver::getInstance()->getUrlManager(); $versions = array(); foreach ($values as $value) { $attachedObjectId = (int) $value; if ($attachedObjectId <= 0) { continue; } /** @var \Bitrix\Disk\AttachedObject $attachedModel */ $attachedModel = \Bitrix\Disk\AttachedObject::loadById($attachedObjectId, array('VERSION.OBJECT')); if (!$attachedModel) { continue; } $version = $attachedModel->getVersion(); if (!$version) { continue; } $extension = $version->getExtension(); $versions[] = array('ID' => $attachedModel->getId(), 'NAME' => $version->getName(), 'CONVERT_EXTENSION' => DocumentHandler::isNeedConvertExtension($extension), 'EDITABLE' => DocumentHandler::isEditable($extension), 'CAN_UPDATE' => $attachedModel->canUpdate($userId), 'FROM_EXTERNAL_SYSTEM' => $version->getObject()->getContentProvider() && $version->getObject()->getCreatedBy() == $userId, 'EXTENSION' => $extension, 'SIZE' => \CFile::formatSize($version->getSize()), 'HISTORY_URL' => $urlManager->getUrlUfController('history', array('attachedId' => $attachedModel->getId())), 'DOWNLOAD_URL' => $urlManager->getUrlUfController('download', array('attachedId' => $attachedModel->getId())), 'COPY_TO_ME_URL' => $urlManager->getUrlUfController('copyTome', array('attachedId' => $attachedModel->getId())), 'VIEW_URL' => $urlManager->getUrlToShowAttachedFileByService($attachedModel->getId(), 'gvdrive'), 'EDIT_URL' => $urlManager->getUrlToStartEditUfFileByService($attachedModel->getId(), 'gdrive'), 'GLOBAL_CONTENT_VERSION' => $version->getGlobalContentVersion(), 'ATTRIBUTES_FOR_VIEWER' => Ui\Viewer::getAttributesByAttachedObject($attachedModel, array('version' => $version->getGlobalContentVersion(), 'canUpdate' => $attachedModel->canUpdate($userId), 'showStorage' => false, 'externalId' => false, 'relativePath' => false))); } unset($value); return $versions; }
protected function initializeData() { $this->attachedModel = AttachedObject::loadById($this->attachedId, array('OBJECT.STORAGE', 'VERSION')); if (!$this->attachedModel) { $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_UF_DOCUMENT_CONTROLLER_ERROR_COULD_NOT_FIND_ATTACHED_OBJECT'), self::ERROR_COULD_NOT_FIND_ATTACHED_OBJECT))); $this->sendJsonErrorResponse(); } $this->fileId = $this->attachedModel->getObjectId(); $this->file = $this->attachedModel->getFile(); if ($this->attachedModel->getVersionId()) { $this->versionId = $this->attachedModel->getVersionId(); $this->version = $this->attachedModel->getVersion(); } }
/** * @param $id * @return AttachedObject|null */ protected static function getAttachedObjectById($id) { if (!isset(static::$loadedAttachedObjects[$id])) { static::$loadedAttachedObjects[$id] = AttachedObject::loadById($id, array('OBJECT')); } return static::$loadedAttachedObjects[$id]; }
public static function onDelete($userField, $value) { list($type, $realValue) = self::detectType($value); if ($type != self::TYPE_ALREADY_ATTACHED) { return; } $attachedModel = AttachedObject::loadById($realValue); if (!$attachedModel) { return; } $userFieldManager = Driver::getInstance()->getUserFieldManager(); if (!$userFieldManager->belongsToEntity($attachedModel, $userField['ENTITY_ID'], $userField['ENTITY_VALUE_ID'])) { return; } AttachedObject::detachByFilter(array('ID' => $realValue)); }
private function setAutoCommentToAttachedObject($attachedId, $enable) { if ($this->errorCollection->hasErrors()) { return false; } /** @var AttachedObject $attachedModel */ $attachedModel = AttachedObject::loadById((int) $attachedId); if (!$attachedModel) { $this->errorCollection->add(array(new Error('Could not find attached object'))); return false; } if ($attachedModel->getCreatedBy() != $this->getUser()->getId()) { $this->errorCollection->add(array(new Error('Could not disable comments to another attached object'))); return false; } return $enable ? $attachedModel->enableAutoComment() : $attachedModel->disableAutoComment(); }
public static function getObjectId($attachedId) { $attachedId = (int) $attachedId; $attachedModel = AttachedObject::loadById($attachedId, array('OBJECT')); if (!$attachedModel) { return null; } $objectId = $attachedModel->getObjectId(); if (!$objectId) { return null; } return $objectId; }
/** * Clones uf values from entity and creates new files (copies from attach) to save in new entity. * @param array $attachedIds List of attached objects id. * @param int $userId Id of user. * @internal * @return array */ public function cloneUfValuesFromAttachedObject(array $attachedIds, $userId) { $this->errorCollection->clear(); $userId = (int) $userId; if ($userId <= 0) { $this->errorCollection->addOne(new Error('Invalid $userId')); return null; } $userStorage = Driver::getInstance()->getStorageByUserId($userId); if (!$userStorage) { $this->errorCollection->addOne(new Error("Could not find storage for user {$userId}")); $this->errorCollection->add(Driver::getInstance()->getErrors()); return null; } $folder = $userStorage->getFolderForUploadedFiles(); if (!$folder) { $this->errorCollection->addOne(new Error("Could not create/find folder for upload")); $this->errorCollection->add($userStorage->getErrors()); return null; } $newValues = array(); foreach ($attachedIds as $id) { list($type, $realValue) = FileUserType::detectType($id); if (FileUserType::TYPE_ALREADY_ATTACHED != $type) { continue; } $attachedObject = AttachedObject::loadById($realValue, array('OBJECT')); if (!$attachedObject) { continue; } if (!$attachedObject->canRead($userId)) { continue; } $file = $attachedObject->getFile(); if (!$file) { continue; } $newFile = $file->copyTo($folder, $userId, true); if (!$newFile) { $this->errorCollection->add($file->getErrors()); continue; } $newValues[] = FileUserType::NEW_FILE_PREFIX . $newFile->getId(); } return $newValues; }
if (!$arParams['INPUT_NAME']) { showError(GetMessage('MFI_ERR_NO_INPUT_NAME')); return false; } if (!IsModuleInstalled("webdav") && !IsModuleInstalled("disk")) { $arResult['FILES'] = array(); if (is_array($arParams['INPUT_VALUE'])) { $dbRes = CFile::GetList(array(), array("@ID" => implode(",", $arParams["INPUT_VALUE"]))); while ($arFile = $dbRes->GetNext()) { $arFile['URL'] = CHTTP::URN2URI($APPLICATION->GetCurPageParam("mfi_mode=down&fileID=" . $arFile['ID'] . "&cid=" . $arResult['CONTROL_UID'] . "&" . bitrix_sessid_get(), array("mfi_mode", "fileID", "cid"))); $arFile['FILE_SIZE_FORMATTED'] = CFile::FormatSize($arFile['FILE_SIZE']); $arResult['FILES'][$arFile['ID']] = $arFile; $_SESSION["MFU_UPLOADED_FILES_" . $GLOBALS["USER"]->GetId() . "_" . $arResult['CONTROL_UID']][] = $arFile['ID']; } } } if ($arResult["diskEnabled"] && isset($arParams["arAttachedObject"]) && is_array($arParams["arAttachedObject"]) && !empty($arParams["arAttachedObject"])) { $arResult["arAttachedObject"] = array(); foreach ($arParams["arAttachedObject"] as $val) { $oAttachedModel = \Bitrix\Disk\AttachedObject::loadById($val, array('OBJECT.STORAGE', 'VERSION')); if ($oAttachedModel) { $oDiskFile = $oAttachedModel->getFile(); if ($oDiskFile) { $arResult["arAttachedObject"][] = array("ID" => $val, "DISK_FILE_ID" => $oDiskFile->getId()); } } } } CUtil::InitJSCore(array('ajax')); $this->IncludeComponentTemplate(); return $arParams['CONTROL_ID'];
protected function processActionCopyToMe() { $this->checkRequiredGetParams(array('attachedId')); if ($this->errorCollection->hasErrors()) { $this->sendJsonErrorResponse(); } $attachedModel = AttachedObject::loadById((int) $this->request->getQuery('attachedId'), array('OBJECT', 'VERSION')); if (!$attachedModel) { $this->errorCollection->add(array(new Error('Could not find attached object'))); $this->sendJsonErrorResponse(); } if (!$attachedModel->canRead($this->getUser()->getId())) { $this->errorCollection->add(array(new Error("Bad permission. Could not read this file"))); $this->sendJsonErrorResponse(); } $userStorage = Driver::getInstance()->getStorageByUserId($this->getUser()->getId()); if (!$userStorage) { $this->errorCollection->add(array(new Error("Could not find storage for current user"))); $this->sendJsonErrorResponse(); } $folder = $userStorage->getFolderForSavedFiles($this->getUser()->getId()); if (!$folder) { $this->errorCollection->add(array(new Error("Could not find folder for created files"))); $this->sendJsonErrorResponse(); } $file = $attachedModel->getObject(); $newFile = $file->copyTo($folder, $this->getUser()->getId(), true); if (!$newFile) { $this->errorCollection->add(array(new Error("Could not copy file to storage for current user"))); $this->sendJsonErrorResponse(); } $crumbs = array(); foreach ($newFile->getParents(Driver::getInstance()->getFakeSecurityContext()) as $parent) { if ($parent->getId() == $userStorage->getRootObjectId()) { continue; } $crumbs[] = $parent->getName(); } unset($parent); $viewUrl = Driver::getInstance()->getUrlManager()->encodeUrn($userStorage->getProxyType()->getStorageBaseUrl() . 'path/' . implode('/', $crumbs)); $this->sendJsonSuccessResponse(array('newId' => $newFile->getId(), 'viewUrl' => $viewUrl . '#hl-' . $newFile->getId())); }
/** * @param string $documentId - document id. * @return array - document fields array. */ public function GetDocument($documentId) { $documentId = intval($documentId); if ($documentId <= 0) { throw new CBPArgumentNullException("documentId"); } $arResult = null; $dbDocumentList = CIBlockElement::GetList(array(), array("ID" => $documentId, "SHOW_NEW" => "Y", "SHOW_HISTORY" => "Y")); if ($objDocument = $dbDocumentList->GetNextElement(false, true)) { $arDocumentFields = $objDocument->GetFields(); $arDocumentProperties = $objDocument->GetProperties(); foreach ($arDocumentFields as $fieldKey => $fieldValue) { if (substr($fieldKey, 0, 1) == "~") { continue; } $arResult[$fieldKey] = $fieldValue; if (in_array($fieldKey, array("MODIFIED_BY", "CREATED_BY"))) { $arResult[$fieldKey] = "user_" . $fieldValue; $arResult[$fieldKey . "_PRINTABLE"] = $arDocumentFields[$fieldKey == "MODIFIED_BY" ? "USER_NAME" : "CREATED_USER_NAME"]; } elseif (in_array($fieldKey, array("PREVIEW_TEXT", "DETAIL_TEXT"))) { if ($arDocumentFields[$fieldKey . "_TYPE"] == "html") { $arResult[$fieldKey] = HTMLToTxt($arDocumentFields["~" . $fieldKey]); } } } foreach ($arDocumentProperties as $propertyKey => $propertyValue) { if (strlen($propertyValue["USER_TYPE"]) > 0) { if ($propertyValue["USER_TYPE"] == "UserID" || $propertyValue["USER_TYPE"] == "employee" && COption::GetOptionString("bizproc", "employee_compatible_mode", "N") != "Y") { $arPropertyValue = $propertyValue["VALUE"]; $arPropertyKey = isset($propertyValue["VALUE_ENUM_ID"]) ? $propertyValue["VALUE_ENUM_ID"] : $propertyValue["PROPERTY_VALUE_ID"]; if (!is_array($arPropertyValue)) { $db = CUser::GetByID($arPropertyValue); if ($ar = $db->GetNext()) { $arResult["PROPERTY_" . $propertyKey] = "user_" . intval($arPropertyValue); $arResult["PROPERTY_" . $propertyKey . "_PRINTABLE"] = "(" . $ar["LOGIN"] . ")" . (strlen($ar["NAME"]) > 0 || strlen($ar["LAST_NAME"]) > 0 ? " " : "") . $ar["NAME"] . (strlen($ar["NAME"]) > 0 && strlen($ar["LAST_NAME"]) > 0 ? " " : "") . $ar["LAST_NAME"]; } } else { for ($i = 0, $cnt = count($arPropertyValue); $i < $cnt; $i++) { $db = CUser::GetByID($arPropertyValue[$i]); if ($ar = $db->GetNext()) { $arResult["PROPERTY_" . $propertyKey][$arPropertyKey[$i]] = "user_" . intval($arPropertyValue[$i]); $arResult["PROPERTY_" . $propertyKey . "_PRINTABLE"][$arPropertyKey[$i]] = "(" . $ar["LOGIN"] . ")" . (strlen($ar["NAME"]) > 0 || strlen($ar["LAST_NAME"]) > 0 ? " " : "") . $ar["NAME"] . (strlen($ar["NAME"]) > 0 && strlen($ar["LAST_NAME"]) > 0 ? " " : "") . $ar["LAST_NAME"]; } } } } elseif ($propertyValue["USER_TYPE"] == "DiskFile") { if (!CModule::includeModule("disk")) { continue; } if (is_array($propertyValue["VALUE"])) { if ($propertyValue["MULTIPLE"] == "Y") { $propertyValue["VALUE"] = current($propertyValue["VALUE"]); } foreach ($propertyValue["VALUE"] as $attachedId) { $attachedId = (int) $attachedId; $attachedModel = \Bitrix\Disk\AttachedObject::loadById($attachedId, array('OBJECT')); if (!$attachedModel) { continue; } global $USER; $userId = $USER->getID(); if ($userId) { if (!$attachedModel->canRead($userId)) { continue; } } $file = $attachedModel->getFile(); if (!$file) { continue; } $driver = \Bitrix\Disk\Driver::getInstance(); $urlManager = $driver->getUrlManager(); $arResult["PROPERTY_" . $propertyKey][$attachedId] = $urlManager->getUrlUfController('download', array('attachedId' => $attachedModel->getId())); $arResult["PROPERTY_" . $propertyKey . "_PRINTABLE"][$attachedId] = '[url=' . $urlManager->getUrlUfController('download', array('attachedId' => $attachedModel->getId())) . ']' . htmlspecialcharsbx($file->getName()) . '[/url] '; } } else { continue; } } else { $arResult["PROPERTY_" . $propertyKey] = $propertyValue["VALUE"]; } } elseif ($propertyValue["PROPERTY_TYPE"] == "L") { $arPropertyValue = $propertyValue["VALUE"]; $arPropertyKey = self::GetVersion() > 1 ? $propertyValue["VALUE_XML_ID"] : $propertyValue["VALUE_ENUM_ID"]; if (!is_array($arPropertyValue)) { $arPropertyValue = array($arPropertyValue); $arPropertyKey = array($arPropertyKey); } for ($i = 0, $cnt = count($arPropertyValue); $i < $cnt; $i++) { $arResult["PROPERTY_" . $propertyKey][$arPropertyKey[$i]] = $arPropertyValue[$i]; } } elseif ($propertyValue["PROPERTY_TYPE"] == "F") { $arPropertyValue = $propertyValue["VALUE"]; if (!is_array($arPropertyValue)) { $arPropertyValue = array($arPropertyValue); } foreach ($arPropertyValue as $v) { $ar = CFile::GetFileArray($v); if ($ar) { $arResult["PROPERTY_" . $propertyKey][intval($v)] = $ar["SRC"]; $arResult["PROPERTY_" . $propertyKey . "_printable"][intval($v)] = "[url=/bitrix/tools/bizproc_show_file.php?f=" . urlencode($ar["FILE_NAME"]) . "&i=" . $v . "&h=" . md5($ar["SUBDIR"]) . "]" . htmlspecialcharsbx($ar["ORIGINAL_NAME"]) . "[/url]"; } } } else { $arResult["PROPERTY_" . $propertyKey] = $propertyValue["VALUE"]; } } $documentFields = static::GetDocumentFields(static::GetDocumentType($documentId)); foreach ($documentFields as $fieldKey => $field) { if (!array_key_exists($fieldKey, $arResult)) { $arResult[$fieldKey] = null; } } } return $arResult; }
public static function clearValueSingle(FieldType $fieldType, $value) { if (!Loader::includeModule('disk')) { return; } $value = (int) $value; if (!$value) { return; } $documentType = $fieldType->getDocumentType(); $iblockId = intval(substr($documentType[2], strlen("iblock_"))); if (!$iblockId) { return; } $userFieldManager = \Bitrix\Disk\Driver::getInstance()->getUserFieldManager(); list($type, $realId) = \Bitrix\Disk\Uf\FileUserType::detectType($value); if ($type == \Bitrix\Disk\Uf\FileUserType::TYPE_ALREADY_ATTACHED) { $attachedModel = \Bitrix\Disk\AttachedObject::loadById($realId); if (!$attachedModel) { return; } if ($userFieldManager->belongsToEntity($attachedModel, "iblock_workflow", $iblockId)) { \Bitrix\Disk\AttachedObject::detachByFilter(array('ID' => $realId)); } } }
$_SESSION["MFU_UPLOADED_FILES_" . $GLOBALS["USER"]->GetId() . "_" . intval($_REQUEST["post_id"])] = $arPostField["VALUE"]; } elseif ($FIELD_NAME == "UF_BLOG_POST_FILE") { if ($arResult["diskEnabled"]) { $_SESSION["MFU_UPLOADED_DOCS_" . $GLOBALS["USER"]->GetId() . "_" . intval($_REQUEST["post_id"])] = array(); if (is_array($arPostField["VALUE"])) { foreach ($arPostField["VALUE"] as $val) { $oAttachedModel = \Bitrix\Disk\AttachedObject::loadById($val, array('OBJECT.STORAGE', 'VERSION')); if ($oAttachedModel) { $oDiskFile = $oAttachedModel->getFile(); if ($oDiskFile) { $_SESSION["MFU_UPLOADED_DOCS_" . $GLOBALS["USER"]->GetId() . "_" . intval($_REQUEST["post_id"])][] = $oDiskFile->getId(); } } } } elseif (intval($arPostField["VALUE"]) > 0) { $oAttachedModel = \Bitrix\Disk\AttachedObject::loadById($arPostField["VALUE"], array('OBJECT.STORAGE', 'VERSION')); if ($oAttachedModel) { $oDiskFile = $oAttachedModel->getFile(); if ($oDiskFile) { $rsFile = CFile::GetByID($oDiskFile->getFileId()); if ($arFile = $rsFile->Fetch()) { $_SESSION["MFU_UPLOADED_DOCS_" . $GLOBALS["USER"]->GetId() . "_" . intval($_REQUEST["post_id"])] = array($arFile["ID"]); } } } } } else { $_SESSION["MFU_UPLOADED_DOCS_" . $GLOBALS["USER"]->GetId() . "_" . intval($_REQUEST["post_id"])] = $arPostField["VALUE"]; } } }