diff options
author | Joas Schilling <nickvergessen@gmx.de> | 2014-12-09 13:27:38 +0100 |
---|---|---|
committer | Joas Schilling <nickvergessen@gmx.de> | 2014-12-09 13:27:38 +0100 |
commit | f53f25eafe2e7cad28eabccd7ca5acebab488170 (patch) | |
tree | 0edc65f4e4fb156aefb6807e559b1e2d00b91e93 /lib/private | |
parent | 1a16238d5d2a9579e02687e7e76acd1737039de8 (diff) | |
parent | cae600722ed04e69c376aa0a1ef1955c93d18ddf (diff) | |
download | nextcloud-server-f53f25eafe2e7cad28eabccd7ca5acebab488170.tar.gz nextcloud-server-f53f25eafe2e7cad28eabccd7ca5acebab488170.zip |
Merge pull request #12409 from owncloud/tags-getTagsForObjectIds
Add getTagsForObjects in ITags
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/tags.php | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/private/tags.php b/lib/private/tags.php index bab3d495282..e00c1b90ca9 100644 --- a/lib/private/tags.php +++ b/lib/private/tags.php @@ -200,6 +200,48 @@ class Tags implements \OCP\ITags { } /** + * Get the list of tags for the given ids. + * + * @param array $objIds array of object ids + * @return array|boolean of tags id as key to array of tag names + * or false if an error occurred + */ + public function getTagsForObjects(array $objIds) { + $entries = array(); + + try { + $conn = \OC_DB::getConnection(); + $chunks = array_chunk($objIds, 1000, false); + foreach ($chunks as $chunk) { + $result = $conn->executeQuery( + 'SELECT `category`, `categoryid`, `objid` ' . + 'FROM `' . self::RELATION_TABLE . '` r, `' . self::TAG_TABLE . '` ' . + 'WHERE `categoryid` = `id` AND `uid` = ? AND r.`type` = ? AND `objid` IN (?)', + array($this->user, $this->type, $chunk), + array(null, null, \Doctrine\DBAL\Connection::PARAM_INT_ARRAY) + ); + while ($row = $result->fetch()) { + $objId = (int)$row['objid']; + if (!isset($entries[$objId])) { + $entry = $entries[$objId] = array(); + } + $entry = $entries[$objId][] = $row['category']; + } + } + if (\OCP\DB::isError($result)) { + \OCP\Util::writeLog('core', __METHOD__. 'DB error: ' . \OCP\DB::getErrorMessage($result), \OCP\Util::ERROR); + return false; + } + } catch(\Exception $e) { + \OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(), + \OCP\Util::ERROR); + return false; + } + + return $entries; + } + + /** * Get the a list if items tagged with $tag. * * Throws an exception if the tag could not be found. |