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; }
private function getGridData($gridId, $showDeleted = false) { $grid = array('ID' => $gridId); $gridOptions = new CGridOptions($grid['ID']); $gridSort = $gridOptions->getSorting(array('sort' => array('NAME' => 'ASC'), 'vars' => array('by' => 'by', 'order' => 'order'))); $filter = array(); $grid['SORT'] = $gridSort['sort']; $grid['SORT_VARS'] = $gridSort['vars']; $grid['MODE'] = $this->getViewMode(); $possibleColumnForSorting = array('UPDATE_TIME' => array('ALIAS' => 'UPDATE_TIME', 'LABEL' => Loc::getMessage('DISK_FOLDER_LIST_SORT_BY_UPDATE_TIME')), 'NAME' => array('ALIAS' => 'NAME', 'LABEL' => Loc::getMessage('DISK_FOLDER_LIST_SORT_BY_NAME')), 'FORMATTED_SIZE' => array('ALIAS' => 'SIZE', 'LABEL' => Loc::getMessage('DISK_FOLDER_LIST_SORT_BY_FORMATTED_SIZE'))); $byColumn = key($grid['SORT']); if (!isset($possibleColumnForSorting[$byColumn]) || strtolower($grid['SORT'][$byColumn]) !== 'desc' && strtolower($grid['SORT'][$byColumn]) !== 'asc') { $grid['SORT'] = array(); } $order = $grid['SORT']; $byColumn = key($order); $sortingColumns = array('TYPE' => array(SORT_NUMERIC, SORT_ASC), $possibleColumnForSorting[$byColumn]['ALIAS'] => strtolower($order[$byColumn]) === 'asc' ? SORT_ASC : SORT_DESC); if ($byColumn !== 'NAME') { $sortingColumns[$possibleColumnForSorting['NAME']['ALIAS']] = SORT_ASC; } $securityContext = $this->storage->getCurrentUserSecurityContext(); $proxyType = $this->storage->getProxyType(); $isStorageCurrentUser = $proxyType instanceof ProxyType\User && $proxyType->getTitleForCurrentUser() != $proxyType->getTitle(); $parameters = array('with' => array('CREATE_USER'), 'filter' => array('PARENT_ID' => $this->folder->getRealObjectId(), 'DELETED_TYPE' => ObjectTable::DELETED_TYPE_NONE)); $parameters = Driver::getInstance()->getRightsManager()->addRightsCheck($securityContext, $parameters, array('ID', 'CREATED_BY')); $needPagination = $this->needPagination(); $pageNumber = (int) $this->request->getQuery('pageNumber'); if ($pageNumber <= 0) { $pageNumber = 1; } if ($needPagination) { $parameters['order'] = array(); foreach ($sortingColumns as $columnName => $columnData) { if (is_array($columnData)) { $parameters['order'][$columnName] = in_array(SORT_DESC, $columnData, true) ? 'DESC' : 'ASC'; } else { $parameters['order'][$columnName] = SORT_DESC === $columnData ? 'DESC' : 'ASC'; } } unset($columnName, $columnData); $parameters['limit'] = self::COUNT_ON_PAGE + 1; // +1 because we want to know about existence next page $parameters['offset'] = self::COUNT_ON_PAGE * ($pageNumber - 1); } $this->folder->preloadOperationsForChildren($securityContext); $sharedObjectIds = $this->getUserShareObjectIds(); $isDesktopDiskInstall = \Bitrix\Disk\Desktop::isDesktopDiskInstall(); $nowTime = time() + CTimeZone::getOffset(); $fullFormatWithoutSec = preg_replace('/:s$/', '', CAllDatabase::dateFormatToPHP(CSite::GetDateFormat("FULL"))); $urlManager = Driver::getInstance()->getUrlManager(); $rows = array(); $storageTitle = $proxyType->getTitle(); $isEnabledShowExtendedRights = $this->storage->isEnabledShowExtendedRights(); $result = $this->folder->getList($parameters); $countObjectsOnPage = 0; $needShowNextPagePagination = false; while ($row = $result->fetch()) { $countObjectsOnPage++; if ($needPagination && $countObjectsOnPage > self::COUNT_ON_PAGE) { $needShowNextPagePagination = true; break; } $object = BaseObject::buildFromArray($row); /** @var File|Folder $object */ $name = $object->getName(); $objectId = $object->getId(); $exportData = array('TYPE' => $object->getType(), 'NAME' => $name, 'ID' => $objectId); $relativePath = trim($this->arParams['RELATIVE_PATH'], '/'); $detailPageFile = CComponentEngine::makePathFromTemplate($this->arParams['PATH_TO_FILE_VIEW'], array('FILE_ID' => $objectId, 'FILE_PATH' => ltrim($relativePath . '/' . $name, '/'))); $listingPage = rtrim(CComponentEngine::makePathFromTemplate($this->arParams['PATH_TO_FOLDER_LIST'], array('PATH' => $relativePath)), '/'); $isFolder = $object instanceof Folder; $actions = $tileActions = $columns = array(); if ($object->canRead($securityContext)) { $exportData['OPEN_URL'] = $urlManager->encodeUrn($isFolder ? $listingPage . '/' . $name . '/' : $detailPageFile); $actions[] = array("PSEUDO_NAME" => "open", "DEFAULT" => true, "ICONCLASS" => "show", "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_ACT_OPEN'), "ONCLICK" => "jsUtils.Redirect(arguments, '" . $exportData['OPEN_URL'] . "')"); if (!$object->canChangeRights($securityContext) && !$object->canShare($securityContext)) { $actions[] = array("PSEUDO_NAME" => "share", "ICONCLASS" => "share", "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_ACT_SHOW_SHARING_DETAIL_2'), "ONCLICK" => "BX.Disk.showSharingDetailWithoutEdit({\n\t\t\t\t\t\t\t\tajaxUrl: '/bitrix/components/bitrix/disk.folder.list/ajax.php',\n\t\t\t\t\t\t\t\tobject: {\n\t\t\t\t\t\t\t\t\tid: {$objectId},\n\t\t\t\t\t\t\t\t\tname: '{$name}',\n\t\t\t\t\t\t\t\t\tisFolder: " . ($isFolder ? 'true' : 'false') . "\n\t\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t})"); } elseif ($object->canChangeRights($securityContext)) { $actions[] = array("PSEUDO_NAME" => "share", "ICONCLASS" => "share", "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_ACT_SHOW_SHARING_DETAIL_2'), "ONCLICK" => "BX.Disk['FolderListClass_{$this->componentId}'].showSharingDetailWithChangeRights({\n\t\t\t\t\t\t\t\tajaxUrl: '/bitrix/components/bitrix/disk.folder.list/ajax.php',\n\t\t\t\t\t\t\t\tobject: {\n\t\t\t\t\t\t\t\t\tid: {$objectId},\n\t\t\t\t\t\t\t\t\tname: '{$name}',\n\t\t\t\t\t\t\t\t\tisFolder: " . ($isFolder ? 'true' : 'false') . "\n\t\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t})"); } elseif ($object->canShare($securityContext)) { $actions[] = array("PSEUDO_NAME" => "share", "ICONCLASS" => "share", "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_ACT_SHOW_SHARING_DETAIL_2'), "ONCLICK" => "BX.Disk['FolderListClass_{$this->componentId}'].showSharingDetailWithSharing({\n\t\t\t\t\t\t\t\tajaxUrl: '/bitrix/components/bitrix/disk.folder.list/ajax.php',\n\t\t\t\t\t\t\t\tobject: {\n\t\t\t\t\t\t\t\t\tid: {$objectId},\n\t\t\t\t\t\t\t\t\tname: '{$name}',\n\t\t\t\t\t\t\t\t\tisFolder: " . ($isFolder ? 'true' : 'false') . "\n\t\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t})"); } if ($isEnabledShowExtendedRights && !$object->isLink() && $object->canChangeRights($securityContext)) { $actions[] = array("PSEUDO_NAME" => "rights", "ICONCLASS" => "rights", "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_ACT_RIGHTS_SETTINGS'), "ONCLICK" => "BX.Disk['FolderListClass_{$this->componentId}'].showRightsOnObjectDetail({\n\t\t\t\t\t\t\t\tobject: {\n\t\t\t\t\t\t\t\t\tid: {$objectId},\n\t\t\t\t\t\t\t\t\tname: '{$name}',\n\t\t\t\t\t\t\t\t\tisFolder: " . ($isFolder ? 'true' : 'false') . "\n\t\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t})"); } if (!$isFolder) { $actions[] = array("PSEUDO_NAME" => "download", "ICONCLASS" => "download", "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_ACT_DOWNLOAD'), "ONCLICK" => "jsUtils.Redirect(arguments, '" . $urlManager->getUrlForDownloadFile($object) . "')"); } $actions[] = array("PSEUDO_NAME" => "copy", "ICONCLASS" => "copy", "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_ACT_COPY'), "ONCLICK" => "BX.Disk['FolderListClass_{$this->componentId}'].openCopyModalWindow({\n\t\t\t\t\t\tid: {$this->storage->getRootObjectId()},\n\t\t\t\t\t\tname: '" . CUtil::JSEscape($storageTitle) . "'\n\t\t\t\t\t}, {\n\t\t\t\t\t\tid: {$objectId},\n\t\t\t\t\t\tname: '" . CUtil::JSEscape($name) . "'\n\t\t\t\t\t});"); if ($object->canDelete($securityContext)) { $actions[] = array("PSEUDO_NAME" => "move", "ICONCLASS" => "move", "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_ACT_MOVE'), "ONCLICK" => "BX.Disk['FolderListClass_{$this->componentId}'].openMoveModalWindow({\n\t\t\t\t\t\t\tid: {$this->storage->getRootObjectId()},\n\t\t\t\t\t\t\tname: '" . CUtil::JSEscape($storageTitle) . "'\n\t\t\t\t\t\t}, {\n\t\t\t\t\t\t\tid: {$objectId},\n\t\t\t\t\t\t\tname: '" . CUtil::JSEscape($name) . "'\n\t\t\t\t\t\t});"); } if (!$isStorageCurrentUser && (!isset($sharedObjectIds[$object->getRealObjectId()]) || $sharedObjectIds[$object->getRealObjectId()]['TO_ENTITY'] != Sharing::CODE_USER . $this->getUser()->getId())) { $actions[] = array("PSEUDO_NAME" => "connect", "ICONCLASS" => "connect", "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_ACT_CONNECT'), "ONCLICK" => "BX.Disk['FolderListClass_{$this->componentId}'].connectObjectToDisk({\n\t\t\t\t\t\t\tobject: {\n\t\t\t\t\t\t\t\tid: {$objectId},\n\t\t\t\t\t\t\t\tname: '" . CUtil::JSEscape($name) . "',\n\t\t\t\t\t\t\t\tisFolder: " . ($isFolder ? 'true' : 'false') . "\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});"); } if (!$isFolder) { $actions[] = array("ICONCLASS" => "show", "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_ACT_GET_EXT_LINK'), "ONCLICK" => "BX.Disk['FolderListClass_{$this->componentId}'].getExternalLink({$objectId});"); $downloadLink = $urlManager->getUrlForShowFile($object, array(), true); $actions[] = array("ICONCLASS" => "show", 'PSEUDO_NAME' => 'internal_link', 'PSEUDO_VALUE' => $downloadLink, "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_ACT_COPY_INTERNAL_LINK'), "ONCLICK" => "BX.Disk['FolderListClass_{$this->componentId}'].getInternalLink('{$downloadLink}');"); $actions[] = array("ICONCLASS" => "history", "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_ACT_SHOW_HISTORY'), "ONCLICK" => "jsUtils.Redirect(arguments, '" . $exportData['OPEN_URL'] . "#tab-history')"); } } if ($object->canRename($securityContext)) { $actions[] = array("TEXT" => Loc::getMessage('DISK_FOLDER_LIST_ACT_RENAME'), "ONCLICK" => "BX.Disk['FolderListClass_{$this->componentId}'].renameInline({$objectId})"); } if ((!empty($sharedObjectIds[$objectId]) || $object->isLink()) && $object->canRead($securityContext)) { $tileActions['SHARE_INFO'] = array("ICONCLASS" => "show", "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_DETAIL_SHARE_INFO'), "ONCLICK" => "BX.Disk['FolderListClass_{$this->componentId}'].showShareInfoSmallView({\n\t\t\t\t\t\tobject: {\n\t\t\t\t\t\t\tid: {$objectId},\n\t\t\t\t\t\t\tname: '{$name}',\n\t\t\t\t\t\t\tisFolder: " . ($isFolder ? 'true' : 'false') . "\n\t\t\t\t\t\t }\n\t\t\t\t\t})"); } $columnsBizProc = array('BIZPROC' => ''); $bizprocIcon = array('BIZPROC' => ''); if ($this->arParams['STATUS_BIZPROC'] && !$isFolder) { list($actions, $columnsBizProc, $bizprocIcon) = $this->getBizProcData($object, $securityContext, $actions, $columnsBizProc, $bizprocIcon, $exportData); } if ($object->canDelete($securityContext)) { if ($object->isLink()) { $actions[] = array("PSEUDO_NAME" => "detach", "ICONCLASS" => "detach", "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_DETACH_BUTTON'), "ONCLICK" => "BX.Disk['FolderListClass_{$this->componentId}'].openConfirmDetach({\n\t\t\t\t\t\t\t\tobject: {\n\t\t\t\t\t\t\t\t\tid: {$objectId},\n\t\t\t\t\t\t\t\t\tname: '{$name}',\n\t\t\t\t\t\t\t\t\tisFolder: " . ($isFolder ? 'true' : 'false') . "\n\t\t\t\t\t\t\t\t }\n\t\t\t\t\t\t\t})"); } elseif ($object->getCode() !== Folder::CODE_FOR_UPLOADED_FILES) { $actions[] = array("PSEUDO_NAME" => "delete", "ICONCLASS" => "delete", "TEXT" => Loc::getMessage('DISK_FOLDER_LIST_ACT_MARK_DELETED'), "ONCLICK" => "BX.Disk['FolderListClass_{$this->componentId}'].openConfirmDelete({\n\t\t\t\t\t\t\t\tobject: {\n\t\t\t\t\t\t\t\t\tid: {$objectId},\n\t\t\t\t\t\t\t\t\tname: '{$name}',\n\t\t\t\t\t\t\t\t\tisFolder: " . ($isFolder ? 'true' : 'false') . "\n\t\t\t\t\t\t\t\t },\n\t\t\t\t\t\t\t\tcanDelete: {$object->canDelete($securityContext)}\n\t\t\t\t\t\t\t})"); } } $iconClass = Ui\Icon::getIconClassByObject($object, !empty($sharedObjectIds[$objectId])); $dataAttributesForViewer = ''; if ($isFolder) { $dataAttributesForViewer = Ui\Viewer::getAttributesByObject($object); if ($grid['MODE'] === 'tile') { $exportData['VIEWER_ATTRS'] = $dataAttributesForViewer; $dataAttributesForViewer = ''; } $nameSpecialChars = htmlspecialcharsbx($name); $columnName = "\n\t\t\t\t\t<table class=\"bx-disk-object-name\"><tr>\n\t\t\t\t\t\t\t<td style=\"width: 45px;\"><div data-object-id=\"{$objectId}\" class=\"draggable bx-file-icon-container-small {$iconClass}\"></div></td>\n\t\t\t\t\t\t\t<td><a class=\"bx-disk-folder-title\" id=\"disk_obj_{$objectId}\" href=\"{$exportData['OPEN_URL']}\" {$dataAttributesForViewer}>{$nameSpecialChars}</a></td>\n\t\t\t\t\t</tr></table>\n\t\t\t\t"; } else { $externalId = ''; if ($isDesktopDiskInstall && $isStorageCurrentUser) { $externalId = "st{$this->storage->getId()}|{$this->storage->getRootObjectId()}|f{$objectId}"; } $dataAttributesForViewer = Ui\Viewer::getAttributesByObject($object, array('canUpdate' => $object->canUpdate($securityContext), 'relativePath' => $relativePath . '/' . $name, 'externalId' => $externalId)); if ($grid['MODE'] === 'tile') { $exportData['VIEWER_ATTRS'] = $dataAttributesForViewer; $dataAttributesForViewer = ''; } $nameSpecialChars = htmlspecialcharsbx($name); $columnName = "\n\t\t\t\t\t<table class=\"bx-disk-object-name\"><tr>\n\t\t\t\t\t\t<td style=\"width: 45px;\"><div data-object-id=\"{$objectId}\" class=\"draggable bx-file-icon-container-small {$iconClass}\"></div></td>\n\t\t\t\t\t\t<td><a class=\"bx-disk-folder-title\" id=\"disk_obj_{$objectId}\" href=\"{$exportData['OPEN_URL']}\" {$dataAttributesForViewer}>{$nameSpecialChars}</a></td>\n\t\t\t\t\t\t<td>{$bizprocIcon['BIZPROC']}</td>\n\t\t\t\t\t</tr></table>\n\t\t\t\t"; } $createdByLink = \CComponentEngine::makePathFromTemplate($this->arParams['PATH_TO_USER'], array("user_id" => $object->getCreatedBy())); $timestampCreate = $object->getCreateTime()->toUserTime()->getTimestamp(); $timestampUpdate = $object->getUpdateTime()->toUserTime()->getTimestamp(); $columns = array('CREATE_TIME' => $nowTime - $timestampCreate > 158400 ? formatDate($fullFormatWithoutSec, $timestampCreate, $nowTime) : formatDate('x', $timestampCreate, $nowTime), 'UPDATE_TIME' => $nowTime - $timestampCreate > 158400 ? formatDate($fullFormatWithoutSec, $timestampUpdate, $nowTime) : formatDate('x', $timestampUpdate, $nowTime), 'NAME' => $columnName, 'FORMATTED_SIZE' => $isFolder ? '' : CFile::formatSize($object->getSize()), 'CREATE_USER' => "\n\t\t\t\t\t<div class=\"bx-disk-user-link\"><a target='_blank' href=\"{$createdByLink}\" id=\"\">" . htmlspecialcharsbx($object->getCreateUser()->getFormattedName()) . "</a></div>\n\t\t\t\t"); if ($this->arParams['STATUS_BIZPROC']) { $columns['BIZPROC'] = $columnsBizProc["BIZPROC"]; } $exportData['ICON_CLASS'] = $iconClass; if ($grid['MODE'] === 'tile') { $exportData['IS_IMAGE'] = $isFolder ? false : \Bitrix\Disk\TypeFile::isImage($object); if ($exportData['IS_IMAGE']) { $exportData['SRC_IMAGE'] = $urlManager->getUrlForShowFile($object, array('exact' => 'Y', 'width' => 64, 'height' => 64)); } $exportData['UPDATE_TIME'] = $columns['UPDATE_TIME']; } $exportData['IS_SHARED'] = !empty($sharedObjectIds[$objectId]); $exportData['IS_LINK'] = $object->isLink(); $tildaExportData = array(); foreach ($exportData as $exportName => $exportValue) { $tildaExportData['~' . $exportName] = $exportValue; } unset($exportRow); $rows[] = array('data' => array_merge($exportData, $tildaExportData), 'columns' => $columns, 'actions' => $actions, 'tileActions' => $tileActions, 'TYPE' => $exportData['TYPE'], 'NAME' => $exportData['NAME'], 'UPDATE_TIME' => $object->getUpdateTime()->getTimestamp(), 'SIZE' => $isFolder ? 0 : $object->getSize()); } unset($object); if (!$needPagination) { Collection::sortByColumn($rows, $sortingColumns); } $grid['HEADERS'] = array(array('id' => 'ID', 'name' => 'ID', 'sort' => isset($possibleColumnForSorting['ID']) ? 'ID' : false, 'default' => false), array('id' => 'NAME', 'name' => Loc::getMessage('DISK_FOLDER_LIST_COLUMN_NAME'), 'sort' => isset($possibleColumnForSorting['NAME']) ? 'NAME' : false, 'default' => true, 'editable' => array('size' => 45)), array('id' => 'CREATE_TIME', 'name' => Loc::getMessage('DISK_FOLDER_LIST_COLUMN_CREATE_TIME'), 'sort' => isset($possibleColumnForSorting['CREATE_TIME']) ? 'CREATE_TIME' : false, 'default' => false), array('id' => 'UPDATE_TIME', 'name' => Loc::getMessage('DISK_FOLDER_LIST_COLUMN_UPDATE_TIME'), 'sort' => isset($possibleColumnForSorting['UPDATE_TIME']) ? 'UPDATE_TIME' : false, 'default' => true), array('id' => 'CREATE_USER', 'name' => Loc::getMessage('DISK_FOLDER_LIST_COLUMN_CREATE_USER'), 'sort' => isset($possibleColumnForSorting['CREATE_USER']) ? 'CREATE_USER' : false, 'default' => false), array('id' => 'FORMATTED_SIZE', 'name' => Loc::getMessage('DISK_FOLDER_LIST_COLUMN_FORMATTED_SIZE'), 'sort' => isset($possibleColumnForSorting['FORMATTED_SIZE']) ? 'FORMATTED_SIZE' : false, 'default' => true)); if ($this->arParams['STATUS_BIZPROC']) { $grid['HEADERS'][] = array('id' => 'BIZPROC', 'name' => Loc::getMessage('DISK_FOLDER_LIST_COLUMN_BIZPROC'), 'default' => false); } $grid['DATA_FOR_PAGINATION'] = array('ENABLED' => $needPagination); if ($needPagination) { $grid['DATA_FOR_PAGINATION']['SHOW_NEXT_PAGE'] = $needShowNextPagePagination; $grid['DATA_FOR_PAGINATION']['CURRENT_PAGE'] = $pageNumber; } $grid['COLUMN_FOR_SORTING'] = $possibleColumnForSorting; $grid['ROWS'] = $rows; $grid['ROWS_COUNT'] = count($rows); $grid['FOOTER'] = array(); if (isModuleInstalled('bitrix24')) { list($freeSpace, $diskSize) = $this->getDiskSpace(); $freeSpace = CFile::formatSize($freeSpace); $diskSize = CFile::formatSize($diskSize); $grid['FOOTER'] = array(array('custom_html' => ' <td class="tar" style="width: 100%;">' . Loc::getMessage('DISK_FOLDER_LIST_B24_LABEL_DISK_SPACE', array('#FREE_SPACE#' => '<span>' . $freeSpace, '#DISK_SIZE#' => $diskSize . '</span>')) . '</span></td> '), array('custom_html' => ' <td class="tar"><a class="bx-disk-mp-link-addhdd" href="' . Loc::getMessage('DISK_FOLDER_LIST_B24_URL_DISK_SPACE') . '" target="_blank">+ <span>' . Loc::getMessage('DISK_FOLDER_LIST_B24_APPEND_DISK_SPACE') . '</span></a></td> ')); } return $grid; }
private function loadFilesData() { 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); } $files = array(); $driver = \Bitrix\Disk\Driver::getInstance(); $urlManager = $driver->getUrlManager(); $userFieldManager = $driver->getUserFieldManager(); $userFieldManager->loadBatchAttachedObject($values); foreach ($values as $id) { $attachedModel = null; list($type, $realValue) = FileUserType::detectType($id); if ($realValue <= 0) { continue; } elseif ($type == FileUserType::TYPE_NEW_OBJECT) { /** @var File $fileModel */ $fileModel = File::loadById($realValue); if (!$fileModel || !$fileModel->canRead($fileModel->getStorage()->getCurrentUserSecurityContext())) { continue; } } else { /** @var \Bitrix\Disk\AttachedObject $attachedModel */ $attachedModel = $userFieldManager->getAttachedObjectById($realValue); if (!$attachedModel) { continue; } if (!$this->editMode) { $attachedModel->setOperableEntity(array('ENTITY_ID' => $this->arParams['PARAMS']['arUserField']['ENTITY_ID'], 'ENTITY_VALUE_ID' => $this->arParams['PARAMS']['arUserField']['ENTITY_VALUE_ID'])); } /** @var File $fileModel */ $fileModel = $attachedModel->getFile(); } $name = $fileModel->getName(); $data = array('ID' => $id, 'NAME' => $name, 'CONVERT_EXTENSION' => DocumentHandler::isNeedConvertExtension($fileModel->getExtension()), 'EDITABLE' => DocumentHandler::isEditable($fileModel->getExtension()), 'CAN_UPDATE' => $attachedModel ? $attachedModel->canUpdate($userId) : $fileModel->canUpdate($fileModel->getStorage()->getCurrentUserSecurityContext()), 'FROM_EXTERNAL_SYSTEM' => $fileModel->getContentProvider() && $fileModel->getCreatedBy() == $userId, 'EXTENSION' => $fileModel->getExtension(), 'SIZE' => \CFile::formatSize($fileModel->getSize()), 'XML_ID' => $fileModel->getXmlId(), 'FILE_ID' => $fileModel->getId(), 'VIEW_URL' => $urlManager->getUrlToShowAttachedFileByService($id, 'gvdrive'), 'EDIT_URL' => $urlManager->getUrlToStartEditUfFileByService($id, 'gdrive'), 'DOWNLOAD_URL' => $urlManager->getUrlUfController('download', array('attachedId' => $id)), 'COPY_TO_ME_URL' => $urlManager->getUrlUfController('copyToMe', array('attachedId' => $id)), 'DELETE_URL' => ""); if (\Bitrix\Disk\TypeFile::isImage($fileModel)) { $this->arParams['PARAMS']['THUMB_SIZE'] = $this->arParams['PARAMS']['THUMB_SIZE'] > 0 ? $this->arParams['PARAMS']['THUMB_SIZE'] : 100; $data["PREVIEW_URL"] = $attachedModel === null ? $urlManager->getUrlForShowFile($fileModel) : $urlManager->getUrlUfController('show', array('attachedId' => $id)); $data["IMAGE"] = $fileModel->getFile(); } if ($this->editMode) { $data['STORAGE'] = $fileModel->getStorage()->getProxyType()->getTitleForCurrentUser() . ' / ' . $fileModel->getParent()->getName(); } else { $data['ATTRIBUTES_FOR_VIEWER'] = Ui\Viewer::getAttributesByAttachedObject($attachedModel, array('canUpdate' => $data['CAN_UPDATE'], 'canFakeUpdate' => true, 'showStorage' => false, 'externalId' => false, 'relativePath' => false)); } $files[] = $data; } unset($id); return $files; }
/** * Gets data attributes by attached object to viewer. * @param AttachedObject $attachedObject Target attached object. * @param array $additionalParams Additional parameters 'relativePath', 'externalId', 'canUpdate', 'canFakeUpdate', 'showStorage', 'version'. * @return string */ public static function getAttributesByAttachedObject(AttachedObject $attachedObject, array $additionalParams = array()) { $urlManager = Driver::getInstance()->getUrlManager(); $version = $object = null; if ($attachedObject->isSpecificVersion()) { $version = $attachedObject->getVersion(); if (!$version) { return ''; } $name = $version->getName(); $extension = $version->getExtension(); $size = $version->getSize(); $updateTime = $version->getCreateTime(); } else { $object = $attachedObject->getObject(); if (!$object) { return ''; } $name = $object->getName(); $extension = $object->getExtension(); $size = $object->getSize(); $updateTime = $object->getUpdateTime(); } if (DocumentHandler::isEditable($extension)) { $dataAttributesForViewer = 'data-bx-viewer="iframe" ' . 'data-bx-title="' . htmlspecialcharsbx($name) . '" ' . 'data-bx-src="' . $urlManager->getUrlToShowAttachedFileByService($attachedObject->getId(), 'gvdrive') . '" ' . 'data-bx-isFromUserLib="" ' . 'data-bx-askConvert="' . (DocumentHandler::isNeedConvertExtension($extension) ? '1' : '') . '" ' . 'data-bx-download="' . $urlManager->getUrlUfController('download', array('attachedId' => $attachedObject->getId())) . '" ' . 'data-bx-size="' . htmlspecialcharsbx(CFile::formatSize($size)) . '" '; } elseif (Viewer::isViewable($extension)) { $dataAttributesForViewer = 'data-bx-viewer="iframe" ' . 'data-bx-title="' . htmlspecialcharsbx($name) . '" ' . 'data-bx-src="' . $urlManager->getUrlToShowAttachedFileByService($attachedObject->getId(), 'gvdrive') . '" ' . 'data-bx-isFromUserLib="" ' . 'data-bx-askConvert="0" ' . 'data-bx-download="' . $urlManager->getUrlUfController('download', array('attachedId' => $attachedObject->getId())) . '" ' . 'data-bx-size="' . htmlspecialcharsbx(CFile::formatSize($size)) . '" ' . 'data-bx-dateModify="' . htmlspecialcharsbx($updateTime) . '" '; } elseif (TypeFile::isImage($name)) { $dataAttributesForViewer = 'data-bx-viewer="image" ' . 'data-bx-title="' . htmlspecialcharsbx($name) . '" ' . 'data-bx-src="' . $urlManager->getUrlUfController('download', array('attachedId' => $attachedObject->getId())) . '" ' . 'data-bx-isFromUserLib="" ' . 'data-bx-download="' . $urlManager->getUrlUfController('download', array('attachedId' => $attachedObject->getId())) . '" '; } else { $user = $version ? $version->getCreateUser() : $object->getCreateUser(); $formattedName = $user ? $user->getFormattedName() : ''; $dataAttributesForViewer = 'data-bx-viewer="unknown" ' . 'data-bx-src="' . $urlManager->getUrlUfController('download', array('attachedId' => $attachedObject->getId())) . '" ' . 'data-bx-isFromUserLib="" ' . 'data-bx-download="' . $urlManager->getUrlUfController('download', array('attachedId' => $attachedObject->getId())) . '" ' . 'data-bx-title="' . htmlspecialcharsbx($name) . '" ' . 'data-bx-owner="' . htmlspecialcharsbx($formattedName) . '" ' . 'data-bx-dateModify="' . htmlspecialcharsbx($updateTime) . '" ' . 'data-bx-size="' . htmlspecialcharsbx(CFile::formatSize($size)) . '" '; } $dataAttributesForViewer .= " data-bx-history=\"\"" . " data-bx-historyPage=\"\""; if ($object) { $dataAttributesForViewer .= " bx-attach-file-id=\"{$object->getId()}\""; } if (!empty($additionalParams['relativePath'])) { $dataAttributesForViewer .= ' data-bx-relativePath="' . htmlspecialcharsbx($additionalParams['relativePath'] . '/' . $name) . '" '; } if (!empty($additionalParams['externalId'])) { $dataAttributesForViewer .= ' data-bx-externalId="' . htmlspecialcharsbx($additionalParams['externalId']) . '" '; } if (!empty($additionalParams['canUpdate'])) { $dataAttributesForViewer .= ' data-bx-edit="' . $urlManager->getUrlToStartEditUfFileByService($attachedObject->getId(), 'gdrive') . '" '; } if (!empty($additionalParams['canFakeUpdate'])) { $dataAttributesForViewer .= ' data-bx-fakeEdit="' . $urlManager->getUrlToStartEditUfFileByService($attachedObject->getId(), 'gdrive') . '" '; } if (!empty($additionalParams['showStorage']) && $object) { $dataAttributesForViewer .= ' data-bx-storage="' . htmlspecialcharsbx($object->getParent()->getName()) . '" '; } if (!empty($additionalParams['version'])) { $dataAttributesForViewer .= ' data-bx-version="' . htmlspecialcharsbx($additionalParams['version']) . '" '; } return $dataAttributesForViewer; }
private function getVersionGridData($gridId) { $grid = array('ID' => $gridId); $gridOptions = new CGridOptions($grid['ID']); $gridSort = $gridOptions->getSorting(array('sort' => array('ID' => 'desc'), 'vars' => array('by' => 'by', 'order' => 'order'))); $grid['SORT'] = $gridSort['sort']; $grid['SORT_VARS'] = $gridSort['vars']; $this->arResult['ITEMS'] = $this->file->getVersions(array('with' => array('CREATE_USER'), 'order' => $gridSort['sort'])); $urlManager = \Bitrix\Disk\Driver::getInstance()->getUrlManager(); $rows = array(); foreach ($this->arResult['ITEMS'] as $version) { /** @var $version Version */ $objectArray = $version->toArray(); $actions = array(array("ICONCLASS" => "download", "TEXT" => Loc::getMessage('DISK_FILE_VIEW_HISTORY_ACT_DOWNLOAD'), "DEFAULT" => true, "ONCLICK" => "jsUtils.Redirect(arguments, '" . $urlManager->getUrlForDownloadVersion($version) . "')")); $securityContext = $this->storage->getCurrentUserSecurityContext(); if ($this->file->canRestore($securityContext)) { $actions[] = array("ICONCLASS" => "restore", "TEXT" => Loc::getMessage('DISK_FILE_VIEW_HISTORY_ACT_RESTORE'), "DEFAULT" => true, "ONCLICK" => "BX.Disk['FileViewClass_{$this->getComponentId()}'].openConfirmRestore({\n\t\t\t\t\t\t\tobject: {\n\t\t\t\t\t\t\t\tid: {$this->file->getId()},\n\t\t\t\t\t\t\t\tname: '{$this->file->getName()}'\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tversion: {\n\t\t\t\t\t\t\t\tid: {$version->getId()}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t})"); } if ($this->file->canRestore($securityContext) && $this->file->canDelete($securityContext)) { $actions[] = array("ICONCLASS" => "delete", "TEXT" => Loc::getMessage('DISK_FILE_VIEW_HISTORY_ACT_DELETE'), "DEFAULT" => true, "ONCLICK" => "BX.Disk['FileViewClass_{$this->getComponentId()}'].openConfirmDeleteVersion({\n\t\t\t\t\t\t\tobject: {\n\t\t\t\t\t\t\t\tid: {$this->file->getId()},\n\t\t\t\t\t\t\t\tname: '{$this->file->getName()}'\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tversion: {\n\t\t\t\t\t\t\t\tid: {$version->getId()}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t})"); } $createdByLink = \CComponentEngine::makePathFromTemplate($this->arParams['PATH_TO_USER'], array("user_id" => $version->getCreatedBy())); $dataAttributesForViewer = Ui\Viewer::getAttributesByVersion($version); $rows[] = array('data' => $objectArray, 'columns' => array('FORMATTED_SIZE' => CFile::formatSize($version->getSize()), 'NAME' => "<a href='' {$dataAttributesForViewer}>" . $version->getName() . "</a>", 'CREATE_USER' => "\n\t\t\t\t\t\t<div class=\"bx-disk-user-link\"><span class=\"bx-disk-filepage-fileinfo-ownner-avatar\" style=\"background-image: url({$version->getCreateUser()->getAvatarSrc()});\"></span><a target='_blank' href=\"{$createdByLink}\" id=\"\">" . htmlspecialcharsbx($version->getCreateUser()->getFormattedName()) . "</a></div>\n\t\t\t\t\t", 'CREATE_TIME_VERSION' => $version->getCreateTime(), 'CREATE_TIME_FILE' => $version->getObjectCreateTime(), 'UPDATE_TIME_FILE' => $version->getObjectUpdateTime()), 'actions' => $actions); } unset($version); $grid['ROWS'] = $rows; $grid['ROWS_COUNT'] = count($rows); $grid['HEADERS'] = array(array('id' => 'CREATE_USER', 'name' => Loc::getMessage('DISK_FILE_VIEW_VERSION_COLUMN_CREATE_USER_2'), 'default' => true), array('id' => 'NAME', 'name' => Loc::getMessage('DISK_FILE_VIEW_VERSION_COLUMN_NAME'), 'default' => true), array('id' => 'CREATE_TIME_VERSION', 'name' => Loc::getMessage('DISK_FILE_VIEW_VERSION_COLUMN_CREATE_TIME_2'), 'default' => true), array('id' => 'FORMATTED_SIZE', 'name' => Loc::getMessage('DISK_FILE_VIEW_VERSION_COLUMN_FORMATTED_SIZE'), 'default' => true), array('id' => 'ID', 'name' => 'ID', 'default' => false, 'show_checkbox' => true)); return $grid; }