Ejemplo n.º 1
0
 private function getGridData($gridId)
 {
     $grid = array('ID' => $gridId);
     $filter = array();
     $securityContext = $this->storage->getCurrentUserSecurityContext();
     //shown trash can root
     if ($this->arParams['RELATIVE_PATH'] == '/') {
         $filter['DELETED_TYPE'] = ObjectTable::DELETED_TYPE_ROOT;
         $items = $this->folder->getDescendants($securityContext, array('with' => array('CREATE_USER', 'UPDATE_USER', 'DELETE_USER'), 'filter' => $filter));
     } else {
         $filter['DELETED_TYPE'] = ObjectTable::DELETED_TYPE_CHILD;
         $items = $this->folder->getChildren($securityContext, array('with' => array('CREATE_USER', 'UPDATE_USER', 'DELETE_USER'), 'filter' => $filter));
     }
     if (count($items)) {
         $this->folder->preloadOperationsForChildren($securityContext);
     }
     $urlManager = \Bitrix\Disk\Driver::getInstance()->getUrlManager();
     $rows = array();
     foreach ($items as $object) {
         /** @var File|Folder $object */
         $exportData = $object->toArray();
         $relativePath = trim($this->arParams['RELATIVE_PATH'], '/');
         $detailPageFile = CComponentEngine::MakePathFromTemplate($this->arParams['PATH_TO_TRASHCAN_FILE_VIEW'], array('FILE_ID' => $object->getId(), 'TRASH_FILE_PATH' => ltrim($relativePath . '/' . $object->getOriginalName(), '/')));
         $listingPage = rtrim(CComponentEngine::MakePathFromTemplate($this->arParams['PATH_TO_TRASHCAN_LIST'], array('TRASH_PATH' => $relativePath)), '/');
         $isFolder = $object instanceof Folder;
         $actions = array();
         $exportData['OPEN_URL'] = $urlManager->encodeUrn($isFolder ? $listingPage . '/' . $object->getOriginalName() : $detailPageFile);
         $actions[] = array("PSEUDO_NAME" => "open", "ICONCLASS" => "show", "TEXT" => Loc::getMessage('DISK_TRASHCAN_ACT_OPEN'), "ONCLICK" => "jsUtils.Redirect(arguments, '" . $exportData['OPEN_URL'] . "')");
         if (!$isFolder) {
             $actions[] = array("PSEUDO_NAME" => "download", "ICONCLASS" => "download", "TEXT" => Loc::getMessage('DISK_TRASHCAN_ACT_DOWNLOAD'), "ONCLICK" => "jsUtils.Redirect(arguments, '" . $urlManager->getUrlForDownloadFile($object) . "')");
         }
         if ($object->isDeleted() && $object->canRestore($securityContext)) {
             $actions[] = array("ICONCLASS" => "restore", "PSEUDO_NAME" => "restore", "TEXT" => Loc::getMessage('DISK_TRASHCAN_ACT_RESTORE'), "ONCLICK" => "BX.Disk['TrashCanClass_{$this->getComponentId()}'].openConfirmRestore({\n\t\t\t\t\t\t\tobject: {\n\t\t\t\t\t\t\t\tid: {$object->getId()},\n\t\t\t\t\t\t\t\tname: '{$object->getName()}',\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 ($object->canDelete($securityContext)) {
             $actions[] = array("ICONCLASS" => "destroy", "PSEUDO_NAME" => "destroy", "TEXT" => Loc::getMessage('DISK_TRASHCAN_ACT_DESTROY'), "ONCLICK" => "BX.Disk['TrashCanClass_{$this->getComponentId()}'].openConfirmDelete({\n\t\t\t\t\t\t\tobject: {\n\t\t\t\t\t\t\t\tid: {$object->getId()},\n\t\t\t\t\t\t\t\tname: '{$object->getName()}',\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) {
             $uri = $urlManager->encodeUrn($listingPage . '/' . $object->getOriginalName());
         } else {
             $uri = \Bitrix\Disk\Driver::getInstance()->getUrlManager()->encodeUrn($detailPageFile);
         }
         $iconClass = \Bitrix\Disk\Ui\Icon::getIconClassByObject($object);
         $name = htmlspecialcharsbx($object->getName());
         $updateDateTime = $object->getUpdateTime();
         $columnName = "\n\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=\"{$object->getId()}\" class=\"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_{$object->getId()}\" href=\"{$uri}\" data-bx-dateModify=\"" . htmlspecialcharsbx($updateDateTime) . "\">{$name}</a></td>\n\t\t\t\t</tr></table>\n\t\t\t";
         $deletedTime = $object->getDeleteTime();
         $createdByLink = \CComponentEngine::makePathFromTemplate($this->arParams['PATH_TO_USER'], array("user_id" => $object->getCreatedBy()));
         $deletedByLink = \CComponentEngine::makePathFromTemplate($this->arParams['PATH_TO_USER'], array("user_id" => $object->getDeletedBy()));
         $columns = array('CREATE_TIME' => formatDate('x', $object->getCreateTime()->toUserTime()->getTimestamp(), time() + CTimeZone::getOffset()), 'UPDATE_TIME' => formatDate('x', $updateDateTime->toUserTime()->getTimestamp(), time() + CTimeZone::getOffset()), 'DELETE_TIME' => formatDate('x', $deletedTime->toUserTime()->getTimestamp(), time() + CTimeZone::getOffset()), '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", 'DELETE_USER' => "\n\t\t\t\t\t<div class=\"bx-disk-user-link\"><a target='_blank' href=\"{$deletedByLink}\" id=\"\">" . htmlspecialcharsbx($object->getDeleteUser()->getFormattedName()) . "</a></div>\n\t\t\t\t");
         $exportData['ICON_CLASS'] = $iconClass;
         $exportData['IS_SHARED'] = false;
         $exportData['IS_LINK'] = false;
         $tildaExportData = array();
         foreach ($exportData as $exportName => $exportValue) {
             $tildaExportData['~' . $exportName] = $exportValue;
         }
         unset($exportRow);
         $rows[] = array('data' => array_merge($exportData, $tildaExportData), 'columns' => $columns, 'actions' => $actions, 'DELETE_TIME' => $deletedTime->getTimestamp());
     }
     unset($object);
     Collection::sortByColumn($rows, array('DELETE_TIME' => SORT_DESC));
     $grid['HEADERS'] = array(array('id' => 'ID', 'name' => 'ID', 'default' => false), array('id' => 'NAME', 'name' => Loc::getMessage('DISK_TRASHCAN_COLUMN_NAME'), 'default' => true), array('id' => 'DELETE_TIME', 'name' => Loc::getMessage('DISK_TRASHCAN_COLUMN_DELETE_TIME'), 'default' => true), array('id' => 'CREATE_TIME', 'name' => Loc::getMessage('DISK_TRASHCAN_COLUMN_CREATE_TIME'), 'default' => false), array('id' => 'UPDATE_TIME', 'name' => Loc::getMessage('DISK_TRASHCAN_COLUMN_UPDATE_TIME'), 'default' => false), array('id' => 'CREATE_USER', 'name' => Loc::getMessage('DISK_TRASHCAN_COLUMN_CREATE_USER'), 'default' => false), array('id' => 'DELETE_USER', 'name' => Loc::getMessage('DISK_TRASHCAN_COLUMN_DELETE_USER'), 'default' => false), array('id' => 'FORMATTED_SIZE', 'name' => Loc::getMessage('DISK_TRASHCAN_COLUMN_FORMATTED_SIZE'), 'default' => true));
     $grid['ROWS'] = $rows;
     $grid['ROWS_COUNT'] = count($rows);
     $grid['FOOTER'] = array();
     return $grid;
 }