drupal: получение идентификаторов узлов узла-автомата из идентификаторов таксономии - PullRequest
0 голосов
/ 04 февраля 2010

Я использую модуль drupal NAT и мне нужно получить nid из термина id.

Вот что я попробовал:

foreach ( (array)nat_get_nids($termid) as $natid ) {
    $NatName = $natid->name;
}
print $natid;

Это не работает.

Функция get nid для автоматического термина узла выглядит следующим образом:

function nat_get_nids($tids, $get_nodes = FALSE) {
  static $nid_cache = NULL;
  static $node_cache = NULL;

  $return = array();

  // Keep processing to a minimum for empty tid arrays.
  if (!empty($tids)) {
    // Sort tid array to ensure that the cache_string never suffers from order
    // issues.
    sort($tids);
    $cache_string = implode('+', $tids);
    if ($get_nodes) {
      if (isset($node_cache[$cache_string])) {
        return $node_cache[$cache_string];
      }
      elseif (isset($nid_cache[$cache_string])) {
        // If the nid cache stores the same string, node_load() each nid and
        // return them.
        $return = array();
        foreach (array_keys($nid_cache[$cache_string]) as $nid) {
          $return[$nid] = node_load($nid);
        }
        $node_cache[$cache_string] = $return;

        return $return;
      }
    }
    else {
      if (isset($nid_cache[$cache_string])) {
        return $nid_cache[$cache_string];
      }
      elseif (isset($node_cache[$cache_string])) {
        // If the node cache stores the same string, retrieve only the nids and
        // return them.
        foreach ($node_cache[$cache_string] as $nid => $node) {
          $return[$nid] = $node->name;
        }
        // Cache extracted results.
        $nid_cache[$cache_string] = $return;

        return $return;
      }
    }

    // Results have not been cached.
    $tids = implode(', ', $tids);
    $result = db_query("SELECT n.nid, t.name FROM {nat} n INNER JOIN {term_data} t USING (tid) WHERE n.tid IN (". db_placeholders($tids) .")", $tids);
    while ($node = db_fetch_object($result)) {
      if ($get_nodes) {
        $return[$node->nid] = node_load($node->nid);
      }
      else {
        $return[$node->nid] = $node->name;
      }
    }

    if ($get_nodes) {
      $node_cache[$cache_string] = $return;
    }
    else {
      $nid_cache[$cache_string] = $return;
    }
  }

  return $return;
}

Заранее спасибо!

Редактировать: Попробуйте на основе первого ответа:

foreach (nat_get_nids($termid) as $nid => $node_name) {

}

print $node_name;

Ответы [ 2 ]

0 голосов
/ 07 февраля 2010
$nids = nat_get_nids(array($termid));
0 голосов
/ 04 февраля 2010

Похоже, nat_get_nids возвращает ассоциативный массив, поэтому ваш цикл for должен выглядеть как

foreach (nat_get_nids($termid) as $nid => $node_name) {
  ...
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...