aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/lib/Helper.php
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2017-08-22 18:46:47 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2017-08-29 12:03:13 +0200
commiteea7de4c9fc57e1a5c3e8c2f3b94200e7415cd10 (patch)
tree0275cd987792cc020717495203b08845e9f43085 /apps/files/lib/Helper.php
parent141bee931f0e1f51cd81772c5ac60274bc0df8d7 (diff)
downloadnextcloud-server-eea7de4c9fc57e1a5c3e8c2f3b94200e7415cd10.tar.gz
nextcloud-server-eea7de4c9fc57e1a5c3e8c2f3b94200e7415cd10.zip
Correctly format OCS response with favorites
The helper funtion did not handle the response correctly and basically only returned the last share with tags. This is a simple rewrite. That is still understandable. Loops maybe more than strictly required. But preformance is not the issue here. Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps/files/lib/Helper.php')
-rw-r--r--apps/files/lib/Helper.php34
1 files changed, 17 insertions, 17 deletions
diff --git a/apps/files/lib/Helper.php b/apps/files/lib/Helper.php
index 4a5595999d2..3eddbbaebf8 100644
--- a/apps/files/lib/Helper.php
+++ b/apps/files/lib/Helper.php
@@ -32,6 +32,7 @@
namespace OCA\Files;
use OCP\Files\FileInfo;
+use OCP\ITagManager;
/**
* Helper class for manipulating file information
@@ -206,40 +207,39 @@ class Helper {
*
* @param array $fileList
* @param string $fileIdentifier identifier attribute name for values in $fileList
+ * @param ITagManager $tagManager
* @return array file list populated with tags
*/
- public static function populateTags(array $fileList, $fileIdentifier = 'fileid') {
- $filesById = [];
+ public static function populateTags(array $fileList, $fileIdentifier = 'fileid', ITagManager $tagManager) {
+ $ids = [];
foreach ($fileList as $fileData) {
- $filesById[$fileData[$fileIdentifier]] = $fileData;
+ $ids[] = $fileData[$fileIdentifier];
}
- $tagger = \OC::$server->getTagManager()->load('files');
- $tags = $tagger->getTagsForObjects(array_keys($filesById));
+ $tagger = $tagManager->load('files');
+ $tags = $tagger->getTagsForObjects($ids);
if (!is_array($tags)) {
throw new \UnexpectedValueException('$tags must be an array');
}
+ // Set empty tag array
+ foreach ($fileList as $key => $fileData) {
+ $fileList[$key]['tags'] = [];
+ }
+
if (!empty($tags)) {
foreach ($tags as $fileId => $fileTags) {
- $filesById[$fileId]['tags'] = $fileTags;
- }
- foreach ($filesById as $key => $fileWithTags) {
- foreach($fileList as $key2 => $file){
- if( $file[$fileIdentifier] === $key){
- $fileList[$key2] = $fileWithTags;
+ foreach ($fileList as $key => $fileData) {
+ if ($fileId !== $fileData[$fileIdentifier]) {
+ continue;
}
- }
- }
- foreach ($fileList as $key => $file) {
- if (!array_key_exists('tags', $file)) {
- $fileList[$key]['tags'] = [];
+ $fileList[$key]['tags'] = $fileTags;
}
}
-
}
+
return $fileList;
}