From: Michael J. Rubinsky Date: Mon, 8 Mar 2010 23:09:19 +0000 (-0500) Subject: Add method to get tagIds without having to call ensureTags() X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=0a9b5f72dac3710ebbe47900e8b0e55868fc7207;p=horde.git Add method to get tagIds without having to call ensureTags() Calling ensureTags() results in the tags being created. This isn't needed in every case we want a list of tagIds. --- diff --git a/content/lib/Tagger.php b/content/lib/Tagger.php index e4c3f07a9..587b14c8b 100644 --- a/content/lib/Tagger.php +++ b/content/lib/Tagger.php @@ -607,14 +607,14 @@ class Content_Tagger } /** - * Ensure that an array of tags exist, create any that don't, and - * return ids for all of them. - * - * @param array $tags Array of tag names or ids. - * - * @return array Array of tag ids. + * Check if tags exists, optionally create then if they don't and return + * ids for all that exist (including those that are optionally created). + * + * @param $tags + * @param $create + * @return \ */ - public function ensureTags($tags) + protected function _checkTags($tags, $create = true) { if (!is_array($tags)) { $tags = array($tags); @@ -646,15 +646,38 @@ class Content_Tagger } } - // Create any tags that didn't already exist - foreach ($tagText as $tag => $tagIndex) { - $tagIds[$tagIndex] = $this->_db->insert('INSERT INTO ' . $this->_t('tags') . ' (tag_name) VALUES (' . $this->_db->quote($tag) . ')'); + if ($create) { + // Create any tags that didn't already exist + foreach ($tagText as $tag => $tagIndex) { + $tagIds[$tagIndex] = $this->_db->insert('INSERT INTO ' . $this->_t('tags') . ' (tag_name) VALUES (' . $this->_db->quote($tag) . ')'); + } } return $tagIds; } /** + * Ensure that an array of tags exist, create any that don't, and + * return ids for all of them. + * + * @param array $tags Array of tag names or ids. + * + * @return array Array of tag ids. + */ + public function ensureTags($tags) + { + return $this->_checkTags($tags); + } + + /** + * + */ + public function getTagIds($tags) + { + return $this->_checkTags($tags, false); + } + + /** * Split a string into an array of tag names, respecting tags with spaces * and ones that are quoted in some way. For example: * this, "somecompany, llc", "and ""this"" w,o.rks", foo bar