summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/private/tags.php38
-rw-r--r--lib/public/itags.php9
2 files changed, 41 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()
+ );
+ }
}
diff --git a/lib/public/itags.php b/lib/public/itags.php
index 6076ddb4d02..2b09dcb5685 100644
--- a/lib/public/itags.php
+++ b/lib/public/itags.php
@@ -54,6 +54,15 @@ interface ITags {
public function isEmpty();
/**
+ * 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);
+
+ /**
* Get the tags for a specific user.
*
* This returns an array with id/name maps: