You are here

function tagadelic_get_weighted_tags in Tagadelic 5

Same name and namespace in other branches
  1. 6 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 orndering 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
implementation of 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 voc

File

./tagadelic.module, line 205

Code

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

  // build the options so we can cache multiple versions
  $options = implode($vids) . '_' . $steps . '_' . $size;

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

  // make sure cache has data
  if (isset($cache->data)) {
    $tags = unserialize($cache->data);
  }
  else {
    if (!is_array($vids) || count($vids) == 0) {
      return array();
    }
    $result = db_query_range('SELECT COUNT(*) AS count, d.tid, d.name, d.vid FROM {term_data} d INNER JOIN {term_node} n ON d.tid = n.tid WHERE d.vid IN (' . substr(str_repeat('%d,', count($vids)), 0, -1) . ') GROUP BY d.tid, d.name, d.vid ORDER BY count DESC', $vids, 0, $size);
    $tags = tagadelic_build_weighted_tags($result, $steps);
    cache_set($cache_name, 'cache', serialize($tags), CACHE_TEMPORARY);
  }
  return $tags;
}