You are here

function cctags_sort_tags in cctags 7

Same name and namespace in other branches
  1. 6 cctags.module \cctags_sort_tags()
1 call to cctags_sort_tags()
cctags_get_level_tags in ./cctags.module
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.

File

./cctags.module, line 214

Code

function cctags_sort_tags($terms, $sort, $mode = 'mixed') {
  list($sort, $order) = explode(',', $sort);
  $tags = array();
  $vocname = array();
  $tcount = array();
  $tvid = array();
  if ($mode == 'mixed') {
    foreach ($terms as $vid => $tag) {
      if (isset($terms[$vid]['vocname'])) {
        $vocname[] = $terms[$vid]['vocname'];
      }
      $tcount[] = count($tag);
      $tvid[] = $vid;
      foreach ($tag as $tid => $term) {
        if (is_numeric($tid)) {
          $tags[$tid] = $term;
        }
      }
    }
    $tags = _cctags_sort($tags, $sort, $order);
    $terms = array();
    foreach ($tags as $t => $tag) {
      $terms[0][$tag->tid] = $tag;
    }
    if (isset($vocname)) {
      $terms[0]['vocname'] = $vocname;
    }
    $terms[0]['terms'] = $tcount;
    $terms[0]['vid'] = $tvid;
  }
  else {
    foreach ($terms as $vid => $tags) {
      $vocname = $tags['vocname'];
      unset($tags['vocname']);
      $terms[$vid] = _cctags_sort($tags, $sort, $order);
      $terms[$vid]['vocname'] = array(
        $vocname,
      );
      $terms[$vid]['terms'] = array(
        count($tags),
      );
      $terms[$vid]['vid'] = array(
        $vid,
      );
    }
  }
  return $terms;
}