summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2014-11-24 21:51:45 +0100
committerVincent Petry <pvince81@owncloud.com>2014-12-08 22:02:00 +0100
commitcae600722ed04e69c376aa0a1ef1955c93d18ddf (patch)
tree862693a24e5d6b883bf15c0b24327f2a6a086d0e /lib
parent6fb2477fb75d4c982a1568e2392d17fd7cc2fd4b (diff)
downloadnextcloud-server-cae600722ed04e69c376aa0a1ef1955c93d18ddf.tar.gz
nextcloud-server-cae600722ed04e69c376aa0a1ef1955c93d18ddf.zip
Add getTagsForObjects in ITags
Returns the list of tags that are set on the given object ids.
Diffstat (limited to 'lib')
-rw-r--r--lib/private/tags.php42
-rw-r--r--lib/public/itags.php18
2 files changed, 59 insertions, 1 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.
diff --git a/lib/public/itags.php b/lib/public/itags.php
index 4514746bbe8..238b12c6424 100644
--- a/lib/public/itags.php
+++ b/lib/public/itags.php
@@ -76,7 +76,23 @@ interface ITags {
public function getTags();
/**
- * Get the a list if items tagged with $tag.
+ * Get a list of tags for the given item ids.
+ *
+ * This returns an array with object id / tag names:
+ * [
+ * 1 => array('First tag', 'Second tag'),
+ * 2 => array('Second tag'),
+ * 3 => array('Second tag', 'Third tag'),
+ * ]
+ *
+ * @param array $objIds item ids
+ * @return array|boolean with object id as key and an array
+ * of tag names as value or false if an error occurred
+ */
+ public function getTagsForObjects(array $objIds);
+
+ /**
+ * Get a list of items tagged with $tag.
*
* Throws an exception if the tag could not be found.
*