diff options
Diffstat (limited to 'apps/files/lib/Helper.php')
-rw-r--r-- | apps/files/lib/Helper.php | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/apps/files/lib/Helper.php b/apps/files/lib/Helper.php index b6b209dea70..c3d80957913 100644 --- a/apps/files/lib/Helper.php +++ b/apps/files/lib/Helper.php @@ -208,19 +208,40 @@ class Helper { * Populate the result set with file tags * * @param array $fileList + * @param string $fileIdentifier identifier attribute name for values in $fileList * @return array file list populated with tags */ - public static function populateTags(array $fileList) { - $filesById = array(); + public static function populateTags(array $fileList, $fileIdentifier = 'fileid') { + $filesById = []; foreach ($fileList as $fileData) { - $filesById[$fileData['fileid']] = $fileData; + $filesById[$fileData[$fileIdentifier]] = $fileData; } $tagger = \OC::$server->getTagManager()->load('files'); $tags = $tagger->getTagsForObjects(array_keys($filesById)); - if ($tags) { + + if (!is_array($tags)) { + throw new \UnexpectedValueException('$tags must be an array'); + } + + 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 => $file) { + if (!array_key_exists('tags', $file)) { + $fileList[$key]['tags'] = []; + } + } + } return $fileList; } |