format getPopularTags and add docblock

This commit is contained in:
Christian Weiske 2011-03-23 18:52:01 +01:00
parent 9f46e9f3ff
commit 5c480c9bab

View file

@ -477,35 +477,70 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService
return $this->getPopularTags($contacts, $limit, $logged_on_user, $days);
}
// $users can be {NULL, an id, an array of id}
function &getPopularTags($user = NULL, $limit = 30, $logged_on_user = NULL, $days = NULL) {
/**
* The the most popular tags and their usage count
*
* @param mixed $user Integer user ID or array of user IDs to limit tag
* finding to
* @param integer $limit Number of tags to return
* @param integer $logged_on_user ID of the user that's currently logged in.
* If the logged in user equals the $user to find
* tags for, tags of private bookmarks are
* returned.
* @param integer $days Bookmarks have to be changed in the last X days
* if their tags shall count*
*
* @return array Array of found tags. Each tag entry is an array with two keys,
* 'tag' (tag name) and 'bCount'.
*/
public function getPopularTags(
$user = null, $limit = 30, $logged_on_user = null, $days = null
) {
// Only count the tags that are visible to the current user.
if (($user != $logged_on_user) || is_null($user) || ($user === false))
if (($user != $logged_on_user) || is_null($user) || ($user === false)) {
$privacy = ' AND B.bStatus = 0';
else
} else {
$privacy = '';
}
if (is_null($days) || !is_int($days))
if (is_null($days) || !is_int($days)) {
$span = '';
else
$span = ' AND B.bDatetime > "'. date('Y-m-d H:i:s', time() - (86400 * $days)) .'"';
} else {
$span = ' AND B.bDatetime > "'
. date('Y-m-d H:i:s', time() - (86400 * $days))
. '"';
}
$query = 'SELECT'
. ' T.tag, COUNT(T.bId) AS bCount'
. ' FROM '
. $this->getTableName() . ' AS T'
. ', ' . $GLOBALS['tableprefix'] . 'bookmarks AS B'
. ' WHERE';
$query = 'SELECT T.tag, COUNT(T.bId) AS bCount FROM '. $this->getTableName() .' AS T, '. $GLOBALS['tableprefix'] .'bookmarks AS B WHERE ';
if (is_null($user) || ($user === false)) {
$query .= 'B.bId = T.bId AND B.bStatus = 0';
} elseif(is_array($user)) {
$query .= ' B.bId = T.bId AND B.bStatus = 0';
} else if (is_array($user)) {
$query .= ' (1 = 0'; //tricks
foreach($user as $u) {
$query .= ' OR B.uId = '. $this->db->sql_escape($u) .' AND B.bId = T.bId';
foreach ($user as $u) {
$query .= ' OR B.uId = ' . $this->db->sql_escape($u)
. ' AND B.bId = T.bId';
}
$query .= ' )';
} else {
$query .= 'B.uId = '. $this->db->sql_escape($user) .' AND B.bId = T.bId'. $privacy;
$query .= ' B.uId = ' . $this->db->sql_escape($user)
. ' AND B.bId = T.bId' . $privacy;
}
$query .= $span .' AND LEFT(T.tag, 7) <> "system:" GROUP BY T.tag ORDER BY bCount DESC, tag';
if (!($dbresult =& $this->db->sql_query_limit($query, $limit))) {
message_die(GENERAL_ERROR, 'Could not get popular tags', '', __LINE__, __FILE__, $query, $this->db);
$query .= $span . ' AND LEFT(T.tag, 7) <> "system:"'
. ' GROUP BY T.tag'
. ' ORDER BY bCount DESC, tag';
if (!($dbresult = $this->db->sql_query_limit($query, $limit))) {
message_die(
GENERAL_ERROR, 'Could not get popular tags',
'', __LINE__, __FILE__, $query, $this->db
);
return false;
}
@ -514,6 +549,8 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService
return $output;
}
function hasTag($bookmarkid, $tag) {
$query = 'SELECT COUNT(*) AS tCount FROM '. $this->getTableName() .' WHERE bId = '. intval($bookmarkid) .' AND tag ="'. $this->db->sql_escape($tag) .'"';