function _community_tags_get_tag_result in Community Tags 6
Same name and namespace in other branches
- 5 community_tags.module \_community_tags_get_tag_result()
- 7 community_tags.module \_community_tags_get_tag_result()
Helper function for retrieving a query result to pass along to the Tagadelic functions prior to theming.
Parameters
$type: The type of query to perform. Possible values:
- node: get tag count for a given node.
- type: get tag count for a given node type.
- user: get tag count for a given user.
- user_node: get tag count for a given user on a given node.
- global: get tag count across entire site (default).
$args: An array of arguments that correspond to the result type:
- If type is 'node', $arg1 is a node ID, $arg2 (optional) is vocabulary ID.
- If type is 'type', $arg1 is a node type.
- If type is 'user', $arg1 is a user ID.
- If type is 'user_node', $arg1 is a user ID, and $arg2 is a node ID.
- If type is 'global', neither $args are used.
$limit: Only display a certain number of tags.
Return value
$result A database result set.
3 calls to _community_tags_get_tag_result()
- community_tags_mypage in ./
community_tags.pages.inc - Menu callback:
- _community_tags_display_handler_links in ./
community_tags.module - Display all tags as simple links.
- _community_tags_display_handler_tagadelic in ./
community_tags.module - Display all tags using tagadelic. Only called if tagadelic module is enabled. See _community_tags_get_tag_result() for definitions of $type and the arguments.
File
- ./
community_tags.module, line 364 - Implements community tagging of nodes using a specific vocabulary for Drupal v6.x
Code
function _community_tags_get_tag_result($type = 'global', $limit = NULL, $arg1 = NULL, $arg2 = NULL) {
$sql = '';
switch ($type) {
case 'node':
$arg1 = (int) $arg1;
if ($arg2) {
$arg2 = (int) $arg2;
$sql = "SELECT COUNT(t.tid) AS count, t.tid, t.name, t.vid FROM {term_data} t INNER JOIN {community_tags} c ON c.tid = t.tid WHERE c.nid = %d AND t.vid = %d GROUP BY t.tid, t.name, t.vid ORDER BY count DESC";
}
else {
$arg2 = NULL;
$sql = "SELECT COUNT(t.tid) AS count, t.tid, t.name, t.vid FROM {term_data} t INNER JOIN {community_tags} c ON c.tid = t.tid WHERE c.nid = %d GROUP BY t.tid, t.name, t.vid ORDER BY count DESC";
}
break;
case 'type':
$arg1 = (string) $arg1;
$arg2 = NULL;
$sql = "SELECT COUNT(t.tid) AS count, t.tid, t.name, t.vid FROM {term_data} t INNER JOIN {community_tags} c ON c.tid = t.tid INNER JOIN {node} n ON n.nid = c.nid WHERE n.type = '%s' GROUP BY t.tid, t.name, t.vid ORDER BY count DESC";
break;
case 'user':
$arg1 = (int) $arg1;
$arg2 = NULL;
$sql = "SELECT COUNT(t.tid) AS count, t.tid, t.name, t.vid FROM {term_data} t INNER JOIN {community_tags} c ON c.tid = t.tid WHERE c.uid = %d GROUP BY t.tid, t.name, t.vid ORDER BY count DESC";
break;
case 'user_node':
$arg1 = (int) $arg1;
$arg2 = (int) $arg2;
$sql = "SELECT COUNT(t.tid) AS count, t.tid, t.name, t.vid FROM {term_data} t INNER JOIN {community_tags} c ON c.tid = t.tid WHERE c.nid = %d AND c.uid = %d GROUP BY t.tid, t.name, t.vid ORDER BY count DESC";
default:
$sql = "SELECT COUNT(t.tid) AS count, t.tid, t.name, t.vid FROM {term_data} t INNER JOIN {community_tags} c ON c.tid = t.tid GROUP BY t.tid, t.name, t.vid ORDER BY count DESC";
}
if ($limit) {
$limit = (int) $limit;
return db_query_range($sql, $arg1, $arg2, 0, $limit);
}
else {
return db_query($sql, $arg1, $arg2);
}
}