summaryrefslogtreecommitdiff
path: root/src/SemanticScuttle/Service/Bookmark2Tag.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/SemanticScuttle/Service/Bookmark2Tag.php')
-rw-r--r--src/SemanticScuttle/Service/Bookmark2Tag.php75
1 files changed, 69 insertions, 6 deletions
diff --git a/src/SemanticScuttle/Service/Bookmark2Tag.php b/src/SemanticScuttle/Service/Bookmark2Tag.php
index 8e5cb22..4d2c969 100644
--- a/src/SemanticScuttle/Service/Bookmark2Tag.php
+++ b/src/SemanticScuttle/Service/Bookmark2Tag.php
@@ -266,27 +266,90 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService
return true;
}
- function &getTagsForBookmark($bookmarkid) {
+
+ /**
+ * Retrieves all tags for a given bookmark except system tags.
+ *
+ * @param integer $bookmarkid ID of the bookmark
+ *
+ * @return array Array of tags
+ */
+ public function getTagsForBookmark($bookmarkid)
+ {
if (!is_numeric($bookmarkid)) {
- message_die(GENERAL_ERROR, 'Could not get tags (invalid bookmarkid)', '', __LINE__, __FILE__, $query);
+ message_die(
+ GENERAL_ERROR, 'Could not get tags (invalid bookmarkid)',
+ '', __LINE__, __FILE__, $query
+ );
return false;
}
- $query = 'SELECT tag FROM '. $this->getTableName() .' WHERE bId = '. intval($bookmarkid) .' AND LEFT(tag, 7) <> "system:" ORDER BY id ASC';
+ $query = 'SELECT tag FROM ' . $this->getTableName()
+ . ' WHERE bId = ' . intval($bookmarkid)
+ . ' AND LEFT(tag, 7) <> "system:"'
+ . ' ORDER BY id ASC';
- if (!($dbresult =& $this->db->sql_query($query))) {
- message_die(GENERAL_ERROR, 'Could not get tags', '', __LINE__, __FILE__, $query, $this->db);
+ if (!($dbresult = $this->db->sql_query($query))) {
+ message_die(
+ GENERAL_ERROR, 'Could not get tags',
+ '', __LINE__, __FILE__, $query, $this->db
+ );
return false;
}
$tags = array();
- while ($row =& $this->db->sql_fetchrow($dbresult)) {
+ while ($row = $this->db->sql_fetchrow($dbresult)) {
$tags[] = $row['tag'];
}
$this->db->sql_freeresult($dbresult);
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;
+ } else if (count($bookmarkids) == 0) {
+ return array();
+ }
+
+ $query = 'SELECT tag, bId FROM ' . $this->getTableName()
+ . ' WHERE bId IN (' . implode(',', $bookmarkids) . ')'
+ . ' 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();