You are here

function tagadelic_get_weighted_tags in Tagadelic 6

Same name and namespace in other branches
  1. 5 tagadelic.module \tagadelic_get_weighted_tags()
  2. 7 tagadelic.module \tagadelic_get_weighted_tags()

Function that gets the information from the database, passes it along to the weight builder and returns these weighted tags. Note that the tags are unordered at this stage, hence they need ordering either by calling our api or by your own ordering data.

Parameters

$vids: Vocabulary ids representing the vocabularies where you want the tags from.

$steps: The amount of tag-sizes you will be using. If you give "12" you sill get six different "weights". Defaults to 6 and is optional.

Return value

An <em>unordered</em> array with tags-objects, containing the attribute $tag->weight.

3 calls to tagadelic_get_weighted_tags()
tagadelic_block in ./tagadelic.module
Implements hook_block().
tagadelic_page_chunk in ./tagadelic.module
Menu callback renders a tagadelic page.
tagadelic_page_list in ./tagadelic.module
Menu callback renders a tagadelic page with listed items: each vocabulary.

File

./tagadelic.module, line 275

Code

function tagadelic_get_weighted_tags($vids, $steps = 6, $size = 60) {
  $tags = array();

  // Build the options so we can cache multiple versions.
  global $language;
  $options = implode('_', $vids) . '_' . $language->language . '_' . $steps . '_' . $size;

  // Check if the cache exists.
  $cache_name = 'tagadelic_cache_' . $options;
  $cache = cache_get($cache_name, 'cache_page');

  // Make sure cache has data.
  if (isset($cache->data)) {
    $tags = $cache->data;
  }
  else {
    if (!is_array($vids) || count($vids) == 0) {
      return array();
    }
    $result = db_query_range(db_rewrite_sql('SELECT COUNT(*) AS count, td.tid, td.vid, td.name, td.description FROM {term_data} td INNER JOIN {term_node} tn ON td.tid = tn.tid INNER JOIN {node} n ON tn.vid = n.vid WHERE td.vid IN (' . db_placeholders($vids) . ') AND n.status = 1 GROUP BY td.tid, td.vid, td.name, td.description HAVING COUNT(*) > 0 ORDER BY count DESC'), $vids, 0, $size);
    $tags = tagadelic_build_weighted_tags($result, $steps);
    cache_set($cache_name, $tags, 'cache_page', CACHE_TEMPORARY);
  }
  return $tags;
}