You are here

function nodeorder_orderable_tids in Node Order 6

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

Returns an array of the node's tids that are in orderable vocabularies...

1 call to nodeorder_orderable_tids()
nodeorder_nodeapi in ./nodeorder.module
Implementation of hook_nodeapi().

File

./nodeorder.module, line 575
Nodeorder module.

Code

function nodeorder_orderable_tids($node) {
  $tids = array();
  $orderable_tids = array();
  $cid = 'nodeorder:orderable_tids:' . $node->type;
  if (($cache = cache_get($cid)) && !empty($cache->data)) {
    $orderable_tids = $cache->data;
  }
  else {
    $sql = "SELECT v.vid AS vid FROM {vocabulary_node_types} vnt JOIN {vocabulary} v ON vnt.vid = v.vid WHERE vnt.type = '%s' AND v.module = 'nodeorder'";
    $result = db_query($sql, $node->type);
    while ($row = db_fetch_object($result)) {
      $tree = taxonomy_get_tree($row->vid);
      foreach ($tree as $term) {
        $orderable_tids[] = $term->tid;
      }
    }

    //permanently cache the value for easy reuse
    cache_set($cid, $orderable_tids, 'cache');
  }

  // Now select only those tids which are actually assigned to this term
  foreach ($node->taxonomy as $key => $value) {
    $list_of_tids = nodeorder_get_tids($key, $value);
    $tids = array_merge($tids, array_intersect($list_of_tids, $orderable_tids));
  }
  return $tids;
}