Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
use mimeIcon is preview not available
Signed-off-by: Maxence Lange <[email protected]>
  • Loading branch information
ArtificialOwl authored and backportbot-nextcloud[bot] committed Oct 21, 2022
commit 3edb9a184150369600a1a7c9e0b3912ffc5def8c
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/build
/node_modules
/vendor/

.idea/
41 changes: 32 additions & 9 deletions lib/Dashboard/RecommendationWidget.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2020 Julius Härtl <[email protected]>
*
Expand Down Expand Up @@ -30,6 +33,7 @@
use OCP\Dashboard\IIconWidget;
use OCP\Dashboard\IWidget;
use OCP\Dashboard\Model\WidgetItem;
use OCP\Files\IMimeTypeDetector;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\IUserManager;
Expand All @@ -40,19 +44,22 @@ class RecommendationWidget implements IWidget, IIconWidget, IAPIWidget {
private IUserSession $userSession;
private IL10N $l10n;
private IURLGenerator $urlGenerator;
private IMimeTypeDetector $mimeTypeDetector;
private RecommendationService $recommendationService;
private IUserManager $userManager;

public function __construct(
IUserSession $userSession,
IL10N $l10n,
IURLGenerator $urlGenerator,
IMimeTypeDetector $mimeTypeDetector,
RecommendationService $recommendationService,
IUserManager $userManager
) {
$this->userSession = $userSession;
$this->l10n = $l10n;
$this->urlGenerator = $urlGenerator;
$this->mimeTypeDetector = $mimeTypeDetector;
$this->recommendationService = $recommendationService;
$this->userManager = $userManager;
}
Expand Down Expand Up @@ -96,15 +103,31 @@ public function getItems(string $userId, ?string $since = null, int $limit = 7):
}
$recommendations = $this->recommendationService->getRecommendations($user, $limit);

return array_map(function(IRecommendation $recommendation) {
$url = $this->urlGenerator->linkToRouteAbsolute('files.viewcontroller.showFile', ['fileid' => $recommendation->getNode()->getId()]);
$icon = $this->urlGenerator->linkToRouteAbsolute('core.Preview.getPreviewByFileId', [
'x' => 256,
'y' => 256,
'fileId' => $recommendation->getNode()->getId(),
'c' => $recommendation->getNode()->getEtag(),
]);
return new WidgetItem($recommendation->getNode()->getName(), '', $url, $icon, $recommendation->getTimestamp());
return array_map(function (IRecommendation $recommendation) {
$url = $this->urlGenerator->linkToRouteAbsolute(
'files.viewcontroller.showFile', ['fileid' => $recommendation->getNode()->getId()]
);

if ($recommendation->hasPreview()) {
$icon = $this->urlGenerator->linkToRouteAbsolute('core.Preview.getPreviewByFileId', [
'x' => 256,
'y' => 256,
'fileId' => $recommendation->getNode()->getId(),
'c' => $recommendation->getNode()->getEtag(),
]);
} else {
$icon = $this->urlGenerator->getAbsoluteURL(
$this->mimeTypeDetector->mimeTypeIcon($recommendation->getNode()->getMimetype())
);
}

return new WidgetItem(
$recommendation->getNode()->getName(),
'',
$url,
$icon,
(string)$recommendation->getTimestamp()
);
}, $recommendations);
}
}