diff options
author | Michael Jobst <mjobst+github@tecratech.de> | 2016-11-10 09:13:25 +0100 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2017-04-11 11:54:13 -0500 |
commit | 81b1dc4930204ca7210b595e631a4c4ce46fb79d (patch) | |
tree | 77e867b192923d51b054f529e0ab5e4a1623d204 /apps/files/lib/Helper.php | |
parent | 45a6e376995a3ef6618b12ee65e6f903e846b1a5 (diff) | |
download | nextcloud-server-81b1dc4930204ca7210b595e631a4c4ce46fb79d.tar.gz nextcloud-server-81b1dc4930204ca7210b595e631a4c4ce46fb79d.zip |
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 <hey@morrisjobke.de>
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; } |