From 909e9ee64a4df83dee2e2278517c38f184712cbc Mon Sep 17 00:00:00 2001 From: yemkareems Date: Wed, 8 Jan 2025 14:32:16 +0530 Subject: [PATCH] fix: added count and removed slice Signed-off-by: yemkareems --- apps/files/lib/Dashboard/FavoriteWidget.php | 22 +++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/apps/files/lib/Dashboard/FavoriteWidget.php b/apps/files/lib/Dashboard/FavoriteWidget.php index 28180f56154d4..4a959348074e1 100644 --- a/apps/files/lib/Dashboard/FavoriteWidget.php +++ b/apps/files/lib/Dashboard/FavoriteWidget.php @@ -81,6 +81,7 @@ public function getItems(string $userId, int $limit = 7): array { } $favoriteNodes = []; $userFolder = $this->rootFolder->getUserFolder($userId); + $count = 0; foreach ($favorites as $favorite) { $node = $userFolder->getFirstNodeById($favorite); if ($node) { @@ -99,17 +100,22 @@ public function getItems(string $userId, int $limit = 7): array { $this->mimeTypeDetector->mimeTypeIcon($node->getMimetype()) ); } - $favoriteNodes[] = new WidgetItem( - $node->getName(), - '', - $url, - $icon, - (string)$node->getCreationTime() - ); + if($count < $limit) { + $favoriteNodes[] = new WidgetItem( + $node->getName(), + '', + $url, + $icon, + (string)$node->getCreationTime() + ); + $count++; + } else { + break; + } } } - return array_slice($favoriteNodes, 0, $limit); + return $favoriteNodes; } public function getItemsV2(string $userId, ?string $since = null, int $limit = 7): WidgetItems {