You are here

function _id_by_name in Bibliography Module 7

Same name and namespace in other branches
  1. 6 biblio.install \_id_by_name()
  2. 7.2 biblio.install \_id_by_name()
2 calls to _id_by_name()
_add_custom_field_data in ./biblio.install
_add_db_field_data_XML in ./biblio.install

File

./biblio.install, line 1802

Code

function _id_by_name($table, $name, $id = NULL, $build = NULL) {
  static $result = NULL;

  // Refresh cache from table.
  if (!empty($build)) {
    unset($result[$build['tablename']]);
    $res = db_query("SELECT " . $build['name_column'] . ", " . $build['id_column'] . " FROM {" . $build['tablename'] . "}", array(), array(
      'fetch' => PDO::FETCH_ASSOC,
    ));
    foreach ($res as $row) {
      $result[$build['tablename']][$row[$build['name_column']]] = $row[$build['id_column']];
    }
    return;
  }
  $name = trim($name);
  if (isset($result[$table][$name])) {
    return $result[$table][$name];
  }
  if ($id) {
    $result[$table][$name] = $id;
  }
  return FALSE;
}