Completed
Push — master ( bc2321...13210b )
by Joas
33:56 queued 01:24
created
apps/files/lib/Dashboard/FavoriteWidget.php 1 patch
Indentation   +109 added lines, -109 removed lines patch added patch discarded remove patch
@@ -29,113 +29,113 @@
 block discarded – undo
29 29
 
30 30
 class FavoriteWidget implements IIconWidget, IAPIWidgetV2, IButtonWidget, IOptionWidget {
31 31
 
32
-	public function __construct(
33
-		private readonly IL10N $l10n,
34
-		private readonly IURLGenerator $urlGenerator,
35
-		private readonly IMimeTypeDetector $mimeTypeDetector,
36
-		private readonly IUserManager $userManager,
37
-		private readonly ITagManager $tagManager,
38
-		private readonly IRootFolder $rootFolder,
39
-		private readonly IPreview $previewManager,
40
-	) {
41
-	}
42
-
43
-	public function getId(): string {
44
-		return Application::APP_ID . '-favorites';
45
-	}
46
-
47
-	public function getTitle(): string {
48
-		return $this->l10n->t('Favorite files');
49
-	}
50
-
51
-	public function getOrder(): int {
52
-		return 0;
53
-	}
54
-
55
-	public function getIconClass(): string {
56
-		return 'icon-starred-dark';
57
-	}
58
-
59
-	public function getIconUrl(): string {
60
-		return $this->urlGenerator->getAbsoluteURL(
61
-			$this->urlGenerator->imagePath('core', 'actions/star-dark.svg')
62
-		);
63
-	}
64
-
65
-	public function getUrl(): ?string {
66
-		return $this->urlGenerator->linkToRouteAbsolute('files.View.indexView', ['view' => 'favorites']);
67
-	}
68
-
69
-	public function load(): void {
70
-	}
71
-
72
-	public function getItems(string $userId, int $limit = 7): array {
73
-		$user = $this->userManager->get($userId);
74
-
75
-		if (!$user) {
76
-			return [];
77
-		}
78
-		$tags = $this->tagManager->load('files', [], false, $userId);
79
-		$favorites = $tags->getFavorites();
80
-		if (empty($favorites)) {
81
-			return [];
82
-		}
83
-		$favoriteNodes = [];
84
-		$userFolder = $this->rootFolder->getUserFolder($userId);
85
-		$count = 0;
86
-		foreach ($favorites as $favorite) {
87
-			$node = $userFolder->getFirstNodeById($favorite);
88
-			if ($node) {
89
-				$url = $this->urlGenerator->linkToRouteAbsolute(
90
-					'files.view.showFile', ['fileid' => $node->getId()]
91
-				);
92
-				if ($node instanceof File) {
93
-					$icon = $this->urlGenerator->linkToRouteAbsolute('core.Preview.getPreviewByFileId', [
94
-						'x' => 256,
95
-						'y' => 256,
96
-						'fileId' => $node->getId(),
97
-						'c' => $node->getEtag(),
98
-						'mimeFallback' => true,
99
-					]);
100
-				} else {
101
-					$icon = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'filetypes/folder.svg'));
102
-				}
103
-				$favoriteNodes[] = new WidgetItem(
104
-					$node->getName(),
105
-					'',
106
-					$url,
107
-					$icon,
108
-					(string)$node->getCreationTime()
109
-				);
110
-				$count++;
111
-				if ($count >= $limit) {
112
-					break;
113
-				}
114
-			}
115
-		}
116
-
117
-		return $favoriteNodes;
118
-	}
119
-
120
-	public function getItemsV2(string $userId, ?string $since = null, int $limit = 7): WidgetItems {
121
-		$items = $this->getItems($userId, $limit);
122
-		return new WidgetItems(
123
-			$items,
124
-			count($items) === 0 ? $this->l10n->t('No favorites') : '',
125
-		);
126
-	}
127
-
128
-	public function getWidgetButtons(string $userId): array {
129
-		return [
130
-			new WidgetButton(
131
-				WidgetButton::TYPE_MORE,
132
-				$this->urlGenerator->linkToRouteAbsolute('files.View.indexView', ['view' => 'favorites']),
133
-				$this->l10n->t('More favorites')
134
-			),
135
-		];
136
-	}
137
-
138
-	public function getWidgetOptions(): WidgetOptions {
139
-		return new WidgetOptions(roundItemIcons: false);
140
-	}
32
+    public function __construct(
33
+        private readonly IL10N $l10n,
34
+        private readonly IURLGenerator $urlGenerator,
35
+        private readonly IMimeTypeDetector $mimeTypeDetector,
36
+        private readonly IUserManager $userManager,
37
+        private readonly ITagManager $tagManager,
38
+        private readonly IRootFolder $rootFolder,
39
+        private readonly IPreview $previewManager,
40
+    ) {
41
+    }
42
+
43
+    public function getId(): string {
44
+        return Application::APP_ID . '-favorites';
45
+    }
46
+
47
+    public function getTitle(): string {
48
+        return $this->l10n->t('Favorite files');
49
+    }
50
+
51
+    public function getOrder(): int {
52
+        return 0;
53
+    }
54
+
55
+    public function getIconClass(): string {
56
+        return 'icon-starred-dark';
57
+    }
58
+
59
+    public function getIconUrl(): string {
60
+        return $this->urlGenerator->getAbsoluteURL(
61
+            $this->urlGenerator->imagePath('core', 'actions/star-dark.svg')
62
+        );
63
+    }
64
+
65
+    public function getUrl(): ?string {
66
+        return $this->urlGenerator->linkToRouteAbsolute('files.View.indexView', ['view' => 'favorites']);
67
+    }
68
+
69
+    public function load(): void {
70
+    }
71
+
72
+    public function getItems(string $userId, int $limit = 7): array {
73
+        $user = $this->userManager->get($userId);
74
+
75
+        if (!$user) {
76
+            return [];
77
+        }
78
+        $tags = $this->tagManager->load('files', [], false, $userId);
79
+        $favorites = $tags->getFavorites();
80
+        if (empty($favorites)) {
81
+            return [];
82
+        }
83
+        $favoriteNodes = [];
84
+        $userFolder = $this->rootFolder->getUserFolder($userId);
85
+        $count = 0;
86
+        foreach ($favorites as $favorite) {
87
+            $node = $userFolder->getFirstNodeById($favorite);
88
+            if ($node) {
89
+                $url = $this->urlGenerator->linkToRouteAbsolute(
90
+                    'files.view.showFile', ['fileid' => $node->getId()]
91
+                );
92
+                if ($node instanceof File) {
93
+                    $icon = $this->urlGenerator->linkToRouteAbsolute('core.Preview.getPreviewByFileId', [
94
+                        'x' => 256,
95
+                        'y' => 256,
96
+                        'fileId' => $node->getId(),
97
+                        'c' => $node->getEtag(),
98
+                        'mimeFallback' => true,
99
+                    ]);
100
+                } else {
101
+                    $icon = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'filetypes/folder.svg'));
102
+                }
103
+                $favoriteNodes[] = new WidgetItem(
104
+                    $node->getName(),
105
+                    '',
106
+                    $url,
107
+                    $icon,
108
+                    (string)$node->getCreationTime()
109
+                );
110
+                $count++;
111
+                if ($count >= $limit) {
112
+                    break;
113
+                }
114
+            }
115
+        }
116
+
117
+        return $favoriteNodes;
118
+    }
119
+
120
+    public function getItemsV2(string $userId, ?string $since = null, int $limit = 7): WidgetItems {
121
+        $items = $this->getItems($userId, $limit);
122
+        return new WidgetItems(
123
+            $items,
124
+            count($items) === 0 ? $this->l10n->t('No favorites') : '',
125
+        );
126
+    }
127
+
128
+    public function getWidgetButtons(string $userId): array {
129
+        return [
130
+            new WidgetButton(
131
+                WidgetButton::TYPE_MORE,
132
+                $this->urlGenerator->linkToRouteAbsolute('files.View.indexView', ['view' => 'favorites']),
133
+                $this->l10n->t('More favorites')
134
+            ),
135
+        ];
136
+    }
137
+
138
+    public function getWidgetOptions(): WidgetOptions {
139
+        return new WidgetOptions(roundItemIcons: false);
140
+    }
141 141
 }
Please login to merge, or discard this patch.