You are here

function translation_overview_get_node_priority in Translation Overview 6.2

Determine the priority of a node.

If no priority has been set this module will create a record in the {translation_overview_priority} table for it.

Parameters

$node:

$reset: Boolean indcating that the function's cache should be reset.

Return value

The priority:

3 calls to translation_overview_get_node_priority()
translation_overview_nodeapi in ./translation_overview.module
Implementation of hook_nodeapi().
translation_overview_node_form in ./translation_overview.pages.inc
Overview page for a node's translations.
translation_overview_translation_link in ./translation_overview.module
Build a link to the translated node.

File

./translation_overview.module, line 171

Code

function translation_overview_get_node_priority($node, $reset = FALSE) {
  static $cache;
  if (!isset($cache) || $reset) {
    $cache = array();
  }
  $tnid = empty($node->tnid) ? $node->nid : $node->tnid;
  if (isset($cache[$tnid])) {
    return $cache[$tnid];
  }
  $languages = array_keys(language_list('language'));
  $pri = array();
  $result = db_query('SELECT * FROM {translation_overview_priority} WHERE tnid = %d', $tnid);
  $row = db_fetch_array($result);

  // Insert a record if one isn't found.
  if (empty($row)) {
    $row = array(
      'tnid' => empty($node->tnid) ? $node->nid : $node->tnid,
    );
    foreach ($languages as $lang_code) {
      $row[translation_overview_field_name($lang_code)] = TRANSLATION_OVERVIEW_NORMAL;
    }
    drupal_write_record('translation_overview_priority', $row);
  }

  // We need to adjust the array's keys. The fieldnames are encoded language codes.
  foreach (array_keys(language_list('language')) as $language) {
    $pri[$language] = isset($row[translation_overview_field_name($language)]) ? $row[translation_overview_field_name($language)] : TRANSLATION_OVERVIEW_NORMAL;
  }
  return $cache[$tnid] = $pri;
}