You are here

function simple_ldap_user_find_tids_by_terms in Simple LDAP 7.2

1 call to simple_ldap_user_find_tids_by_terms()
simple_ldap_user_translate_term_ldap_to_drupal in simple_ldap_user/simple_ldap_user.ldap_handlers.inc
Map the value(s) in the LDAP attr to one or more TIDs. This will *NOT* create new Terms if they are not present, and this funciton does not understand the term's heirarchy. If the term's name is ambiguous, the one selected depends on the…

File

simple_ldap_user/simple_ldap_user.ldap_handlers.inc, line 180

Code

function simple_ldap_user_find_tids_by_terms($info, $terms) {
  if (empty($terms)) {
    return array();
  }

  // Find all the valid vocabularies
  $vocab_machine_names = array();
  foreach ($info['settings']['allowed_values'] as $allowed_vocab) {
    $vocab_machine_names[] = $allowed_vocab['vocabulary'];
  }

  // Build the SQL
  $sql = "SELECT tid FROM {taxonomy_term_data} td WHERE td.name IN (:terms)";
  if (!empty($vocab_machine_names)) {
    $sql .= " AND vid IN (SELECT vid FROM {taxonomy_vocabulary} WHERE machine_name IN (:machine_names))";
  }

  // One query is all we need.
  $db_result = db_query($sql, array(
    ':terms' => $terms,
    ':machine_names' => $vocab_machine_names,
  ));
  $results = array();
  foreach ($db_result as $record) {
    $results[] = (array) $record;
  }
  return $results;
}