l10n->t('Favorite files'); } public function getOrder(): int { return 0; } public function getIconClass(): string { return 'icon-star-dark'; } public function getIconUrl(): string { return $this->urlGenerator->getAbsoluteURL( $this->urlGenerator->imagePath('core', 'actions/star.svg') ); } public function getUrl(): ?string { return $this->urlGenerator->linkToRouteAbsolute('files.View.indexView', ['view' => 'favorites']); } public function load(): void { } public function getItems(string $userId, int $limit = 7): array { $user = $this->userManager->get($userId); if (!$user) { return []; } $tags = $this->tagManager->load('files', [], false, $userId); $favorites = $tags->getFavorites(); if (empty($favorites)) { return []; } $favoriteNodes = []; $userFolder = $this->rootFolder->getUserFolder($userId); $count = 0; foreach ($favorites as $favorite) { $node = $userFolder->getFirstNodeById($favorite); if ($node) { $url = $this->urlGenerator->linkToRouteAbsolute( 'files.view.showFile', ['fileid' => $node->getId()] ); $icon = $this->urlGenerator->linkToRouteAbsolute('core.Preview.getPreviewByFileId', [ 'x' => 256, 'y' => 256, 'fileId' => $node->getId(), 'c' => $node->getEtag(), 'mimeFallback' => true, ]); $favoriteNodes[] = new WidgetItem( $node->getName(), '', $url, $icon, (string)$node->getCreationTime() ); $count++; if ($count >= $limit) { break; } } } return $favoriteNodes; } public function getItemsV2(string $userId, ?string $since = null, int $limit = 7): WidgetItems { $items = $this->getItems($userId, $limit); return new WidgetItems( $items, count($items) === 0 ? $this->l10n->t('No favorites') : '', ); } public function getWidgetButtons(string $userId): array { return [ new WidgetButton( WidgetButton::TYPE_MORE, $this->urlGenerator->linkToRouteAbsolute('files.View.indexView', ['view' => 'favorites']), $this->l10n->t('More favorites') ), ]; } public function getWidgetOptions(): WidgetOptions { return new WidgetOptions(roundItemIcons: false); } }