diff options
author | Vincent Petry <pvince81@owncloud.com> | 2016-05-11 12:25:09 +0200 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2016-05-20 17:56:02 +0200 |
commit | 3cd65fe25dc6f213dd7e4a1687616dc5e0960d4d (patch) | |
tree | 01a4e4a6bb7ff4f3a9243bd6c523fc5a738e1c65 /lib | |
parent | 09b3883d9ceae77793e524209090f2e36ab61260 (diff) | |
download | nextcloud-server-3cd65fe25dc6f213dd7e4a1687616dc5e0960d4d.tar.gz nextcloud-server-3cd65fe25dc6f213dd7e4a1687616dc5e0960d4d.zip |
Add systemtag_group table and get/set methods
Added systemtag to group mapping table.
Added methods in ISystemTagManager to get/set the group mappings.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/SystemTag/SystemTagManager.php | 55 | ||||
-rw-r--r-- | lib/public/SystemTag/ISystemTagManager.php | 20 |
2 files changed, 75 insertions, 0 deletions
diff --git a/lib/private/SystemTag/SystemTagManager.php b/lib/private/SystemTag/SystemTagManager.php index 495df674a03..1c91ad1f578 100644 --- a/lib/private/SystemTag/SystemTagManager.php +++ b/lib/private/SystemTag/SystemTagManager.php @@ -42,6 +42,7 @@ use OCP\IUser; class SystemTagManager implements ISystemTagManager { const TAG_TABLE = 'systemtag'; + const TAG_GROUP_TABLE = 'systemtag_group'; /** @var IDBConnection */ protected $connection; @@ -365,4 +366,58 @@ class SystemTagManager implements ISystemTagManager { private function createSystemTagFromRow($row) { return new SystemTag((int)$row['id'], $row['name'], (bool)$row['visibility'], (bool)$row['editable']); } + + /** + * {@inheritdoc} + */ + public function setTagGroups(ISystemTag $tag, $groupIds) { + // delete relationships first + $this->connection->beginTransaction(); + try { + $query = $this->connection->getQueryBuilder(); + $query->delete(self::TAG_GROUP_TABLE) + ->where($query->expr()->eq('systemtagid', $query->createNamedParameter($tag->getId()))) + ->execute(); + + // add each group id + $query = $this->connection->getQueryBuilder(); + $query->insert(self::TAG_GROUP_TABLE) + ->values([ + 'systemtagid' => $query->createNamedParameter($tag->getId()), + 'gid' => $query->createParameter('gid'), + ]); + foreach ($groupIds as $groupId) { + $query->setParameter('gid', $groupId); + $query->execute(); + } + + $this->connection->commit(); + } catch (\Exception $e) { + $this->connection->rollback(); + throw $e; + } + + return false; + } + + /** + * {@inheritdoc} + */ + public function getTagGroups(ISystemTag $tag) { + $groupIds = []; + $query = $this->connection->getQueryBuilder(); + $query->select('*') + ->from(self::TAG_GROUP_TABLE) + ->where($query->expr()->eq('systemtagid', $query->createNamedParameter($tag->getId()))) + ->orderBy('gid'); + + $result = $query->execute(); + while ($row = $result->fetch()) { + $groupIds[] = $row['gid']; + } + + $result->closeCursor(); + + return $groupIds; + } } diff --git a/lib/public/SystemTag/ISystemTagManager.php b/lib/public/SystemTag/ISystemTagManager.php index 283ca63e4f6..a2c61a8dcc2 100644 --- a/lib/public/SystemTag/ISystemTagManager.php +++ b/lib/public/SystemTag/ISystemTagManager.php @@ -141,4 +141,24 @@ interface ISystemTagManager { */ public function canUserSeeTag(ISystemTag $tag, IUser $userId); + /** + * Set groups that can assign a given tag. + * + * @param ISystemTag $tag tag for group assignment + * @param string[] $groupIds group ids of groups that can assign/unassign the tag + * + * @since 9.1.0 + */ + public function setTagGroups(ISystemTag $tag, $groupIds); + + /** + * Get groups that can assign a given tag. + * + * @param ISystemTag $tag tag for group assignment + * + * @return string[] group ids of groups that can assign/unassign the tag + * + * @since 9.1.0 + */ + public function getTagGroups(ISystemTag $tag); } |