From 81b1dc4930204ca7210b595e631a4c4ce46fb79d Mon Sep 17 00:00:00 2001 From: Michael Jobst Date: Thu, 10 Nov 2016 09:13:25 +0100 Subject: share api expanded by tags (#26583) * share api expanded by tags * Modified files_sharing JS Unit tests * modified tests. renamed request parameter. refactoring * Update Share20OCS.php Added missing function description * Update Helper.php Added missing function description * Update Helper.php implicit boolean conversion to !empty() * Update Share20OCSTest.php Signed-off-by: Morris Jobke --- apps/files/ajax/list.php | 1 - apps/files/js/tagsplugin.js | 7 +++++-- apps/files/lib/Helper.php | 29 +++++++++++++++++++++++++---- 3 files changed, 30 insertions(+), 7 deletions(-) (limited to 'apps/files') diff --git a/apps/files/ajax/list.php b/apps/files/ajax/list.php index 2cd09765435..d91db8744c4 100644 --- a/apps/files/ajax/list.php +++ b/apps/files/ajax/list.php @@ -71,7 +71,6 @@ try { $files = \OCA\Files\Helper::getFiles($dir, $sortAttribute, $sortDirection); } - $files = \OCA\Files\Helper::populateTags($files); $data['directory'] = $dir; $data['files'] = \OCA\Files\Helper::formatFileInfos($files); $data['permissions'] = $permissions; diff --git a/apps/files/js/tagsplugin.js b/apps/files/js/tagsplugin.js index 67bd9c667c8..9bd20be4bf8 100644 --- a/apps/files/js/tagsplugin.js +++ b/apps/files/js/tagsplugin.js @@ -75,7 +75,11 @@ allowedLists: [ 'files', - 'favorites' + 'favorites', + 'systemtags', + 'shares.self', + 'shares.others', + 'shares.link' ], _extendFileActions: function(fileActions) { @@ -241,4 +245,3 @@ })(OCA); OC.Plugins.register('OCA.Files.FileList', OCA.Files.TagsPlugin); - 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; } -- cgit v1.2.3