11<?php
2+
3+ declare (strict_types=1 );
4+
25/**
36 * @copyright Copyright (c) 2020 Julius Härtl <jus@bitgrid.net>
47 *
3033use OCP \Dashboard \IIconWidget ;
3134use OCP \Dashboard \IWidget ;
3235use OCP \Dashboard \Model \WidgetItem ;
36+ use OCP \Files \IMimeTypeDetector ;
3337use OCP \IL10N ;
3438use OCP \IURLGenerator ;
3539use OCP \IUserManager ;
@@ -40,19 +44,22 @@ class RecommendationWidget implements IWidget, IIconWidget, IAPIWidget {
4044 private IUserSession $ userSession ;
4145 private IL10N $ l10n ;
4246 private IURLGenerator $ urlGenerator ;
47+ private IMimeTypeDetector $ mimeTypeDetector ;
4348 private RecommendationService $ recommendationService ;
4449 private IUserManager $ userManager ;
4550
4651 public function __construct (
4752 IUserSession $ userSession ,
4853 IL10N $ l10n ,
4954 IURLGenerator $ urlGenerator ,
55+ IMimeTypeDetector $ mimeTypeDetector ,
5056 RecommendationService $ recommendationService ,
5157 IUserManager $ userManager
5258 ) {
5359 $ this ->userSession = $ userSession ;
5460 $ this ->l10n = $ l10n ;
5561 $ this ->urlGenerator = $ urlGenerator ;
62+ $ this ->mimeTypeDetector = $ mimeTypeDetector ;
5663 $ this ->recommendationService = $ recommendationService ;
5764 $ this ->userManager = $ userManager ;
5865 }
@@ -96,15 +103,31 @@ public function getItems(string $userId, ?string $since = null, int $limit = 7):
96103 }
97104 $ recommendations = $ this ->recommendationService ->getRecommendations ($ user , $ limit );
98105
99- return array_map (function (IRecommendation $ recommendation ) {
100- $ url = $ this ->urlGenerator ->linkToRouteAbsolute ('files.viewcontroller.showFile ' , ['fileid ' => $ recommendation ->getNode ()->getId ()]);
101- $ icon = $ this ->urlGenerator ->linkToRouteAbsolute ('core.Preview.getPreviewByFileId ' , [
102- 'x ' => 256 ,
103- 'y ' => 256 ,
104- 'fileId ' => $ recommendation ->getNode ()->getId (),
105- 'c ' => $ recommendation ->getNode ()->getEtag (),
106- ]);
107- return new WidgetItem ($ recommendation ->getNode ()->getName (), '' , $ url , $ icon , $ recommendation ->getTimestamp ());
106+ return array_map (function (IRecommendation $ recommendation ) {
107+ $ url = $ this ->urlGenerator ->linkToRouteAbsolute (
108+ 'files.viewcontroller.showFile ' , ['fileid ' => $ recommendation ->getNode ()->getId ()]
109+ );
110+
111+ if ($ recommendation ->hasPreview ()) {
112+ $ icon = $ this ->urlGenerator ->linkToRouteAbsolute ('core.Preview.getPreviewByFileId ' , [
113+ 'x ' => 256 ,
114+ 'y ' => 256 ,
115+ 'fileId ' => $ recommendation ->getNode ()->getId (),
116+ 'c ' => $ recommendation ->getNode ()->getEtag (),
117+ ]);
118+ } else {
119+ $ icon = $ this ->urlGenerator ->getAbsoluteURL (
120+ $ this ->mimeTypeDetector ->mimeTypeIcon ($ recommendation ->getNode ()->getMimetype ())
121+ );
122+ }
123+
124+ return new WidgetItem (
125+ $ recommendation ->getNode ()->getName (),
126+ '' ,
127+ $ url ,
128+ $ icon ,
129+ (string )$ recommendation ->getTimestamp ()
130+ );
108131 }, $ recommendations );
109132 }
110133}
0 commit comments