From 17701796480ae1fd53222fa4e59d5fa1b79648db Mon Sep 17 00:00:00 2001 From: Bernhard Reiter Date: Mon, 13 Oct 2014 22:30:36 +0200 Subject: [PATCH] Add getTag() function for accessing of a single tag. --- lib/private/tags.php | 38 ++++++++++++++++++++++++++++++++------ lib/public/itags.php | 9 +++++++++ 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 @@ -139,6 +139,21 @@ class Tags implements \OCP\ITags { return count($this->tags) === 0; } + /** + * 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. * @@ -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 @@ -53,6 +53,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. * -- 2.39.5