From 3e9c2cd0a57d798bb7cbcf89575cbc0199e0d2e5 Mon Sep 17 00:00:00 2001 From: cweiske Date: Sat, 20 Feb 2010 11:14:39 +0000 Subject: add new method for better sql performance: Bookmark2Tag::getTagsForBookmarks() git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@667 b3834d28-1941-0410-a4f8-b48e95affb8f --- src/SemanticScuttle/Service/Bookmark2Tag.php | 48 ++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'src/SemanticScuttle') diff --git a/src/SemanticScuttle/Service/Bookmark2Tag.php b/src/SemanticScuttle/Service/Bookmark2Tag.php index e0f831e..770b1d9 100644 --- a/src/SemanticScuttle/Service/Bookmark2Tag.php +++ b/src/SemanticScuttle/Service/Bookmark2Tag.php @@ -305,6 +305,54 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService return $tags; } + + /** + * Retrieves all tags for an array of bookmark IDs + * + * @param array $bookmarkids Array of bookmark IDs + * + * @return array Array of tag arrays. Key is bookmark ID. + */ + public function getTagsForBookmarks($bookmarkids) + { + if (!is_array($bookmarkids)) { + message_die( + GENERAL_ERROR, 'Could not get tags (invalid bookmarkids)', + '', __LINE__, __FILE__, $query + ); + return false; + } + + $sql = ''; + foreach ($bookmarkids as $bookmarkid) { + $sql .= ' OR bId = ' . intval($bookmarkid); + } + + $query = 'SELECT tag, bId FROM ' . $this->getTableName() + . ' WHERE (1' . $sql . ')' + . ' AND LEFT(tag, 7) <> "system:"' + . ' ORDER BY id, bId ASC'; + + if (!($dbresult = $this->db->sql_query($query))) { + message_die( + GENERAL_ERROR, 'Could not get tags', + '', __LINE__, __FILE__, $query, $this->db + ); + return false; + } + + $tags = array_combine( + $bookmarkids, + array_fill(0, count($bookmarkids), array()) + ); + while ($row = $this->db->sql_fetchrow($dbresult)) { + $tags[$row['bId']][] = $row['tag']; + } + $this->db->sql_freeresult($dbresult); + return $tags; + } + + function &getTags($userid = NULL) { $userservice =SemanticScuttle_Service_Factory::get('User'); $logged_on_user = $userservice->getCurrentUserId(); -- cgit v1.2.3