summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorBernhard Reiter <ockham@raz.or.at>2014-10-13 22:30:36 +0200
committerBernhard Reiter <ockham@raz.or.at>2014-10-14 00:06:33 +0200
commit17701796480ae1fd53222fa4e59d5fa1b79648db (patch)
tree441b20e375641611721fe74a67b0476ab5eccffb /lib/private
parentbc265e8b527c50dc7c63fbff7e43483ed1d2c891 (diff)
downloadnextcloud-server-17701796480ae1fd53222fa4e59d5fa1b79648db.tar.gz
nextcloud-server-17701796480ae1fd53222fa4e59d5fa1b79648db.zip
Add getTag() function for accessing of a single tag.
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/tags.php38
1 files changed, 32 insertions, 6 deletions
diff --git a/lib/private/tags.php b/lib/private/tags.php
index 05fb117036a..1065ba2ef98 100644
--- a/lib/private/tags.php
+++ b/lib/private/tags.php
@@ -140,6 +140,21 @@ class Tags implements \OCP\ITags {
}
/**
+ * Returns an array mapping a given tag's properties to its values:
+ * ['id' => 0, 'name' = 'Tag', 'owner' = 'User', 'type' => 'tagtype']
+ *
+ * @param string $id The ID of the tag that is going to be mapped
+ * @return array|false
+ */
+ public function getTag($id) {
+ $key = $this->getTagById($id);
+ if ($key !== false) {
+ return $this->tagMap($this->tags[$key]);
+ }
+ return false;
+ }
+
+ /**
* Get the tags for a specific user.
*
* This returns an array with maps containing each tag's properties:
@@ -162,12 +177,7 @@ class Tags implements \OCP\ITags {
foreach($this->tags as $tag) {
if($tag->getName() !== self::TAG_FAVORITE) {
- $tagMap[] = array(
- 'id' => $tag->getId(),
- 'name' => $tag->getName(),
- 'owner' => $tag->getOwner(),
- 'type' => $tag->getType()
- );
+ $tagMap[] = $this->tagMap($tag);
}
}
return $tagMap;
@@ -728,4 +738,20 @@ class Tags implements \OCP\ITags {
private function getTagById($id) {
return $this->array_searchi($id, $this->tags, 'getId');
}
+
+ /**
+ * Returns an array mapping a given tag's properties to its values:
+ * ['id' => 0, 'name' = 'Tag', 'owner' = 'User', 'type' => 'tagtype']
+ *
+ * @param Tag $tag The tag that is going to be mapped
+ * @return array
+ */
+ private function tagMap(Tag $tag) {
+ return array(
+ 'id' => $tag->getId(),
+ 'name' => $tag->getName(),
+ 'owner' => $tag->getOwner(),
+ 'type' => $tag->getType()
+ );
+ }
}