}
/**
- * 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 <type> $tags
+ * @param <type> $create
+ * @return <type> \
*/
- public function ensureTags($tags)
+ protected function _checkTags($tags, $create = true)
{
if (!is_array($tags)) {
$tags = array($tags);
}
}
- // 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