diff options
author | Vincent Petry <pvince81@owncloud.com> | 2014-12-04 14:01:15 +0100 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2014-12-11 17:38:50 +0100 |
commit | 25dde7e93bc648ec8cd14b8f2711d50f77d8d1bf (patch) | |
tree | f45b35dd647870b6c3aeded3e8e11faa41effcba /apps/files_sharing/lib/cache.php | |
parent | 745d8706b973ff0494af54f183acc0da361f0e83 (diff) | |
download | nextcloud-server-25dde7e93bc648ec8cd14b8f2711d50f77d8d1bf.tar.gz nextcloud-server-25dde7e93bc648ec8cd14b8f2711d50f77d8d1bf.zip |
Added searchByTags to view, storage and cache
Diffstat (limited to 'apps/files_sharing/lib/cache.php')
-rw-r--r-- | apps/files_sharing/lib/cache.php | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/apps/files_sharing/lib/cache.php b/apps/files_sharing/lib/cache.php index e09b64cb039..da8155ec6fa 100644 --- a/apps/files_sharing/lib/cache.php +++ b/apps/files_sharing/lib/cache.php @@ -345,6 +345,46 @@ class Shared_Cache extends Cache { } /** + * search for files by tag + * + * @param string|int $tag tag to search for + * @param string $userId owner of the tags + * @return array file data + */ + public function searchByTag($tag, $userId = null) { + // TODO: inject this + $tagger = \OC::$server->getTagManager()->load('files', null, null, $userId); + $result = array(); + $exploreDirs = array(''); + // FIXME: this is so wrong and unefficient, need to replace with actual DB queries + while (count($exploreDirs) > 0) { + $dir = array_pop($exploreDirs); + $files = $this->getFolderContents($dir); + // no results? + if (!$files) { + // maybe it's a single shared file + $file = $this->get(''); + $tags = $tagger->getTagsForObjects(array((int)$file['fileid'])); + if (!empty($tags) && in_array($tag, current($tags))) { + $result[] = $file; + } + continue; + } + foreach ($files as $file) { + if ($file['mimetype'] === 'httpd/unix-directory') { + $exploreDirs[] = ltrim($dir . '/' . $file['name'], '/'); + } else { + $tags = $tagger->getTagsForObjects(array((int)$file['fileid'])); + if (!empty($tags) && in_array($tag, current($tags))) { + $result[] = $file; + } + } + } + } + return $result; + } + + /** * get the size of a folder and set it in the cache * * @param string $path |